diff --git a/muk_web_preview_image/LICENSE b/muk_web_preview_image/LICENSE new file mode 100644 index 0000000..faf7bf4 --- /dev/null +++ b/muk_web_preview_image/LICENSE @@ -0,0 +1,619 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/muk_web_preview_image/README.rst b/muk_web_preview_image/README.rst new file mode 100644 index 0000000..8829b75 --- /dev/null +++ b/muk_web_preview_image/README.rst @@ -0,0 +1,128 @@ +================= +MuK Preview Image +================= + +Extendes the Preview Dialog to support images. Currently the following image extensions +are supported: + +* CIS-Cod-Dateien (\*.cod, image/cis-cod) +* CMU-Raster-Dateien (\*.ras, image/cmu-raster) +* FIF-Dateien (\*.fif, image/fif) +* GIF-Dateien (\*.gif, image/gif) +* IEF-Dateien (\*.ief, image/ief) +* JPEG-Dateien (\*.jpeg \*.jpg \*.jpe, image/jpeg) +* PNG-Dateien (\*.png, image/png) +* TIFF-Dateien (\*.tiff \*.tif, image/tiff) +* Vasa-Dateien (\*.mcf, image/vasa) +* Bitmap-Dateien (WAP) (\*.wbmp, image/vnd.wap.wbmp) +* Freehand-Dateien (\*.fh4 \*.fh5 \*.fhc, image/x-freehand) +* Icon-Dateien (\*.ico, image/x-icon) +* PBM Anymap Dateien (\*.pnm, image/x-portable-anymap) +* PBM Bitmap Dateien (\*.pbm, image/x-portable-bitmap) +* PBM Graymap Dateien (\*.pgm, image/x-portable-graymap) +* PBM Pixmap Dateien (\*.ppm, image/x-portable-pixmap) +* RGB-Dateien (\*.rgb, image/x-rgb) +* X-Windows Dump (\*.xwd, image/x-windowdump) +* XBM-Dateien (\*.xbm, image/x-xbitmap) +* XPM-Dateien (\*.xpm, image/x-xpixmap) + +Installation +============ + +To install this module, you need to: + +Download the module and add it to your Odoo addons folder. Afterward, log on to +your Odoo server and go to the Apps menu. Trigger the debug mode and update the +list by clicking on the "Update Apps List" link. Now install the module by +clicking on the install button. + +Another way to install this module is via the package management for Python +(`PyPI `_). + +To install our modules using the package manager make sure +`odoo-autodiscover `_ is installed +correctly. Then open a console and install the module by entering the following +command: + +``pip install --extra-index-url https://nexus.mukit.at/repository/odoo/simple `` + +The module name consists of the Odoo version and the module name, where +underscores are replaced by a dash. + +**Module:** + +``odoo-addon-`` + +**Example:** + +``sudo -H pip3 install --extra-index-url https://nexus.mukit.at/repository/odoo/simple odoo11-addon-muk-utils`` + +Once the installation has been successfully completed, the app is already in the +correct folder. Log on to your Odoo server and go to the Apps menu. Trigger the +debug mode and update the list by clicking on the "Update Apps List" link. Now +install the module by clicking on the install button. + +The biggest advantage of this variant is that you can now also update the app +using the "pip" command. To do this, enter the following command in your console: + +``pip install --upgrade --extra-index-url https://nexus.mukit.at/repository/odoo/simple `` + +When the process is finished, restart your server and update the application in +Odoo. The steps are the same as for the installation only the button has changed +from "Install" to "Upgrade". + +You can also view available Apps directly in our `repository `_ +and find a more detailed installation guide on our `website `_. + +For modules licensed under OPL-1, you will receive access data when you purchase +the module. If the modules were not purchased directly from +`MuK IT `_ please contact our support (support@mukit.at) +with a confirmation of purchase to receive the corresponding access data. + +Upgrade +============ + +To upgrade this module, you need to: + +Download the module and add it to your Odoo addons folder. Restart the server +and log on to your Odoo server. Select the Apps menu and upgrade the module by +clicking on the upgrade button. + +If you installed the module using the "pip" command, you can also update the +module in the same way. Just type the following command into the console: + +``pip install --upgrade --extra-index-url https://nexus.mukit.at/repository/odoo/simple `` + +When the process is finished, restart your server and update the application in +Odoo, just like you would normally. + +Configuration +============= + +No additional configuration is needed to use this module. + +Usage +============= + +Go to a binary that contains an image and open the preview dialog to view +the image. + +Credits +======= + +Contributors +------------ + +* Mathias Markl + +Author & Maintainer +------------------- + +This module is maintained by the `MuK IT GmbH `_. + +MuK IT is an Austrian company specialized in customizing and extending Odoo. +We develop custom solutions for your individual needs to help you focus on +your strength and expertise to grow your business. + +If you want to get in touch please contact us via mail +(sale@mukit.at) or visit our website (https://mukit.at). diff --git a/muk_web_preview_image/__init__.py b/muk_web_preview_image/__init__.py new file mode 100644 index 0000000..21f21ae --- /dev/null +++ b/muk_web_preview_image/__init__.py @@ -0,0 +1,18 @@ +################################################################################### +# +# Copyright (C) 2017 MuK IT GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### diff --git a/muk_web_preview_image/__manifest__.py b/muk_web_preview_image/__manifest__.py new file mode 100644 index 0000000..7fb9941 --- /dev/null +++ b/muk_web_preview_image/__manifest__.py @@ -0,0 +1,51 @@ +################################################################################### +# +# Copyright (C) 2017 MuK IT GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### + +{ + "name": "MuK Preview Image", + "summary": """Image Preview""", + "version": "12.0.2.0.1", + "category": "Extra Tools", + "license": "AGPL-3", + "website": "http://www.mukit.at", + "live_test_url": "https://demo.mukit.at/web/login", + "author": "MuK IT", + "contributors": [ + "Mathias Markl ", + ], + "depends": [ + "muk_web_preview", + ], + "data": [ + "template/assets.xml", + ], + "qweb": [ + "static/src/xml/*.xml", + ], + "images": [ + 'static/description/banner.png' + ], + "external_dependencies": { + "python": [], + "bin": [], + }, + "application": False, + "installable": True, + +} \ No newline at end of file diff --git a/muk_web_preview_image/doc/changelog.rst b/muk_web_preview_image/doc/changelog.rst new file mode 100644 index 0000000..f10b321 --- /dev/null +++ b/muk_web_preview_image/doc/changelog.rst @@ -0,0 +1,14 @@ +`2.0.0` +------- + +- Migrated to Python 3 + +`1.1.0` +------- + +- Lazy load javascript + +`1.0.0` +------- + +- Init version diff --git a/muk_web_preview_image/doc/index.rst b/muk_web_preview_image/doc/index.rst new file mode 100644 index 0000000..8829b75 --- /dev/null +++ b/muk_web_preview_image/doc/index.rst @@ -0,0 +1,128 @@ +================= +MuK Preview Image +================= + +Extendes the Preview Dialog to support images. Currently the following image extensions +are supported: + +* CIS-Cod-Dateien (\*.cod, image/cis-cod) +* CMU-Raster-Dateien (\*.ras, image/cmu-raster) +* FIF-Dateien (\*.fif, image/fif) +* GIF-Dateien (\*.gif, image/gif) +* IEF-Dateien (\*.ief, image/ief) +* JPEG-Dateien (\*.jpeg \*.jpg \*.jpe, image/jpeg) +* PNG-Dateien (\*.png, image/png) +* TIFF-Dateien (\*.tiff \*.tif, image/tiff) +* Vasa-Dateien (\*.mcf, image/vasa) +* Bitmap-Dateien (WAP) (\*.wbmp, image/vnd.wap.wbmp) +* Freehand-Dateien (\*.fh4 \*.fh5 \*.fhc, image/x-freehand) +* Icon-Dateien (\*.ico, image/x-icon) +* PBM Anymap Dateien (\*.pnm, image/x-portable-anymap) +* PBM Bitmap Dateien (\*.pbm, image/x-portable-bitmap) +* PBM Graymap Dateien (\*.pgm, image/x-portable-graymap) +* PBM Pixmap Dateien (\*.ppm, image/x-portable-pixmap) +* RGB-Dateien (\*.rgb, image/x-rgb) +* X-Windows Dump (\*.xwd, image/x-windowdump) +* XBM-Dateien (\*.xbm, image/x-xbitmap) +* XPM-Dateien (\*.xpm, image/x-xpixmap) + +Installation +============ + +To install this module, you need to: + +Download the module and add it to your Odoo addons folder. Afterward, log on to +your Odoo server and go to the Apps menu. Trigger the debug mode and update the +list by clicking on the "Update Apps List" link. Now install the module by +clicking on the install button. + +Another way to install this module is via the package management for Python +(`PyPI `_). + +To install our modules using the package manager make sure +`odoo-autodiscover `_ is installed +correctly. Then open a console and install the module by entering the following +command: + +``pip install --extra-index-url https://nexus.mukit.at/repository/odoo/simple `` + +The module name consists of the Odoo version and the module name, where +underscores are replaced by a dash. + +**Module:** + +``odoo-addon-`` + +**Example:** + +``sudo -H pip3 install --extra-index-url https://nexus.mukit.at/repository/odoo/simple odoo11-addon-muk-utils`` + +Once the installation has been successfully completed, the app is already in the +correct folder. Log on to your Odoo server and go to the Apps menu. Trigger the +debug mode and update the list by clicking on the "Update Apps List" link. Now +install the module by clicking on the install button. + +The biggest advantage of this variant is that you can now also update the app +using the "pip" command. To do this, enter the following command in your console: + +``pip install --upgrade --extra-index-url https://nexus.mukit.at/repository/odoo/simple `` + +When the process is finished, restart your server and update the application in +Odoo. The steps are the same as for the installation only the button has changed +from "Install" to "Upgrade". + +You can also view available Apps directly in our `repository `_ +and find a more detailed installation guide on our `website `_. + +For modules licensed under OPL-1, you will receive access data when you purchase +the module. If the modules were not purchased directly from +`MuK IT `_ please contact our support (support@mukit.at) +with a confirmation of purchase to receive the corresponding access data. + +Upgrade +============ + +To upgrade this module, you need to: + +Download the module and add it to your Odoo addons folder. Restart the server +and log on to your Odoo server. Select the Apps menu and upgrade the module by +clicking on the upgrade button. + +If you installed the module using the "pip" command, you can also update the +module in the same way. Just type the following command into the console: + +``pip install --upgrade --extra-index-url https://nexus.mukit.at/repository/odoo/simple `` + +When the process is finished, restart your server and update the application in +Odoo, just like you would normally. + +Configuration +============= + +No additional configuration is needed to use this module. + +Usage +============= + +Go to a binary that contains an image and open the preview dialog to view +the image. + +Credits +======= + +Contributors +------------ + +* Mathias Markl + +Author & Maintainer +------------------- + +This module is maintained by the `MuK IT GmbH `_. + +MuK IT is an Austrian company specialized in customizing and extending Odoo. +We develop custom solutions for your individual needs to help you focus on +your strength and expertise to grow your business. + +If you want to get in touch please contact us via mail +(sale@mukit.at) or visit our website (https://mukit.at). diff --git a/muk_web_preview_image/i18n/de.po b/muk_web_preview_image/i18n/de.po new file mode 100644 index 0000000..0e173c2 --- /dev/null +++ b/muk_web_preview_image/i18n/de.po @@ -0,0 +1,16 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0-20190128\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-03-06 00:21+0000\n" +"PO-Revision-Date: 2019-03-06 00:21+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + diff --git a/muk_web_preview_image/i18n/es.po b/muk_web_preview_image/i18n/es.po new file mode 100644 index 0000000..0e173c2 --- /dev/null +++ b/muk_web_preview_image/i18n/es.po @@ -0,0 +1,16 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0-20190128\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-03-06 00:21+0000\n" +"PO-Revision-Date: 2019-03-06 00:21+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + diff --git a/muk_web_preview_image/i18n/fr.po b/muk_web_preview_image/i18n/fr.po new file mode 100644 index 0000000..0e173c2 --- /dev/null +++ b/muk_web_preview_image/i18n/fr.po @@ -0,0 +1,16 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0-20190128\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-03-06 00:21+0000\n" +"PO-Revision-Date: 2019-03-06 00:21+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + diff --git a/muk_web_preview_image/i18n/muk_web_preview_image.pot b/muk_web_preview_image/i18n/muk_web_preview_image.pot new file mode 100644 index 0000000..0e173c2 --- /dev/null +++ b/muk_web_preview_image/i18n/muk_web_preview_image.pot @@ -0,0 +1,16 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0-20190128\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-03-06 00:21+0000\n" +"PO-Revision-Date: 2019-03-06 00:21+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + diff --git a/muk_web_preview_image/i18n/nl.po b/muk_web_preview_image/i18n/nl.po new file mode 100644 index 0000000..428692b --- /dev/null +++ b/muk_web_preview_image/i18n/nl.po @@ -0,0 +1,16 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0-20190128\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-03-06 00:22+0000\n" +"PO-Revision-Date: 2019-03-06 00:22+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + diff --git a/muk_web_preview_image/static/description/banner.png b/muk_web_preview_image/static/description/banner.png new file mode 100644 index 0000000..86ff1eb Binary files /dev/null and b/muk_web_preview_image/static/description/banner.png differ diff --git a/muk_web_preview_image/static/description/icon.png b/muk_web_preview_image/static/description/icon.png new file mode 100644 index 0000000..b63ce2e Binary files /dev/null and b/muk_web_preview_image/static/description/icon.png differ diff --git a/muk_web_preview_image/static/description/icon.svg b/muk_web_preview_image/static/description/icon.svg new file mode 100644 index 0000000..1cda090 --- /dev/null +++ b/muk_web_preview_image/static/description/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/muk_web_preview_image/static/description/index.html b/muk_web_preview_image/static/description/index.html new file mode 100644 index 0000000..d7ae29a --- /dev/null +++ b/muk_web_preview_image/static/description/index.html @@ -0,0 +1,157 @@ +
+
+

Preview Image

+

Preview your images directly in Odoo.

+

MuK IT GmbH - + www.mukit.at

+
+ +
+
+
+ +
+
+
+

Overview

+

Extendes the Preview Dialog to support images. + Currently the following image extensions are supported:

+

+ CIS-Cod-Dateien (*.cod, + image/cis-cod)
+ CMU-Raster-Dateien (*.ras, image/cmu-raster)
FIF-Dateien (*.fif, + image/fif)
+ GIF-Dateien (*.gif, image/gif)
+ ☑ IEF-Dateien (*.ief, image/ief)
JPEG-Dateien (*.jpeg *.jpg + *.jpe, image/jpeg)
+ ☑ PNG-Dateien (*.png, image/png)
TIFF-Dateien (*.tiff *.tif, + image/tiff)
+ Vasa-Dateien (*.mcf, image/vasa)
+ ☑ Bitmap-Dateien (WAP) (*.wbmp, image/vnd.wap.wbmp)
+ Freehand-Dateien (*.fh4 + *.fh5 *.fhc, image/x-freehand)
+ ☑ Icon-Dateien (*.ico, image/x-icon)
PBM Anymap Dateien (*.pnm, + image/x-portable-anymap)
+ ☑ PBM Bitmap Dateien (*.pbm, image/x-portable-bitmap)
+ PBM Graymap Dateien + (*.pgm, image/x-portable-graymap)
PBM Pixmap Dateien (*.ppm, + image/x-portable-pixmap)
+ ☑ RGB-Dateien (*.rgb, image/x-rgb)
X-Windows Dump (*.xwd, + image/x-windowdump)
+ ☑ XBM-Dateien (*.xbm, image/x-xbitmap)
XPM-Dateien (*.xpm, + image/x-xpixmap)
+

+
+
+
+ +
+ +
+ +
+
+
+ + +
+
+
+ +
+

Help and Support

+
Feel free to + contact us, if you need any help with your Odoo integration or + addiontal features.
+ + +
\ No newline at end of file diff --git a/muk_web_preview_image/static/description/logo.png b/muk_web_preview_image/static/description/logo.png new file mode 100644 index 0000000..9427ce3 Binary files /dev/null and b/muk_web_preview_image/static/description/logo.png differ diff --git a/muk_web_preview_image/static/description/preview.png b/muk_web_preview_image/static/description/preview.png new file mode 100644 index 0000000..1deb1cc Binary files /dev/null and b/muk_web_preview_image/static/description/preview.png differ diff --git a/muk_web_preview_image/static/description/screenshot.png b/muk_web_preview_image/static/description/screenshot.png new file mode 100644 index 0000000..b9fc3a2 Binary files /dev/null and b/muk_web_preview_image/static/description/screenshot.png differ diff --git a/muk_web_preview_image/static/description/service_customization.png b/muk_web_preview_image/static/description/service_customization.png new file mode 100644 index 0000000..3eac664 Binary files /dev/null and b/muk_web_preview_image/static/description/service_customization.png differ diff --git a/muk_web_preview_image/static/description/service_development.png b/muk_web_preview_image/static/description/service_development.png new file mode 100644 index 0000000..580d460 Binary files /dev/null and b/muk_web_preview_image/static/description/service_development.png differ diff --git a/muk_web_preview_image/static/description/service_implementation.png b/muk_web_preview_image/static/description/service_implementation.png new file mode 100644 index 0000000..d64b66b Binary files /dev/null and b/muk_web_preview_image/static/description/service_implementation.png differ diff --git a/muk_web_preview_image/static/description/service_integration.png b/muk_web_preview_image/static/description/service_integration.png new file mode 100644 index 0000000..76c5e80 Binary files /dev/null and b/muk_web_preview_image/static/description/service_integration.png differ diff --git a/muk_web_preview_image/static/description/service_support.png b/muk_web_preview_image/static/description/service_support.png new file mode 100644 index 0000000..4c530fa Binary files /dev/null and b/muk_web_preview_image/static/description/service_support.png differ diff --git a/muk_web_preview_image/static/lib/svg-pan-zoom/svg-pan-zoom.js b/muk_web_preview_image/static/lib/svg-pan-zoom/svg-pan-zoom.js new file mode 100644 index 0000000..a49bd54 --- /dev/null +++ b/muk_web_preview_image/static/lib/svg-pan-zoom/svg-pan-zoom.js @@ -0,0 +1,637 @@ +// Generated by CoffeeScript 1.10.0 + +/* +jQuery SVG Pan Zoom v1.0.2, June 2015 + +Author: Daniel Hoffmann Bernardes (daniel.hoffmann.bernardes@gmail.com) + +Repository: https://github.com/DanielHoffmann/jquery-svg-pan-zoom/ + +jQuery plugin to enable pan and zoom in SVG images either programmatically or through mouse/touch events. + +[Demo page](http://danielhoffmann.github.io/jquery-svg-pan-zoom/) + + * Features + - Programmatically manipulate the SVG viewBox + - Mouse and touch events to pan the SVG viewBox + - Mousewheel events to zoom in or out the SVG viewBox + - Animations + - Mousewheel zooming keeps the cursor over the same coordinates relative to the image (A.K.A. GoogleMaps-like zoom) + - Limiting the navigable area + + * Requirements + +jQuery + +SVG-enabled browser (does not work with SVG work-arounds that use Flash) + + * The viewBox +The viewBox is an attribute of SVG images that defines the area of the SVG that is visible, it is defined by 4 numbers: X, Y, Width, Height. These numbers together specify the visible area. This plugin works by manipulating these four numbers. For example, moving the image to the right alters the X value while zooming in reduces Width and Height. + + + * Usage +```javascript +var svgPanZoom= $("svg").svgPanZoom(options) +``` + +If the selection has more than one element `svgPanZoom` will return an array with a SvgPanZoom object for each image in the same order of the selection. If only one element is selected then the return is a single SvgPanZoom object. If no elements are selected the above call returns `null` + +The returned SvgPanZoom object contains all options, these options can be overriden at any time directly, for example to disable mouseWheel events simply: + +```javascript +svgPanZoom.events.mouseWheel= false +``` + + +the SvgPanZoom object also has methods for manipulating the viewBox programmatically. For example: + +```javascript +svgPanZoom.zoomIn() +``` + +will zoomIn the image using options.zoomFactor. + + * Building +This project requires coffeescript to be installed in order to build. + + `coffee -m --compile --output compiled/ src/` + + * Options + +```javascript +Options: +{ + events: { + mouseWheel: boolean (true), // enables mouse wheel zooming events + doubleClick: boolean (true), // enables double-click to zoom-in events + drag: boolean (true), // enables drag and drop to move the SVG events + dragCursor: string "move" // cursor to use while dragging the SVG + }, + animationTime: number (300), // time in milliseconds to use as default for animations. Set 0 to remove the animation + zoomFactor: number (0.25), // how much to zoom-in or zoom-out + maxZoom: number (3), //maximum zoom in, must be a number bigger than 1 + panFactor: (number (100), // how much to move the viewBox when calling .panDirection() methods + initialViewBox: { // the initial viewBox, if null or undefined will try to use the viewBox set in the svg tag. Also accepts string in the format "X Y Width Height" + x: number (0) // the top-left corner X coordinate + y: number (0) // the top-left corner Y coordinate + width: number (1000) // the width of the viewBox + height: number (1000) // the height of the viewBox + }, + limits: { // the limits in which the image can be moved. If null or undefined will use the initialViewBox plus 15% in each direction + x: number (-150) + y: number (-150) + x2: number (1150) + y2: number (1150) + } +} +``` + + + * Methods + + - pan + +```javascript +svgPanZoom.panLeft(amount, animationTime) +svgPanZoom.panRight(amount, animationTime) +svgPanZoom.panUp(amount, animationTime) +svgPanZoom.panDown(amount, animationTime) +``` + +Moves the SVG viewBox in the specified direction. Parameters: + - amount: Number, optional. How much to move the viewBox, defaults to options.panFactor. + - animationTime: Number, optional. How long the animation should last, defaults to options.animationTime. + + + - zoom + +```javascript +svgPanZoom.zoomIn(animationTime) +svgPanZoom.zoomOut(animationTime) +``` + +Zooms the viewBox. Parameters: + - animationTime: Number, optional. How long the animation should last, defaults to options.animationTime. + + + - reset + +```javascript +svgPanZoom.reset() +``` + +Resets the SVG to options.initialViewBox values. + + - getViewBox + +```javascript +svgPanZoom.getViewBox() +``` + +Returns the viewbox in this format: + +```javascript +{ + x: number + y: number + width: number + height: number +} +``` + + - setViewBox + +```javascript +svgPanZoom.setViewBox(x, y, width, height, animationTime) +``` + +Changes the viewBox to the specified coordinates. Will respect the `options.limits` adapting the viewBox if needed (moving or reducing it to fit into `options.limits` + - x: Number, the new x coodinate of the top-left corner + - y: Number, the new y coodinate of the top-left corner + - width: Number, the new width of the viewBox + - height: Number, the new height of the viewBox + - animationTime: Number, optional. How long the animation should last, defaults to options.animationTime. + + - setCenter + +```javascript +svgPanZoom.setCenter(x, y, animationTime) +``` + +Sets the center of the SVG. Parameters: + - x: Number, the new x coordinate of the center + - y: Number, the new y coordinate of the center + - animationTime: Number, optional. How long the animation should last, defaults to options.animationTime. + + + + + * Notes: + + - Only works in SVGs inlined in the HTML. You can use $.load() to load the SVG image in the page using AJAX and call $().svgPanZoom() in the callback + - Touch pinch events to zoom not yet supported + - This plugin does not create any controls (like arrows to move the image) on top of the SVG. These controls are simple to create manually and they can call the methods to move the image. + - Do not manipulate the SVG viewBox attribute manually, use SvgPanZoom.setViewBox() instead + +Copyright (C) 2014 Daniel Hoffmann Bernardes, Ícaro Technologies + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +(function() { + var hasProp = {}.hasOwnProperty; + + (function($) { + var checkLimits, defaultOptions, defaultViewBox, getViewBoxCoordinatesFromEvent, parseViewBoxString; + defaultOptions = { + events: { + mouseWheel: true, + doubleClick: true, + drag: true, + dragCursor: "move" + }, + animationTime: 300, + zoomFactor: 0.25, + maxZoom: 3, + panFactor: 100, + initialViewBox: null, + limits: null + }; + defaultViewBox = { + x: 0, + y: 0, + width: 1000, + height: 1000 + }; + + /** + * Check the limits of the view box, return a new viewBox that respects the limits while keeping + * the original view box size if possible. If the view box needs to be reduced, the returned view + * box will keep the aspect ratio of the original view box. + * + * @param {Object} viewBox + * The original view box. Takes numbers, in the format `{x, y, width, height}`. + * + * @param {Object} limits + * Extents which can be shown, in the view box coordinate system. Takes numbers in the format + * `{x, y, x2, y2}`. + * + * @return {Object} viewBox + * A new view box object, squeezed into the limits. Contains numbers, in the format `{x, y, + * width, height}`. + */ + checkLimits = function(viewBox, limits) { + var limitsHeight, limitsWidth, reductionFactor, vb; + vb = $.extend({}, viewBox); + limitsWidth = Math.abs(limits.x2 - limits.x); + limitsHeight = Math.abs(limits.y2 - limits.y); + if (vb.width > limitsWidth) { + if (vb.height > limitsHeight) { + if (limitsWidth > limitsHeight) { + reductionFactor = limitsHeight / vb.height; + vb.height = limitsHeight; + vb.width = vb.width * reductionFactor; + } else { + reductionFactor = limitsWidth / vb.width; + vb.width = limitsWidth; + vb.height = vb.height * reductionFactor; + } + } else { + reductionFactor = limitsWidth / vb.width; + vb.width = limitsWidth; + vb.height = vb.height * reductionFactor; + } + } else if (vb.height > limitsHeight) { + reductionFactor = limitsHeight / vb.height; + vb.height = limitsHeight; + vb.width = vb.width * reductionFactor; + } + if (vb.x < limits.x) { + vb.x = limits.x; + } + if (vb.y < limits.y) { + vb.y = limits.y; + } + if (vb.x + vb.width > limits.x2) { + vb.x = limits.x2 - vb.width; + } + if (vb.y + vb.height > limits.y2) { + vb.y = limits.y2 - vb.height; + } + return vb; + }; + + /** + * Parse the viewbox string as defined in the spec for the svg tag. + * + * @param {String} viewBoxString + * A valid value of the `viewBox` attribute. + * + * @return {Object} viewBox + * A view box object. Contains numbers, in the format `{x, y, width, height}`. + */ + parseViewBoxString = function(string) { + var vb; + vb = string.replace("\s+", " ").split(" "); + return vb = { + x: parseFloat(vb[0]), + y: parseFloat(vb[1]), + width: parseFloat(vb[2]), + height: parseFloat(vb[3]) + }; + }; + + /** + * Get the mouse or first touch position from the `event`, relative to the SVG viewBox. + * + * @param {SVGElement} svgRoot + * The `` DOM object + * + * @param {MouseEvent|TouchEvent|jQueryEvent} event + * The DOM or jQuery event. + * + * @return {Object} + * Coordinates of the event. Contains numbers, in the format `{x, y}`. + */ + getViewBoxCoordinatesFromEvent = function(svgRoot, event) { + var ctm, foo, pos; + foo = { + x: null, + y: null + }; + if (event.type === "touchstart" || event.type === "touchmove") { + if ((event.originalEvent != null) && (event.touches == null)) { + foo.x = event.originalEvent.touches[0].clientX; + foo.y = event.originalEvent.touches[0].clientY; + } else { + foo.x = event.touches[0].clientX; + foo.y = event.touches[0].clientY; + } + } else { + if (event.clientX != null) { + foo.x = event.clientX; + foo.y = event.clientY; + } else { + foo.x = event.originalEvent.clientX; + foo.y = event.originalEvent.clientY; + } + } + pos = svgRoot.createSVGPoint(); + pos.x = parseInt(foo.x, 10); + pos.y = parseInt(foo.y, 10); + ctm = svgRoot.getScreenCTM(); + ctm = ctm.inverse(); + pos = pos.matrixTransform(ctm); + return pos; + }; + return $.fn.svgPanZoom = function(options) { + var ret; + ret = []; + this.each(function() { + var $animationDiv, dragStarted, horizontalSizeIncrement, key, opts, preventClick, value, vb, verticalSizeIncrement, viewBox; + opts = $.extend(true, {}, defaultOptions, options); + opts.$svg = $(this); + if (opts.animationTime == null) { + opts.animationTime = 0; + } + opts.$svg[0].setAttribute("preserveAspectRatio", "xMidYMid meet"); + vb = $.extend({}, this.viewBox.baseVal); + if (vb.x == null) { + vb.x = 0; + } + if (vb.y == null) { + vb.y = 0; + } + if (vb.width == null) { + vb.width = 0; + } + if (vb.height == null) { + vb.height = 0; + } + if (opts.initialViewBox != null) { + if (typeof opts.initialViewBox === "string") { + vb = parseViewBoxString(opts.initialViewBox); + } else if (typeof opts.initialViewBox === "object") { + vb = $.extend({}, defaultViewBox, opts.initialViewBox); + } else { + throw "initialViewBox is of invalid type"; + } + } else if (vb.x === 0 && vb.y === 0 && vb.width === 0 && vb.height === 0) { + vb = defaultViewBox; + } + viewBox = vb; + opts.initialViewBox = $.extend({}, viewBox); + if (opts.limits == null) { + horizontalSizeIncrement = viewBox.width * 0.15; + verticalSizeIncrement = viewBox.height * 0.15; + opts.limits = { + x: viewBox.x - horizontalSizeIncrement, + y: viewBox.y - verticalSizeIncrement, + x2: viewBox.x + viewBox.width + horizontalSizeIncrement, + y2: viewBox.y + viewBox.height + verticalSizeIncrement + }; + } + opts.reset = function() { + var inivb; + inivb = this.initialViewBox; + this.setViewBox(inivb.x, inivb.y, inivb.width, inivb.height, 0); + }; + opts.getViewBox = function() { + return $.extend({}, viewBox); + }; + $animationDiv = $("
"); + opts.setViewBox = function(x, y, width, height, animationTime) { + if (animationTime == null) { + animationTime = this.animationTime; + } + if (animationTime > 0) { + $animationDiv.css({ + left: viewBox.x + "px", + top: viewBox.y + "px", + width: viewBox.width + "px", + height: viewBox.height + "px" + }); + } + viewBox = { + x: x != null ? x : viewBox.x, + y: y != null ? y : viewBox.y, + width: width ? width : viewBox.width, + height: height ? height : viewBox.height + }; + viewBox = checkLimits(viewBox, this.limits); + if (animationTime > 0) { + $animationDiv.stop().animate({ + left: viewBox.x, + top: viewBox.y, + width: viewBox.width, + height: viewBox.height + }, { + duration: animationTime, + easing: "linear", + step: (function(value, properties) { + var $div; + $div = $animationDiv; + this.$svg[0].setAttribute("viewBox", ($div.css("left").slice(0, -2)) + " " + ($div.css("top").slice(0, -2)) + " " + ($div.css("width").slice(0, -2)) + " " + ($div.css("height").slice(0, -2))); + }).bind(this) + }); + } else { + this.$svg[0].setAttribute("viewBox", viewBox.x + " " + viewBox.y + " " + viewBox.width + " " + viewBox.height); + } + }; + opts.panLeft = function(amount, animationTime) { + if (amount == null) { + amount = this.panFactor; + } + if (animationTime == null) { + animationTime = this.animationTime; + } + this.panRight(-amount, animationTime); + }; + opts.panRight = function(amount, animationTime) { + if (amount == null) { + amount = this.panFactor; + } + if (animationTime == null) { + animationTime = this.animationTime; + } + this.setViewBox(viewBox.x + amount, null, null, null, animationTime); + }; + opts.panUp = function(amount, animationTime) { + if (amount == null) { + amount = this.panFactor; + } + if (animationTime == null) { + animationTime = this.animationTime; + } + this.panDown(-amount, animationTime); + }; + opts.panDown = function(amount, animationTime) { + if (amount == null) { + amount = this.panFactor; + } + if (animationTime == null) { + animationTime = this.animationTime; + } + this.setViewBox(null, viewBox.y + amount, null, null, animationTime); + }; + opts.zoomIn = function(amount, animationTime) { + if (amount == null) { + amount = this.zoomFactor; + } + if (animationTime == null) { + animationTime = this.animationTime; + } + this.zoomOut(-amount, animationTime); + }; + opts.zoomOut = function(amount, animationTime) { + var center, newHeight, newWidth; + if (amount == null) { + amount = this.zoomFactor; + } + if (animationTime == null) { + animationTime = this.animationTime; + } + if (amount === 0) { + return; + } else if (amount < 0) { + amount = Math.abs(amount); + newWidth = viewBox.width / (1 + amount); + newHeight = viewBox.height / (1 + amount); + } else { + newWidth = viewBox.width * (1 + amount); + newHeight = viewBox.height * (1 + amount); + } + center = { + x: viewBox.x + viewBox.width / 2, + y: viewBox.y + viewBox.height / 2 + }; + this.setViewBox(center.x - newWidth / 2, center.y - newWidth / 2, newWidth, newHeight, animationTime); + }; + opts.setCenter = function(x, y, animationTime) { + if (animationTime == null) { + animationTime = this.animationTime; + } + this.setViewBox(x - viewBox.width / 2, y - viewBox.height / 2, viewBox.width, viewBox.height, animationTime); + }; + for (key in opts) { + if (!hasProp.call(opts, key)) continue; + value = opts[key]; + if (typeof value === "function") { + opts.key = value.bind(opts); + } + } + opts.$svg.on("mousewheel DOMMouseScroll MozMousePixelScroll", (function(ev) { + var delta, minHeight, minWidth, newMousePosition, newViewBox, newcenter, oldDistanceFromCenter, oldMousePosition, oldViewBox, oldcenter, reductionFactor; + delta = parseInt(ev.originalEvent.wheelDelta || -ev.originalEvent.detail); + if (delta === 0 || opts.events.mouseWheel !== true) { + return; + } + oldViewBox = this.getViewBox(); + ev.preventDefault(); + ev.stopPropagation(); + oldMousePosition = getViewBoxCoordinatesFromEvent(this.$svg[0], ev); + oldcenter = { + x: viewBox.x + viewBox.width / 2, + y: viewBox.y + viewBox.height / 2 + }; + oldDistanceFromCenter = { + x: oldcenter.x - oldMousePosition.x, + y: oldcenter.y - oldMousePosition.y + }; + if (delta > 0) { + this.zoomIn(void 0, 0); + minWidth = this.initialViewBox.width / this.maxZoom; + minHeight = this.initialViewBox.height / this.maxZoom; + if (viewBox.width < minWidth) { + reductionFactor = minWidth / viewBox.width; + viewBox.width = minWidth; + viewBox.height = viewBox.height * reductionFactor; + } + if (viewBox.height < minHeight) { + reductionFactor = minHeight / viewBox.height; + viewBox.height = minHeight; + viewBox.width = viewBox.width * reductionFactor; + } + } else { + this.zoomOut(void 0, 0); + } + newMousePosition = getViewBoxCoordinatesFromEvent(this.$svg[0], ev); + newcenter = { + x: oldcenter.x + (oldMousePosition.x - newMousePosition.x), + y: oldcenter.y + (oldMousePosition.y - newMousePosition.y) + }; + this.setCenter(newcenter.x, newcenter.y, 0); + newViewBox = this.getViewBox(); + this.setViewBox(oldViewBox.x, oldViewBox.y, oldViewBox.width, oldViewBox.height, 0); + this.setViewBox(newViewBox.x, newViewBox.y, newViewBox.width, newViewBox.height); + }).bind(opts)); + opts.$svg.dblclick((function(ev) { + if (opts.events.doubleClick !== true) { + return; + } + ev.preventDefault(); + ev.stopPropagation(); + return this.zoomIn(); + }).bind(opts)); + opts.$svg[0].addEventListener("click", function(ev) { + var preventClick; + if (preventClick) { + preventClick = false; + ev.stopPropagation(); + return ev.preventDefault(); + } + }, true); + dragStarted = false; + preventClick = false; + opts.$svg.on("mousedown touchstart", (function(ev) { + var $body, domBody, initialViewBox, mouseMoveCallback, mouseUpCallback, oldCursor; + if (dragStarted) { + return; + } + if (opts.events.drag !== true || (ev.type === "mousedown" && ev.which !== 1)) { + return; + } + dragStarted = true; + preventClick = false; + ev.preventDefault(); + ev.stopPropagation(); + initialViewBox = $.extend({}, viewBox); + $body = $(window.document.body); + domBody = $body[0]; + oldCursor = $body.css("cursor"); + if (this.events.dragCursor != null) { + $body.css("cursor", this.events.dragCursor); + } + mouseMoveCallback = (function(ev2) { + var currentMousePosition, initialMousePosition; + ev2.preventDefault(); + ev2.stopPropagation(); + initialMousePosition = getViewBoxCoordinatesFromEvent(this.$svg[0], ev); + currentMousePosition = getViewBoxCoordinatesFromEvent(this.$svg[0], ev2); + if (Math.sqrt(Math.pow(ev.pageX + ev2.pageX, 2) + Math.pow(ev.pageY + ev2.pageY, 2)) > 3) { + preventClick = true; + } + this.setViewBox(initialViewBox.x + initialMousePosition.x - currentMousePosition.x, initialViewBox.y + initialMousePosition.y - currentMousePosition.y, null, null, 0); + }).bind(opts); + mouseUpCallback = (function(ev2) { + if (ev2.type === "mouseout" && ev2.target !== ev2.currentTarget) { + return; + } + ev2.preventDefault(); + ev2.stopPropagation(); + domBody.removeEventListener("mousemove", mouseMoveCallback, true); + domBody.removeEventListener("touchmove", mouseMoveCallback, true); + domBody.removeEventListener("mouseup", mouseUpCallback, true); + domBody.removeEventListener("touchend", mouseUpCallback, true); + domBody.removeEventListener("touchcancel", mouseUpCallback, true); + domBody.removeEventListener("mouseout", mouseUpCallback, true); + if (this.events.dragCursor != null) { + $body.css("cursor", oldCursor); + } + dragStarted = false; + }).bind(opts); + domBody.addEventListener("mousemove", mouseMoveCallback, true); + domBody.addEventListener("touchmove", mouseMoveCallback, true); + domBody.addEventListener("mouseup", mouseUpCallback, true); + domBody.addEventListener("touchend", mouseUpCallback, true); + domBody.addEventListener("touchcancel", mouseUpCallback, true); + domBody.addEventListener("mouseout", mouseUpCallback, true); + }).bind(opts)); + opts.setViewBox(vb.x, vb.y, vb.width, vb.height, 0); + ret.push(opts); + }); + if (ret.length === 0) { + return null; + } + if (ret.length === 1) { + return ret[0]; + } else { + return ret; + } + }; + })(jQuery); + +}).call(this); + +//# sourceMappingURL=jquery.svg.pan.zoom.js.map \ No newline at end of file diff --git a/muk_web_preview_image/static/lib/viewer/jquery-viewer.js b/muk_web_preview_image/static/lib/viewer/jquery-viewer.js new file mode 100644 index 0000000..cdadff3 --- /dev/null +++ b/muk_web_preview_image/static/lib/viewer/jquery-viewer.js @@ -0,0 +1,75 @@ +/*! + * jQuery Viewer v1.0.0 + * https://github.com/fengyuanchen/jquery-viewer + * + * Copyright (c) 2018 Chen Fengyuan + * Released under the MIT license + * + * Date: 2018-04-01T05:58:29.617Z + */ + +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery'), require('viewerjs')) : + typeof define === 'function' && define.amd ? define(['jquery', 'viewerjs'], factory) : + (factory(global.jQuery,global.Viewer)); +}(this, (function ($,Viewer) { 'use strict'; + + $ = $ && $.hasOwnProperty('default') ? $['default'] : $; + Viewer = Viewer && Viewer.hasOwnProperty('default') ? Viewer['default'] : Viewer; + + if ($.fn) { + var AnotherViewer = $.fn.viewer; + var NAMESPACE = 'viewer'; + + $.fn.viewer = function jQueryViewer(option) { + for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + + var result = void 0; + + this.each(function (i, element) { + var $element = $(element); + var isDestroy = option === 'destroy'; + var viewer = $element.data(NAMESPACE); + + if (!viewer) { + if (isDestroy) { + return; + } + + var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); + + viewer = new Viewer(element, options); + $element.data(NAMESPACE, viewer); + } + + if (typeof option === 'string') { + var fn = viewer[option]; + + if ($.isFunction(fn)) { + result = fn.apply(viewer, args); + + if (result === viewer) { + result = undefined; + } + + if (isDestroy) { + $element.removeData(NAMESPACE); + } + } + } + }); + + return result !== undefined ? result : this; + }; + + $.fn.viewer.Constructor = Viewer; + $.fn.viewer.setDefaults = Viewer.setDefaults; + $.fn.viewer.noConflict = function noConflict() { + $.fn.viewer = AnotherViewer; + return this; + }; + } + +}))); \ No newline at end of file diff --git a/muk_web_preview_image/static/lib/viewer/viewer.css b/muk_web_preview_image/static/lib/viewer/viewer.css new file mode 100644 index 0000000..20e06a9 --- /dev/null +++ b/muk_web_preview_image/static/lib/viewer/viewer.css @@ -0,0 +1,450 @@ +/*! + * Viewer.js v1.3.2 + * https://fengyuanchen.github.io/viewerjs + * + * Copyright 2015-present Chen Fengyuan + * Released under the MIT license + * + * Date: 2019-01-24T11:01:30.299Z + */ + +.viewer-zoom-in::before, +.viewer-zoom-out::before, +.viewer-one-to-one::before, +.viewer-reset::before, +.viewer-prev::before, +.viewer-play::before, +.viewer-next::before, +.viewer-rotate-left::before, +.viewer-rotate-right::before, +.viewer-flip-horizontal::before, +.viewer-flip-vertical::before, +.viewer-fullscreen::before, +.viewer-fullscreen-exit::before, +.viewer-close::before { + background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARgAAAAUCAYAAABWOyJDAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTNui8sowAAAQPSURBVHic7Zs/iFxVFMa/0U2UaJGksUgnIVhYxVhpjDbZCBmLdAYECxsRFBTUamcXUiSNncgKQbSxsxH8gzAP3FU2jY0kKKJNiiiIghFlccnP4p3nPCdv3p9778vsLOcHB2bfveeb7955c3jvvNkBIMdxnD64a94GHMfZu3iBcRynN7zAOI7TG15gHCeeNUkr8zaxG2lbYDYsdgMbktBsP03jdQwljSXdtBhLOmtjowC9Mg9L+knSlcD8TNKpSA9lBpK2JF2VdDSR5n5J64m0qli399hNFMUlpshQii5jbXTbHGviB0nLNeNDSd9VO4A2UdB2fp+x0eCnaXxWXGA2X0au/3HgN9P4LFCjIANOJdrLr0zzZ+BEpNYDwKbpnQMeAw4m8HjQtM6Z9qa917zPQwFr3M5KgA6J5rTJCdFZJj9/lyvGhsDvwFNVuV2MhhjrK6b9bFiE+j1r87eBl4HDwCF7/U/k+ofAX5b/EXBv5JoLMuILzf3Ap6Z3EzgdqHMCuF7hcQf4HDgeoHnccncqdK/TvSDWffFXI/exICY/xZyqc6XLWF1UFZna4gJ7q8BsRvgd2/xXpo6P+D9dfT7PpECtA3cnWPM0GXGFZh/wgWltA+cDNC7X+AP4GzjZQe+k5dRxuYPeiuXU7e1qwLpDz7dFjXKRaSwuMLvAlG8zZlG+YmiK1HoFqT7wP2z+4Q45TfEGcMt01xLoNZEBTwRqD4BLpnMLeC1A41UmVxsXgXeBayV/Wx20rpTyrpnWRft7p6O/FdqzGrDukPNtkaMoMo3FBdBSQMOnYBCReyf05s126fU9ytfX98+mY54Kxnp7S9K3kj6U9KYdG0h6UdLbkh7poFXMfUnSOyVvL0h6VtIXHbS6nOP+s/Zm9mvyXW1uuC9ohZ72E9uDmXWLJOB1GxsH+DxPftsB8B6wlGDN02TAkxG6+4D3TWsbeC5CS8CDFce+AW500LhhOW2020TRjK3b21HEmgti9m0RonxbdMZeVzV+/4tF3cBpP7E9mKHNL5q8h5g0eYsCMQz0epq8gQrwMXAgcs0FGXGFRcB9wCemF9PkbYqM/Bas7fxLwNeJPdTdpo4itQti8lPMqTpXuozVRVXPpbHI3KkNTB1NfkL81j2mvhDp91HgV9MKuRIqrykj3WPq4rHyL+axj8/qGPmTqi6F9YDlHOvJU6oYcTsh/TYSzWmTE6JT19CtLTJt32D6CmHe0eQn1O8z5AXgT4sx4Vcu0/EQecMydB8z0hUWkTd2t4CrwNEePqMBcAR4mrBbwyXLPWJa8zrXmmLEhNBmfpkuY2102xxrih+pb+ieAb6vGhuA97UcJ5KR8gZ77K+99xxeYBzH6Q3/Z0fHcXrDC4zjOL3hBcZxnN74F+zlvXFWXF9PAAAAAElFTkSuQmCC'); + background-repeat: no-repeat; + color: transparent; + display: block; + font-size: 0; + height: 20px; + line-height: 0; + width: 20px; +} + +.viewer-zoom-in::before { + background-position: 0 0; + content: 'Zoom In'; +} + +.viewer-zoom-out::before { + background-position: -20px 0; + content: 'Zoom Out'; +} + +.viewer-one-to-one::before { + background-position: -40px 0; + content: 'One to One'; +} + +.viewer-reset::before { + background-position: -60px 0; + content: 'Reset'; +} + +.viewer-prev::before { + background-position: -80px 0; + content: 'Previous'; +} + +.viewer-play::before { + background-position: -100px 0; + content: 'Play'; +} + +.viewer-next::before { + background-position: -120px 0; + content: 'Next'; +} + +.viewer-rotate-left::before { + background-position: -140px 0; + content: 'Rotate Left'; +} + +.viewer-rotate-right::before { + background-position: -160px 0; + content: 'Rotate Right'; +} + +.viewer-flip-horizontal::before { + background-position: -180px 0; + content: 'Flip Horizontal'; +} + +.viewer-flip-vertical::before { + background-position: -200px 0; + content: 'Flip Vertical'; +} + +.viewer-fullscreen::before { + background-position: -220px 0; + content: 'Enter Full Screen'; +} + +.viewer-fullscreen-exit::before { + background-position: -240px 0; + content: 'Exit Full Screen'; +} + +.viewer-close::before { + background-position: -260px 0; + content: 'Close'; +} + +.viewer-container { + bottom: 0; + direction: ltr; + font-size: 0; + left: 0; + line-height: 0; + overflow: hidden; + position: absolute; + right: 0; + -webkit-tap-highlight-color: transparent; + top: 0; + -ms-touch-action: none; + touch-action: none; + -webkit-touch-callout: none; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.viewer-container::selection, +.viewer-container *::selection { + background-color: transparent; +} + +.viewer-container img { + display: block; + height: auto; + max-height: none !important; + max-width: none !important; + min-height: 0 !important; + min-width: 0 !important; + width: 100%; +} + +.viewer-canvas { + bottom: 0; + left: 0; + overflow: hidden; + position: absolute; + right: 0; + top: 0; +} + +.viewer-canvas > img { + height: auto; + margin: 15px auto; + max-width: 90% !important; + width: auto; +} + +.viewer-footer { + bottom: 0; + left: 0; + overflow: hidden; + position: absolute; + right: 0; + text-align: center; +} + +.viewer-navbar { + background-color: rgba(0, 0, 0, 0.5); + overflow: hidden; +} + +.viewer-list { + -webkit-box-sizing: content-box; + box-sizing: content-box; + height: 50px; + margin: 0; + overflow: hidden; + padding: 1px 0; +} + +.viewer-list > li { + color: transparent; + cursor: pointer; + float: left; + font-size: 0; + height: 50px; + line-height: 0; + opacity: 0.5; + overflow: hidden; + -webkit-transition: opacity 0.15s; + transition: opacity 0.15s; + width: 30px; +} + +.viewer-list > li:hover { + opacity: 0.75; +} + +.viewer-list > li + li { + margin-left: 1px; +} + +.viewer-list > .viewer-loading { + position: relative; +} + +.viewer-list > .viewer-loading::after { + border-width: 2px; + height: 20px; + margin-left: -10px; + margin-top: -10px; + width: 20px; +} + +.viewer-list > .viewer-active, +.viewer-list > .viewer-active:hover { + opacity: 1; +} + +.viewer-player { + background-color: #000; + bottom: 0; + cursor: none; + display: none; + left: 0; + position: absolute; + right: 0; + top: 0; +} + +.viewer-player > img { + left: 0; + position: absolute; + top: 0; +} + +.viewer-toolbar > ul { + display: inline-block; + margin: 0 auto 5px; + overflow: hidden; + padding: 3px 0; +} + +.viewer-toolbar > ul > li { + background-color: rgba(0, 0, 0, 0.5); + border-radius: 50%; + cursor: pointer; + float: left; + height: 24px; + overflow: hidden; + -webkit-transition: background-color 0.15s; + transition: background-color 0.15s; + width: 24px; +} + +.viewer-toolbar > ul > li:hover { + background-color: rgba(0, 0, 0, 0.8); +} + +.viewer-toolbar > ul > li::before { + margin: 2px; +} + +.viewer-toolbar > ul > li + li { + margin-left: 1px; +} + +.viewer-toolbar > ul > .viewer-small { + height: 18px; + margin-bottom: 3px; + margin-top: 3px; + width: 18px; +} + +.viewer-toolbar > ul > .viewer-small::before { + margin: -1px; +} + +.viewer-toolbar > ul > .viewer-large { + height: 30px; + margin-bottom: -3px; + margin-top: -3px; + width: 30px; +} + +.viewer-toolbar > ul > .viewer-large::before { + margin: 5px; +} + +.viewer-tooltip { + background-color: rgba(0, 0, 0, 0.8); + border-radius: 10px; + color: #fff; + display: none; + font-size: 12px; + height: 20px; + left: 50%; + line-height: 20px; + margin-left: -25px; + margin-top: -10px; + position: absolute; + text-align: center; + top: 50%; + width: 50px; +} + +.viewer-title { + color: #ccc; + display: inline-block; + font-size: 12px; + line-height: 1; + margin: 0 5% 5px; + max-width: 90%; + opacity: 0.8; + overflow: hidden; + text-overflow: ellipsis; + -webkit-transition: opacity 0.15s; + transition: opacity 0.15s; + white-space: nowrap; +} + +.viewer-title:hover { + opacity: 1; +} + +.viewer-button { + background-color: rgba(0, 0, 0, 0.5); + border-radius: 50%; + cursor: pointer; + height: 80px; + overflow: hidden; + position: absolute; + right: -40px; + top: -40px; + -webkit-transition: background-color 0.15s; + transition: background-color 0.15s; + width: 80px; +} + +.viewer-button:focus, +.viewer-button:hover { + background-color: rgba(0, 0, 0, 0.8); +} + +.viewer-button::before { + bottom: 15px; + left: 15px; + position: absolute; +} + +.viewer-fixed { + position: fixed; +} + +.viewer-open { + overflow: hidden; +} + +.viewer-show { + display: block; +} + +.viewer-hide { + display: none; +} + +.viewer-backdrop { + background-color: rgba(0, 0, 0, 0.5); +} + +.viewer-invisible { + visibility: hidden; +} + +.viewer-move { + cursor: move; + cursor: -webkit-grab; + cursor: grab; +} + +.viewer-fade { + opacity: 0; +} + +.viewer-in { + opacity: 1; +} + +.viewer-transition { + -webkit-transition: all 0.3s; + transition: all 0.3s; +} + +@-webkit-keyframes viewer-spinner { + 0% { + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + + 100% { + -webkit-transform: rotate(360deg); + transform: rotate(360deg); + } +} + +@keyframes viewer-spinner { + 0% { + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + + 100% { + -webkit-transform: rotate(360deg); + transform: rotate(360deg); + } +} + +.viewer-loading::after { + -webkit-animation: viewer-spinner 1s linear infinite; + animation: viewer-spinner 1s linear infinite; + border: 4px solid rgba(255, 255, 255, 0.1); + border-left-color: rgba(255, 255, 255, 0.5); + border-radius: 50%; + content: ''; + display: inline-block; + height: 40px; + left: 50%; + margin-left: -20px; + margin-top: -20px; + position: absolute; + top: 50%; + width: 40px; + z-index: 1; +} + +@media (max-width: 767px) { + .viewer-hide-xs-down { + display: none; + } +} + +@media (max-width: 991px) { + .viewer-hide-sm-down { + display: none; + } +} + +@media (max-width: 1199px) { + .viewer-hide-md-down { + display: none; + } +} \ No newline at end of file diff --git a/muk_web_preview_image/static/lib/viewer/viewer.js b/muk_web_preview_image/static/lib/viewer/viewer.js new file mode 100644 index 0000000..79b585b --- /dev/null +++ b/muk_web_preview_image/static/lib/viewer/viewer.js @@ -0,0 +1,3020 @@ +/*! + * Viewer.js v1.3.2 + * https://fengyuanchen.github.io/viewerjs + * + * Copyright 2015-present Chen Fengyuan + * Released under the MIT license + * + * Date: 2019-01-24T11:01:33.473Z + */ + +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global.Viewer = factory()); +}(this, (function () { 'use strict'; + + function _typeof(obj) { + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { + _typeof = function (obj) { + return typeof obj; + }; + } else { + _typeof = function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + } + + return _typeof(obj); + } + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; + } + + var DEFAULTS = { + /** + * Enable a modal backdrop, specify `static` for a backdrop + * which doesn't close the modal on click. + * @type {boolean} + */ + backdrop: true, + + /** + * Show the button on the top-right of the viewer. + * @type {boolean} + */ + button: true, + + /** + * Show the navbar. + * @type {boolean | number} + */ + navbar: true, + + /** + * Specify the visibility and the content of the title. + * @type {boolean | number | Function | Array} + */ + title: true, + + /** + * Show the toolbar. + * @type {boolean | number | Object} + */ + toolbar: true, + + /** + * Custom class name(s) to add to the viewer's root element. + * @type {string} + */ + className: '', + + /** + * Define where to put the viewer in modal mode. + * @type {string | Element} + */ + container: 'body', + + /** + * Filter the images for viewing. Return true if the image is viewable. + * @type {Function} + */ + filter: null, + + /** + * Enable to request fullscreen when play. + * @type {boolean} + */ + fullscreen: true, + + /** + * Define the initial index of image for viewing. + * @type {number} + */ + initialViewIndex: 0, + + /** + * Enable inline mode. + * @type {boolean} + */ + inline: false, + + /** + * The amount of time to delay between automatically cycling an image when playing. + * @type {number} + */ + interval: 5000, + + /** + * Enable keyboard support. + * @type {boolean} + */ + keyboard: true, + + /** + * Indicate if show a loading spinner when load image or not. + * @type {boolean} + */ + loading: true, + + /** + * Indicate if enable loop viewing or not. + * @type {boolean} + */ + loop: true, + + /** + * Min width of the viewer in inline mode. + * @type {number} + */ + minWidth: 200, + + /** + * Min height of the viewer in inline mode. + * @type {number} + */ + minHeight: 100, + + /** + * Enable to move the image. + * @type {boolean} + */ + movable: true, + + /** + * Enable to zoom the image. + * @type {boolean} + */ + zoomable: true, + + /** + * Enable to rotate the image. + * @type {boolean} + */ + rotatable: true, + + /** + * Enable to scale the image. + * @type {boolean} + */ + scalable: true, + + /** + * Indicate if toggle the image size between its natural size + * and initial size when double click on the image or not. + * @type {boolean} + */ + toggleOnDblclick: true, + + /** + * Show the tooltip with image ratio (percentage) when zoom in or zoom out. + * @type {boolean} + */ + tooltip: true, + + /** + * Enable CSS3 Transition for some special elements. + * @type {boolean} + */ + transition: true, + + /** + * Define the CSS `z-index` value of viewer in modal mode. + * @type {number} + */ + zIndex: 2015, + + /** + * Define the CSS `z-index` value of viewer in inline mode. + * @type {number} + */ + zIndexInline: 0, + + /** + * Define the ratio when zoom the image by wheeling mouse. + * @type {number} + */ + zoomRatio: 0.1, + + /** + * Define the min ratio of the image when zoom out. + * @type {number} + */ + minZoomRatio: 0.01, + + /** + * Define the max ratio of the image when zoom in. + * @type {number} + */ + maxZoomRatio: 100, + + /** + * Define where to get the original image URL for viewing. + * @type {string | Function} + */ + url: 'src', + + /** + * Event shortcuts. + * @type {Function} + */ + ready: null, + show: null, + shown: null, + hide: null, + hidden: null, + view: null, + viewed: null, + zoom: null, + zoomed: null + }; + + var TEMPLATE = '
' + '
' + '' + '
' + '
' + '
' + '
'; + + var IS_BROWSER = typeof window !== 'undefined'; + var WINDOW = IS_BROWSER ? window : {}; + var IS_TOUCH_DEVICE = IS_BROWSER ? 'ontouchstart' in WINDOW.document.documentElement : false; + var HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false; + var NAMESPACE = 'viewer'; // Actions + + var ACTION_MOVE = 'move'; + var ACTION_SWITCH = 'switch'; + var ACTION_ZOOM = 'zoom'; // Classes + + var CLASS_ACTIVE = "".concat(NAMESPACE, "-active"); + var CLASS_CLOSE = "".concat(NAMESPACE, "-close"); + var CLASS_FADE = "".concat(NAMESPACE, "-fade"); + var CLASS_FIXED = "".concat(NAMESPACE, "-fixed"); + var CLASS_FULLSCREEN = "".concat(NAMESPACE, "-fullscreen"); + var CLASS_FULLSCREEN_EXIT = "".concat(NAMESPACE, "-fullscreen-exit"); + var CLASS_HIDE = "".concat(NAMESPACE, "-hide"); + var CLASS_HIDE_MD_DOWN = "".concat(NAMESPACE, "-hide-md-down"); + var CLASS_HIDE_SM_DOWN = "".concat(NAMESPACE, "-hide-sm-down"); + var CLASS_HIDE_XS_DOWN = "".concat(NAMESPACE, "-hide-xs-down"); + var CLASS_IN = "".concat(NAMESPACE, "-in"); + var CLASS_INVISIBLE = "".concat(NAMESPACE, "-invisible"); + var CLASS_LOADING = "".concat(NAMESPACE, "-loading"); + var CLASS_MOVE = "".concat(NAMESPACE, "-move"); + var CLASS_OPEN = "".concat(NAMESPACE, "-open"); + var CLASS_SHOW = "".concat(NAMESPACE, "-show"); + var CLASS_TRANSITION = "".concat(NAMESPACE, "-transition"); // Events + + var EVENT_CLICK = 'click'; + var EVENT_DBLCLICK = 'dblclick'; + var EVENT_DRAG_START = 'dragstart'; + var EVENT_HIDDEN = 'hidden'; + var EVENT_HIDE = 'hide'; + var EVENT_KEY_DOWN = 'keydown'; + var EVENT_LOAD = 'load'; + var EVENT_TOUCH_START = IS_TOUCH_DEVICE ? 'touchstart' : 'mousedown'; + var EVENT_TOUCH_MOVE = IS_TOUCH_DEVICE ? 'touchmove' : 'mousemove'; + var EVENT_TOUCH_END = IS_TOUCH_DEVICE ? 'touchend touchcancel' : 'mouseup'; + var EVENT_POINTER_DOWN = HAS_POINTER_EVENT ? 'pointerdown' : EVENT_TOUCH_START; + var EVENT_POINTER_MOVE = HAS_POINTER_EVENT ? 'pointermove' : EVENT_TOUCH_MOVE; + var EVENT_POINTER_UP = HAS_POINTER_EVENT ? 'pointerup pointercancel' : EVENT_TOUCH_END; + var EVENT_READY = 'ready'; + var EVENT_RESIZE = 'resize'; + var EVENT_SHOW = 'show'; + var EVENT_SHOWN = 'shown'; + var EVENT_TRANSITION_END = 'transitionend'; + var EVENT_VIEW = 'view'; + var EVENT_VIEWED = 'viewed'; + var EVENT_WHEEL = 'wheel'; + var EVENT_ZOOM = 'zoom'; + var EVENT_ZOOMED = 'zoomed'; // Data keys + + var DATA_ACTION = "".concat(NAMESPACE, "Action"); // RegExps + + var REGEXP_SPACES = /\s\s*/; // Misc + + var BUTTONS = ['zoom-in', 'zoom-out', 'one-to-one', 'reset', 'prev', 'play', 'next', 'rotate-left', 'rotate-right', 'flip-horizontal', 'flip-vertical']; + + /** + * Check if the given value is a string. + * @param {*} value - The value to check. + * @returns {boolean} Returns `true` if the given value is a string, else `false`. + */ + + function isString(value) { + return typeof value === 'string'; + } + /** + * Check if the given value is not a number. + */ + + var isNaN = Number.isNaN || WINDOW.isNaN; + /** + * Check if the given value is a number. + * @param {*} value - The value to check. + * @returns {boolean} Returns `true` if the given value is a number, else `false`. + */ + + function isNumber(value) { + return typeof value === 'number' && !isNaN(value); + } + /** + * Check if the given value is undefined. + * @param {*} value - The value to check. + * @returns {boolean} Returns `true` if the given value is undefined, else `false`. + */ + + function isUndefined(value) { + return typeof value === 'undefined'; + } + /** + * Check if the given value is an object. + * @param {*} value - The value to check. + * @returns {boolean} Returns `true` if the given value is an object, else `false`. + */ + + function isObject(value) { + return _typeof(value) === 'object' && value !== null; + } + var hasOwnProperty = Object.prototype.hasOwnProperty; + /** + * Check if the given value is a plain object. + * @param {*} value - The value to check. + * @returns {boolean} Returns `true` if the given value is a plain object, else `false`. + */ + + function isPlainObject(value) { + if (!isObject(value)) { + return false; + } + + try { + var _constructor = value.constructor; + var prototype = _constructor.prototype; + return _constructor && prototype && hasOwnProperty.call(prototype, 'isPrototypeOf'); + } catch (error) { + return false; + } + } + /** + * Check if the given value is a function. + * @param {*} value - The value to check. + * @returns {boolean} Returns `true` if the given value is a function, else `false`. + */ + + function isFunction(value) { + return typeof value === 'function'; + } + /** + * Iterate the given data. + * @param {*} data - The data to iterate. + * @param {Function} callback - The process function for each element. + * @returns {*} The original data. + */ + + function forEach(data, callback) { + if (data && isFunction(callback)) { + if (Array.isArray(data) || isNumber(data.length) + /* array-like */ + ) { + var length = data.length; + var i; + + for (i = 0; i < length; i += 1) { + if (callback.call(data, data[i], i, data) === false) { + break; + } + } + } else if (isObject(data)) { + Object.keys(data).forEach(function (key) { + callback.call(data, data[key], key, data); + }); + } + } + + return data; + } + /** + * Extend the given object. + * @param {*} obj - The object to be extended. + * @param {*} args - The rest objects which will be merged to the first object. + * @returns {Object} The extended object. + */ + + var assign = Object.assign || function assign(obj) { + for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + + if (isObject(obj) && args.length > 0) { + args.forEach(function (arg) { + if (isObject(arg)) { + Object.keys(arg).forEach(function (key) { + obj[key] = arg[key]; + }); + } + }); + } + + return obj; + }; + var REGEXP_SUFFIX = /^(?:width|height|left|top|marginLeft|marginTop)$/; + /** + * Apply styles to the given element. + * @param {Element} element - The target element. + * @param {Object} styles - The styles for applying. + */ + + function setStyle(element, styles) { + var style = element.style; + forEach(styles, function (value, property) { + if (REGEXP_SUFFIX.test(property) && isNumber(value)) { + value += 'px'; + } + + style[property] = value; + }); + } + /** + * Check if the given element has a special class. + * @param {Element} element - The element to check. + * @param {string} value - The class to search. + * @returns {boolean} Returns `true` if the special class was found. + */ + + function hasClass(element, value) { + return element.classList ? element.classList.contains(value) : element.className.indexOf(value) > -1; + } + /** + * Add classes to the given element. + * @param {Element} element - The target element. + * @param {string} value - The classes to be added. + */ + + function addClass(element, value) { + if (!value) { + return; + } + + if (isNumber(element.length)) { + forEach(element, function (elem) { + addClass(elem, value); + }); + return; + } + + if (element.classList) { + element.classList.add(value); + return; + } + + var className = element.className.trim(); + + if (!className) { + element.className = value; + } else if (className.indexOf(value) < 0) { + element.className = "".concat(className, " ").concat(value); + } + } + /** + * Remove classes from the given element. + * @param {Element} element - The target element. + * @param {string} value - The classes to be removed. + */ + + function removeClass(element, value) { + if (!value) { + return; + } + + if (isNumber(element.length)) { + forEach(element, function (elem) { + removeClass(elem, value); + }); + return; + } + + if (element.classList) { + element.classList.remove(value); + return; + } + + if (element.className.indexOf(value) >= 0) { + element.className = element.className.replace(value, ''); + } + } + /** + * Add or remove classes from the given element. + * @param {Element} element - The target element. + * @param {string} value - The classes to be toggled. + * @param {boolean} added - Add only. + */ + + function toggleClass(element, value, added) { + if (!value) { + return; + } + + if (isNumber(element.length)) { + forEach(element, function (elem) { + toggleClass(elem, value, added); + }); + return; + } // IE10-11 doesn't support the second parameter of `classList.toggle` + + + if (added) { + addClass(element, value); + } else { + removeClass(element, value); + } + } + var REGEXP_HYPHENATE = /([a-z\d])([A-Z])/g; + /** + * Transform the given string from camelCase to kebab-case + * @param {string} value - The value to transform. + * @returns {string} The transformed value. + */ + + function hyphenate(value) { + return value.replace(REGEXP_HYPHENATE, '$1-$2').toLowerCase(); + } + /** + * Get data from the given element. + * @param {Element} element - The target element. + * @param {string} name - The data key to get. + * @returns {string} The data value. + */ + + function getData(element, name) { + if (isObject(element[name])) { + return element[name]; + } + + if (element.dataset) { + return element.dataset[name]; + } + + return element.getAttribute("data-".concat(hyphenate(name))); + } + /** + * Set data to the given element. + * @param {Element} element - The target element. + * @param {string} name - The data key to set. + * @param {string} data - The data value. + */ + + function setData(element, name, data) { + if (isObject(data)) { + element[name] = data; + } else if (element.dataset) { + element.dataset[name] = data; + } else { + element.setAttribute("data-".concat(hyphenate(name)), data); + } + } + + var onceSupported = function () { + var supported = false; + + if (IS_BROWSER) { + var once = false; + + var listener = function listener() {}; + + var options = Object.defineProperty({}, 'once', { + get: function get() { + supported = true; + return once; + }, + + /** + * This setter can fix a `TypeError` in strict mode + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Getter_only} + * @param {boolean} value - The value to set + */ + set: function set(value) { + once = value; + } + }); + WINDOW.addEventListener('test', listener, options); + WINDOW.removeEventListener('test', listener, options); + } + + return supported; + }(); + /** + * Remove event listener from the target element. + * @param {Element} element - The event target. + * @param {string} type - The event type(s). + * @param {Function} listener - The event listener. + * @param {Object} options - The event options. + */ + + + function removeListener(element, type, listener) { + var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; + var handler = listener; + type.trim().split(REGEXP_SPACES).forEach(function (event) { + if (!onceSupported) { + var listeners = element.listeners; + + if (listeners && listeners[event] && listeners[event][listener]) { + handler = listeners[event][listener]; + delete listeners[event][listener]; + + if (Object.keys(listeners[event]).length === 0) { + delete listeners[event]; + } + + if (Object.keys(listeners).length === 0) { + delete element.listeners; + } + } + } + + element.removeEventListener(event, handler, options); + }); + } + /** + * Add event listener to the target element. + * @param {Element} element - The event target. + * @param {string} type - The event type(s). + * @param {Function} listener - The event listener. + * @param {Object} options - The event options. + */ + + function addListener(element, type, listener) { + var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; + var _handler = listener; + type.trim().split(REGEXP_SPACES).forEach(function (event) { + if (options.once && !onceSupported) { + var _element$listeners = element.listeners, + listeners = _element$listeners === void 0 ? {} : _element$listeners; + + _handler = function handler() { + delete listeners[event][listener]; + element.removeEventListener(event, _handler, options); + + for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + args[_key2] = arguments[_key2]; + } + + listener.apply(element, args); + }; + + if (!listeners[event]) { + listeners[event] = {}; + } + + if (listeners[event][listener]) { + element.removeEventListener(event, listeners[event][listener], options); + } + + listeners[event][listener] = _handler; + element.listeners = listeners; + } + + element.addEventListener(event, _handler, options); + }); + } + /** + * Dispatch event on the target element. + * @param {Element} element - The event target. + * @param {string} type - The event type(s). + * @param {Object} data - The additional event data. + * @returns {boolean} Indicate if the event is default prevented or not. + */ + + function dispatchEvent(element, type, data) { + var event; // Event and CustomEvent on IE9-11 are global objects, not constructors + + if (isFunction(Event) && isFunction(CustomEvent)) { + event = new CustomEvent(type, { + detail: data, + bubbles: true, + cancelable: true + }); + } else { + event = document.createEvent('CustomEvent'); + event.initCustomEvent(type, true, true, data); + } + + return element.dispatchEvent(event); + } + /** + * Get the offset base on the document. + * @param {Element} element - The target element. + * @returns {Object} The offset data. + */ + + function getOffset(element) { + var box = element.getBoundingClientRect(); + return { + left: box.left + (window.pageXOffset - document.documentElement.clientLeft), + top: box.top + (window.pageYOffset - document.documentElement.clientTop) + }; + } + /** + * Get transforms base on the given object. + * @param {Object} obj - The target object. + * @returns {string} A string contains transform values. + */ + + function getTransforms(_ref) { + var rotate = _ref.rotate, + scaleX = _ref.scaleX, + scaleY = _ref.scaleY, + translateX = _ref.translateX, + translateY = _ref.translateY; + var values = []; + + if (isNumber(translateX) && translateX !== 0) { + values.push("translateX(".concat(translateX, "px)")); + } + + if (isNumber(translateY) && translateY !== 0) { + values.push("translateY(".concat(translateY, "px)")); + } // Rotate should come first before scale to match orientation transform + + + if (isNumber(rotate) && rotate !== 0) { + values.push("rotate(".concat(rotate, "deg)")); + } + + if (isNumber(scaleX) && scaleX !== 1) { + values.push("scaleX(".concat(scaleX, ")")); + } + + if (isNumber(scaleY) && scaleY !== 1) { + values.push("scaleY(".concat(scaleY, ")")); + } + + var transform = values.length ? values.join(' ') : 'none'; + return { + WebkitTransform: transform, + msTransform: transform, + transform: transform + }; + } + /** + * Get an image name from an image url. + * @param {string} url - The target url. + * @example + * // picture.jpg + * getImageNameFromURL('http://domain.com/path/to/picture.jpg?size=1280×960') + * @returns {string} A string contains the image name. + */ + + function getImageNameFromURL(url) { + return isString(url) ? url.replace(/^.*\//, '').replace(/[?&#].*$/, '') : ''; + } + var IS_SAFARI = WINDOW.navigator && /(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i.test(WINDOW.navigator.userAgent); + /** + * Get an image's natural sizes. + * @param {string} image - The target image. + * @param {Function} callback - The callback function. + * @returns {HTMLImageElement} The new image. + */ + + function getImageNaturalSizes(image, callback) { + var newImage = document.createElement('img'); // Modern browsers (except Safari) + + if (image.naturalWidth && !IS_SAFARI) { + callback(image.naturalWidth, image.naturalHeight); + return newImage; + } + + var body = document.body || document.documentElement; + + newImage.onload = function () { + callback(newImage.width, newImage.height); + + if (!IS_SAFARI) { + body.removeChild(newImage); + } + }; + + newImage.src = image.src; // iOS Safari will convert the image automatically + // with its orientation once append it into DOM + + if (!IS_SAFARI) { + newImage.style.cssText = 'left:0;' + 'max-height:none!important;' + 'max-width:none!important;' + 'min-height:0!important;' + 'min-width:0!important;' + 'opacity:0;' + 'position:absolute;' + 'top:0;' + 'z-index:-1;'; + body.appendChild(newImage); + } + + return newImage; + } + /** + * Get the related class name of a responsive type number. + * @param {string} type - The responsive type. + * @returns {string} The related class name. + */ + + function getResponsiveClass(type) { + switch (type) { + case 2: + return CLASS_HIDE_XS_DOWN; + + case 3: + return CLASS_HIDE_SM_DOWN; + + case 4: + return CLASS_HIDE_MD_DOWN; + + default: + return ''; + } + } + /** + * Get the max ratio of a group of pointers. + * @param {string} pointers - The target pointers. + * @returns {number} The result ratio. + */ + + function getMaxZoomRatio(pointers) { + var pointers2 = assign({}, pointers); + var ratios = []; + forEach(pointers, function (pointer, pointerId) { + delete pointers2[pointerId]; + forEach(pointers2, function (pointer2) { + var x1 = Math.abs(pointer.startX - pointer2.startX); + var y1 = Math.abs(pointer.startY - pointer2.startY); + var x2 = Math.abs(pointer.endX - pointer2.endX); + var y2 = Math.abs(pointer.endY - pointer2.endY); + var z1 = Math.sqrt(x1 * x1 + y1 * y1); + var z2 = Math.sqrt(x2 * x2 + y2 * y2); + var ratio = (z2 - z1) / z1; + ratios.push(ratio); + }); + }); + ratios.sort(function (a, b) { + return Math.abs(a) < Math.abs(b); + }); + return ratios[0]; + } + /** + * Get a pointer from an event object. + * @param {Object} event - The target event object. + * @param {boolean} endOnly - Indicates if only returns the end point coordinate or not. + * @returns {Object} The result pointer contains start and/or end point coordinates. + */ + + function getPointer(_ref2, endOnly) { + var pageX = _ref2.pageX, + pageY = _ref2.pageY; + var end = { + endX: pageX, + endY: pageY + }; + return endOnly ? end : assign({ + timeStamp: Date.now(), + startX: pageX, + startY: pageY + }, end); + } + /** + * Get the center point coordinate of a group of pointers. + * @param {Object} pointers - The target pointers. + * @returns {Object} The center point coordinate. + */ + + function getPointersCenter(pointers) { + var pageX = 0; + var pageY = 0; + var count = 0; + forEach(pointers, function (_ref3) { + var startX = _ref3.startX, + startY = _ref3.startY; + pageX += startX; + pageY += startY; + count += 1; + }); + pageX /= count; + pageY /= count; + return { + pageX: pageX, + pageY: pageY + }; + } + + var render = { + render: function render() { + this.initContainer(); + this.initViewer(); + this.initList(); + this.renderViewer(); + }, + initContainer: function initContainer() { + this.containerData = { + width: window.innerWidth, + height: window.innerHeight + }; + }, + initViewer: function initViewer() { + var options = this.options, + parent = this.parent; + var viewerData; + + if (options.inline) { + viewerData = { + width: Math.max(parent.offsetWidth, options.minWidth), + height: Math.max(parent.offsetHeight, options.minHeight) + }; + this.parentData = viewerData; + } + + if (this.fulled || !viewerData) { + viewerData = this.containerData; + } + + this.viewerData = assign({}, viewerData); + }, + renderViewer: function renderViewer() { + if (this.options.inline && !this.fulled) { + setStyle(this.viewer, this.viewerData); + } + }, + initList: function initList() { + var _this = this; + + var element = this.element, + options = this.options, + list = this.list; + var items = []; + forEach(this.images, function (image, i) { + var src = image.src; + var alt = image.alt || getImageNameFromURL(src); + var url = options.url; + + if (isString(url)) { + url = image.getAttribute(url); + } else if (isFunction(url)) { + url = url.call(_this, image); + } + + if (src || url) { + items.push('
  • ' + '' + '
  • '); + } + }); + list.innerHTML = items.join(''); + this.items = list.getElementsByTagName('li'); + forEach(this.items, function (item) { + var image = item.firstElementChild; + setData(image, 'filled', true); + + if (options.loading) { + addClass(item, CLASS_LOADING); + } + + addListener(image, EVENT_LOAD, function (event) { + if (options.loading) { + removeClass(item, CLASS_LOADING); + } + + _this.loadImage(event); + }, { + once: true + }); + }); + + if (options.transition) { + addListener(element, EVENT_VIEWED, function () { + addClass(list, CLASS_TRANSITION); + }, { + once: true + }); + } + }, + renderList: function renderList(index) { + var i = index || this.index; + var width = this.items[i].offsetWidth || 30; + var outerWidth = width + 1; // 1 pixel of `margin-left` width + // Place the active item in the center of the screen + + setStyle(this.list, assign({ + width: outerWidth * this.length + }, getTransforms({ + translateX: (this.viewerData.width - width) / 2 - outerWidth * i + }))); + }, + resetList: function resetList() { + var list = this.list; + list.innerHTML = ''; + removeClass(list, CLASS_TRANSITION); + setStyle(list, getTransforms({ + translateX: 0 + })); + }, + initImage: function initImage(done) { + var _this2 = this; + + var options = this.options, + image = this.image, + viewerData = this.viewerData; + var footerHeight = this.footer.offsetHeight; + var viewerWidth = viewerData.width; + var viewerHeight = Math.max(viewerData.height - footerHeight, footerHeight); + var oldImageData = this.imageData || {}; + var sizingImage; + this.imageInitializing = { + abort: function abort() { + sizingImage.onload = null; + } + }; + sizingImage = getImageNaturalSizes(image, function (naturalWidth, naturalHeight) { + var aspectRatio = naturalWidth / naturalHeight; + var width = viewerWidth; + var height = viewerHeight; + _this2.imageInitializing = false; + + if (viewerHeight * aspectRatio > viewerWidth) { + height = viewerWidth / aspectRatio; + } else { + width = viewerHeight * aspectRatio; + } + + width = Math.min(width * 0.9, naturalWidth); + height = Math.min(height * 0.9, naturalHeight); + var imageData = { + naturalWidth: naturalWidth, + naturalHeight: naturalHeight, + aspectRatio: aspectRatio, + ratio: width / naturalWidth, + width: width, + height: height, + left: (viewerWidth - width) / 2, + top: (viewerHeight - height) / 2 + }; + var initialImageData = assign({}, imageData); + + if (options.rotatable) { + imageData.rotate = oldImageData.rotate || 0; + initialImageData.rotate = 0; + } + + if (options.scalable) { + imageData.scaleX = oldImageData.scaleX || 1; + imageData.scaleY = oldImageData.scaleY || 1; + initialImageData.scaleX = 1; + initialImageData.scaleY = 1; + } + + _this2.imageData = imageData; + _this2.initialImageData = initialImageData; + + if (done) { + done(); + } + }); + }, + renderImage: function renderImage(done) { + var _this3 = this; + + var image = this.image, + imageData = this.imageData; + setStyle(image, assign({ + width: imageData.width, + height: imageData.height, + // XXX: Not to use translateX/Y to avoid image shaking when zooming + marginLeft: imageData.left, + marginTop: imageData.top + }, getTransforms(imageData))); + + if (done) { + if ((this.viewing || this.zooming) && this.options.transition) { + var onTransitionEnd = function onTransitionEnd() { + _this3.imageRendering = false; + done(); + }; + + this.imageRendering = { + abort: function abort() { + removeListener(image, EVENT_TRANSITION_END, onTransitionEnd); + } + }; + addListener(image, EVENT_TRANSITION_END, onTransitionEnd, { + once: true + }); + } else { + done(); + } + } + }, + resetImage: function resetImage() { + // this.image only defined after viewed + if (this.viewing || this.viewed) { + var image = this.image; + + if (this.viewing) { + this.viewing.abort(); + } + + image.parentNode.removeChild(image); + this.image = null; + } + } + }; + + var events = { + bind: function bind() { + var options = this.options, + viewer = this.viewer, + canvas = this.canvas; + var document = this.element.ownerDocument; + addListener(viewer, EVENT_CLICK, this.onClick = this.click.bind(this)); + addListener(viewer, EVENT_WHEEL, this.onWheel = this.wheel.bind(this), { + passive: false, + capture: true + }); + addListener(viewer, EVENT_DRAG_START, this.onDragStart = this.dragstart.bind(this)); + addListener(canvas, EVENT_POINTER_DOWN, this.onPointerDown = this.pointerdown.bind(this)); + addListener(document, EVENT_POINTER_MOVE, this.onPointerMove = this.pointermove.bind(this)); + addListener(document, EVENT_POINTER_UP, this.onPointerUp = this.pointerup.bind(this)); + addListener(document, EVENT_KEY_DOWN, this.onKeyDown = this.keydown.bind(this)); + addListener(window, EVENT_RESIZE, this.onResize = this.resize.bind(this)); + + if (options.toggleOnDblclick) { + addListener(canvas, EVENT_DBLCLICK, this.onDblclick = this.dblclick.bind(this)); + } + }, + unbind: function unbind() { + var options = this.options, + viewer = this.viewer, + canvas = this.canvas; + var document = this.element.ownerDocument; + removeListener(viewer, EVENT_CLICK, this.onClick); + removeListener(viewer, EVENT_WHEEL, this.onWheel, { + passive: false, + capture: true + }); + removeListener(viewer, EVENT_DRAG_START, this.onDragStart); + removeListener(canvas, EVENT_POINTER_DOWN, this.onPointerDown); + removeListener(document, EVENT_POINTER_MOVE, this.onPointerMove); + removeListener(document, EVENT_POINTER_UP, this.onPointerUp); + removeListener(document, EVENT_KEY_DOWN, this.onKeyDown); + removeListener(window, EVENT_RESIZE, this.onResize); + + if (options.toggleOnDblclick) { + removeListener(canvas, EVENT_DBLCLICK, this.onDblclick); + } + } + }; + + var handlers = { + click: function click(event) { + var target = event.target; + var options = this.options, + imageData = this.imageData; + var action = getData(target, DATA_ACTION); // Cancel the emulated click when the native click event was triggered. + + if (IS_TOUCH_DEVICE && event.isTrusted && target === this.canvas) { + clearTimeout(this.clickCanvasTimeout); + } + + switch (action) { + case 'mix': + if (this.played) { + this.stop(); + } else if (options.inline) { + if (this.fulled) { + this.exit(); + } else { + this.full(); + } + } else { + this.hide(); + } + + break; + + case 'hide': + this.hide(); + break; + + case 'view': + this.view(getData(target, 'index')); + break; + + case 'zoom-in': + this.zoom(0.1, true); + break; + + case 'zoom-out': + this.zoom(-0.1, true); + break; + + case 'one-to-one': + this.toggle(); + break; + + case 'reset': + this.reset(); + break; + + case 'prev': + this.prev(options.loop); + break; + + case 'play': + this.play(options.fullscreen); + break; + + case 'next': + this.next(options.loop); + break; + + case 'rotate-left': + this.rotate(-90); + break; + + case 'rotate-right': + this.rotate(90); + break; + + case 'flip-horizontal': + this.scaleX(-imageData.scaleX || -1); + break; + + case 'flip-vertical': + this.scaleY(-imageData.scaleY || -1); + break; + + default: + if (this.played) { + this.stop(); + } + + } + }, + dblclick: function dblclick(event) { + event.preventDefault(); + + if (this.viewed && event.target === this.image) { + // Cancel the emulated double click when the native dblclick event was triggered. + if (IS_TOUCH_DEVICE && event.isTrusted) { + clearTimeout(this.doubleClickImageTimeout); + } + + this.toggle(); + } + }, + load: function load() { + var _this = this; + + if (this.timeout) { + clearTimeout(this.timeout); + this.timeout = false; + } + + var element = this.element, + options = this.options, + image = this.image, + index = this.index, + viewerData = this.viewerData; + removeClass(image, CLASS_INVISIBLE); + + if (options.loading) { + removeClass(this.canvas, CLASS_LOADING); + } + + image.style.cssText = 'height:0;' + "margin-left:".concat(viewerData.width / 2, "px;") + "margin-top:".concat(viewerData.height / 2, "px;") + 'max-width:none!important;' + 'position:absolute;' + 'width:0;'; + this.initImage(function () { + toggleClass(image, CLASS_MOVE, options.movable); + toggleClass(image, CLASS_TRANSITION, options.transition); + + _this.renderImage(function () { + _this.viewed = true; + _this.viewing = false; + + if (isFunction(options.viewed)) { + addListener(element, EVENT_VIEWED, options.viewed, { + once: true + }); + } + + dispatchEvent(element, EVENT_VIEWED, { + originalImage: _this.images[index], + index: index, + image: image + }); + }); + }); + }, + loadImage: function loadImage(event) { + var image = event.target; + var parent = image.parentNode; + var parentWidth = parent.offsetWidth || 30; + var parentHeight = parent.offsetHeight || 50; + var filled = !!getData(image, 'filled'); + getImageNaturalSizes(image, function (naturalWidth, naturalHeight) { + var aspectRatio = naturalWidth / naturalHeight; + var width = parentWidth; + var height = parentHeight; + + if (parentHeight * aspectRatio > parentWidth) { + if (filled) { + width = parentHeight * aspectRatio; + } else { + height = parentWidth / aspectRatio; + } + } else if (filled) { + height = parentWidth / aspectRatio; + } else { + width = parentHeight * aspectRatio; + } + + setStyle(image, assign({ + width: width, + height: height + }, getTransforms({ + translateX: (parentWidth - width) / 2, + translateY: (parentHeight - height) / 2 + }))); + }); + }, + keydown: function keydown(event) { + var options = this.options; + + if (!this.fulled || !options.keyboard) { + return; + } + + switch (event.keyCode || event.which || event.charCode) { + // Escape + case 27: + if (this.played) { + this.stop(); + } else if (options.inline) { + if (this.fulled) { + this.exit(); + } + } else { + this.hide(); + } + + break; + // Space + + case 32: + if (this.played) { + this.stop(); + } + + break; + // ArrowLeft + + case 37: + this.prev(options.loop); + break; + // ArrowUp + + case 38: + // Prevent scroll on Firefox + event.preventDefault(); // Zoom in + + this.zoom(options.zoomRatio, true); + break; + // ArrowRight + + case 39: + this.next(options.loop); + break; + // ArrowDown + + case 40: + // Prevent scroll on Firefox + event.preventDefault(); // Zoom out + + this.zoom(-options.zoomRatio, true); + break; + // Ctrl + 0 + + case 48: // Fall through + // Ctrl + 1 + // eslint-disable-next-line no-fallthrough + + case 49: + if (event.ctrlKey) { + event.preventDefault(); + this.toggle(); + } + + break; + + default: + } + }, + dragstart: function dragstart(event) { + if (event.target.tagName.toLowerCase() === 'img') { + event.preventDefault(); + } + }, + pointerdown: function pointerdown(event) { + var options = this.options, + pointers = this.pointers; + var buttons = event.buttons, + button = event.button; + + if (!this.viewed || this.showing || this.viewing || this.hiding // No primary button (Usually the left button) + // Note that touch events have no `buttons` or `button` property + || isNumber(buttons) && buttons !== 1 || isNumber(button) && button !== 0 // Open context menu + || event.ctrlKey) { + return; + } // Prevent default behaviours as page zooming in touch devices. + + + event.preventDefault(); + + if (event.changedTouches) { + forEach(event.changedTouches, function (touch) { + pointers[touch.identifier] = getPointer(touch); + }); + } else { + pointers[event.pointerId || 0] = getPointer(event); + } + + var action = options.movable ? ACTION_MOVE : false; + + if (Object.keys(pointers).length > 1) { + action = ACTION_ZOOM; + } else if ((event.pointerType === 'touch' || event.type === 'touchstart') && this.isSwitchable()) { + action = ACTION_SWITCH; + } + + if (options.transition && (action === ACTION_MOVE || action === ACTION_ZOOM)) { + removeClass(this.image, CLASS_TRANSITION); + } + + this.action = action; + }, + pointermove: function pointermove(event) { + var pointers = this.pointers, + action = this.action; + + if (!this.viewed || !action) { + return; + } + + event.preventDefault(); + + if (event.changedTouches) { + forEach(event.changedTouches, function (touch) { + assign(pointers[touch.identifier] || {}, getPointer(touch, true)); + }); + } else { + assign(pointers[event.pointerId || 0] || {}, getPointer(event, true)); + } + + this.change(event); + }, + pointerup: function pointerup(event) { + var _this2 = this; + + var options = this.options, + action = this.action, + pointers = this.pointers; + var pointer; + + if (event.changedTouches) { + forEach(event.changedTouches, function (touch) { + pointer = pointers[touch.identifier]; + delete pointers[touch.identifier]; + }); + } else { + pointer = pointers[event.pointerId || 0]; + delete pointers[event.pointerId || 0]; + } + + if (!action) { + return; + } + + event.preventDefault(); + + if (options.transition && (action === ACTION_MOVE || action === ACTION_ZOOM)) { + addClass(this.image, CLASS_TRANSITION); + } + + this.action = false; // Emulate click and double click in touch devices to support backdrop and image zooming (#210). + + if (IS_TOUCH_DEVICE && action !== ACTION_ZOOM && pointer && Date.now() - pointer.timeStamp < 500) { + clearTimeout(this.clickCanvasTimeout); + clearTimeout(this.doubleClickImageTimeout); + + if (options.toggleOnDblclick && this.viewed && event.target === this.image) { + if (this.imageClicked) { + this.imageClicked = false; // This timeout will be cleared later when a native dblclick event is triggering + + this.doubleClickImageTimeout = setTimeout(function () { + dispatchEvent(_this2.image, EVENT_DBLCLICK); + }, 50); + } else { + this.imageClicked = true; // The default timing of a double click in Windows is 500 ms + + this.doubleClickImageTimeout = setTimeout(function () { + _this2.imageClicked = false; + }, 500); + } + } else { + this.imageClicked = false; + + if (options.backdrop && options.backdrop !== 'static' && event.target === this.canvas) { + // This timeout will be cleared later when a native click event is triggering + this.clickCanvasTimeout = setTimeout(function () { + dispatchEvent(_this2.canvas, EVENT_CLICK); + }, 50); + } + } + } + }, + resize: function resize() { + var _this3 = this; + + if (!this.isShown || this.hiding) { + return; + } + + this.initContainer(); + this.initViewer(); + this.renderViewer(); + this.renderList(); + + if (this.viewed) { + this.initImage(function () { + _this3.renderImage(); + }); + } + + if (this.played) { + if (this.options.fullscreen && this.fulled && !(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)) { + this.stop(); + return; + } + + forEach(this.player.getElementsByTagName('img'), function (image) { + addListener(image, EVENT_LOAD, _this3.loadImage.bind(_this3), { + once: true + }); + dispatchEvent(image, EVENT_LOAD); + }); + } + }, + wheel: function wheel(event) { + var _this4 = this; + + if (!this.viewed) { + return; + } + + event.preventDefault(); // Limit wheel speed to prevent zoom too fast + + if (this.wheeling) { + return; + } + + this.wheeling = true; + setTimeout(function () { + _this4.wheeling = false; + }, 50); + var ratio = Number(this.options.zoomRatio) || 0.1; + var delta = 1; + + if (event.deltaY) { + delta = event.deltaY > 0 ? 1 : -1; + } else if (event.wheelDelta) { + delta = -event.wheelDelta / 120; + } else if (event.detail) { + delta = event.detail > 0 ? 1 : -1; + } + + this.zoom(-delta * ratio, true, event); + } + }; + + var methods = { + /** Show the viewer (only available in modal mode) + * @param {boolean} [immediate=false] - Indicates if show the viewer immediately or not. + * @returns {Viewer} this + */ + show: function show() { + var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + var element = this.element, + options = this.options; + + if (options.inline || this.showing || this.isShown || this.showing) { + return this; + } + + if (!this.ready) { + this.build(); + + if (this.ready) { + this.show(immediate); + } + + return this; + } + + if (isFunction(options.show)) { + addListener(element, EVENT_SHOW, options.show, { + once: true + }); + } + + if (dispatchEvent(element, EVENT_SHOW) === false || !this.ready) { + return this; + } + + if (this.hiding) { + this.transitioning.abort(); + } + + this.showing = true; + this.open(); + var viewer = this.viewer; + removeClass(viewer, CLASS_HIDE); + + if (options.transition && !immediate) { + var shown = this.shown.bind(this); + this.transitioning = { + abort: function abort() { + removeListener(viewer, EVENT_TRANSITION_END, shown); + removeClass(viewer, CLASS_IN); + } + }; + addClass(viewer, CLASS_TRANSITION); // Force reflow to enable CSS3 transition + // eslint-disable-next-line + + viewer.offsetWidth; + addListener(viewer, EVENT_TRANSITION_END, shown, { + once: true + }); + addClass(viewer, CLASS_IN); + } else { + addClass(viewer, CLASS_IN); + this.shown(); + } + + return this; + }, + + /** + * Hide the viewer (only available in modal mode) + * @param {boolean} [immediate=false] - Indicates if hide the viewer immediately or not. + * @returns {Viewer} this + */ + hide: function hide() { + var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + var element = this.element, + options = this.options; + + if (options.inline || this.hiding || !(this.isShown || this.showing)) { + return this; + } + + if (isFunction(options.hide)) { + addListener(element, EVENT_HIDE, options.hide, { + once: true + }); + } + + if (dispatchEvent(element, EVENT_HIDE) === false) { + return this; + } + + if (this.showing) { + this.transitioning.abort(); + } + + this.hiding = true; + + if (this.played) { + this.stop(); + } else if (this.viewing) { + this.viewing.abort(); + } + + var viewer = this.viewer; + + if (options.transition && !immediate) { + var hidden = this.hidden.bind(this); + + var hide = function hide() { + addListener(viewer, EVENT_TRANSITION_END, hidden, { + once: true + }); + removeClass(viewer, CLASS_IN); + }; + + this.transitioning = { + abort: function abort() { + if (this.viewed) { + removeListener(this.image, EVENT_TRANSITION_END, hide); + } else { + removeListener(viewer, EVENT_TRANSITION_END, hidden); + } + } + }; + + if (this.viewed) { + addListener(this.image, EVENT_TRANSITION_END, hide, { + once: true + }); + this.zoomTo(0, false, false, true); + } else { + hide(); + } + } else { + removeClass(viewer, CLASS_IN); + this.hidden(); + } + + return this; + }, + + /** + * View one of the images with image's index + * @param {number} index - The index of the image to view. + * @returns {Viewer} this + */ + view: function view() { + var _this = this; + + var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options.initialViewIndex; + index = Number(index) || 0; + + if (!this.isShown) { + this.index = index; + return this.show(); + } + + if (this.hiding || this.played || index < 0 || index >= this.length || this.viewed && index === this.index) { + return this; + } + + if (this.viewing) { + this.viewing.abort(); + } + + var element = this.element, + options = this.options, + title = this.title, + canvas = this.canvas; + var item = this.items[index]; + var img = item.querySelector('img'); + var url = getData(img, 'originalUrl'); + var alt = img.getAttribute('alt'); + var image = document.createElement('img'); + image.src = url; + image.alt = alt; + + if (isFunction(options.view)) { + addListener(element, EVENT_VIEW, options.view, { + once: true + }); + } + + if (dispatchEvent(element, EVENT_VIEW, { + originalImage: this.images[index], + index: index, + image: image + }) === false || !this.isShown || this.hiding || this.played) { + return this; + } + + this.image = image; + removeClass(this.items[this.index], CLASS_ACTIVE); + addClass(item, CLASS_ACTIVE); + this.viewed = false; + this.index = index; + this.imageData = {}; + addClass(image, CLASS_INVISIBLE); + + if (options.loading) { + addClass(canvas, CLASS_LOADING); + } + + canvas.innerHTML = ''; + canvas.appendChild(image); // Center current item + + this.renderList(); // Clear title + + title.innerHTML = ''; // Generate title after viewed + + var onViewed = function onViewed() { + var imageData = _this.imageData; + var render = Array.isArray(options.title) ? options.title[1] : options.title; + title.innerHTML = isFunction(render) ? render.call(_this, image, imageData) : "".concat(alt, " (").concat(imageData.naturalWidth, " \xD7 ").concat(imageData.naturalHeight, ")"); + }; + + var onLoad; + addListener(element, EVENT_VIEWED, onViewed, { + once: true + }); + this.viewing = { + abort: function abort() { + removeListener(element, EVENT_VIEWED, onViewed); + + if (image.complete) { + if (this.imageRendering) { + this.imageRendering.abort(); + } else if (this.imageInitializing) { + this.imageInitializing.abort(); + } + } else { + removeListener(image, EVENT_LOAD, onLoad); + + if (this.timeout) { + clearTimeout(this.timeout); + } + } + } + }; + + if (image.complete) { + this.load(); + } else { + addListener(image, EVENT_LOAD, onLoad = this.load.bind(this), { + once: true + }); + + if (this.timeout) { + clearTimeout(this.timeout); + } // Make the image visible if it fails to load within 1s + + + this.timeout = setTimeout(function () { + removeClass(image, CLASS_INVISIBLE); + _this.timeout = false; + }, 1000); + } + + return this; + }, + + /** + * View the previous image + * @param {boolean} [loop=false] - Indicate if view the last one + * when it is the first one at present. + * @returns {Viewer} this + */ + prev: function prev() { + var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + var index = this.index - 1; + + if (index < 0) { + index = loop ? this.length - 1 : 0; + } + + this.view(index); + return this; + }, + + /** + * View the next image + * @param {boolean} [loop=false] - Indicate if view the first one + * when it is the last one at present. + * @returns {Viewer} this + */ + next: function next() { + var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + var maxIndex = this.length - 1; + var index = this.index + 1; + + if (index > maxIndex) { + index = loop ? 0 : maxIndex; + } + + this.view(index); + return this; + }, + + /** + * Move the image with relative offsets. + * @param {number} offsetX - The relative offset distance on the x-axis. + * @param {number} offsetY - The relative offset distance on the y-axis. + * @returns {Viewer} this + */ + move: function move(offsetX, offsetY) { + var imageData = this.imageData; + this.moveTo(isUndefined(offsetX) ? offsetX : imageData.left + Number(offsetX), isUndefined(offsetY) ? offsetY : imageData.top + Number(offsetY)); + return this; + }, + + /** + * Move the image to an absolute point. + * @param {number} x - The x-axis coordinate. + * @param {number} [y=x] - The y-axis coordinate. + * @returns {Viewer} this + */ + moveTo: function moveTo(x) { + var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; + var imageData = this.imageData; + x = Number(x); + y = Number(y); + + if (this.viewed && !this.played && this.options.movable) { + var changed = false; + + if (isNumber(x)) { + imageData.left = x; + changed = true; + } + + if (isNumber(y)) { + imageData.top = y; + changed = true; + } + + if (changed) { + this.renderImage(); + } + } + + return this; + }, + + /** + * Zoom the image with a relative ratio. + * @param {number} ratio - The target ratio. + * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not. + * @param {Event} [_originalEvent=null] - The original event if any. + * @returns {Viewer} this + */ + zoom: function zoom(ratio) { + var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + + var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + + var imageData = this.imageData; + ratio = Number(ratio); + + if (ratio < 0) { + ratio = 1 / (1 - ratio); + } else { + ratio = 1 + ratio; + } + + this.zoomTo(imageData.width * ratio / imageData.naturalWidth, hasTooltip, _originalEvent); + return this; + }, + + /** + * Zoom the image to an absolute ratio. + * @param {number} ratio - The target ratio. + * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not. + * @param {Event} [_originalEvent=null] - The original event if any. + * @param {Event} [_zoomable=false] - Indicates if the current zoom is available or not. + * @returns {Viewer} this + */ + zoomTo: function zoomTo(ratio) { + var _this2 = this; + + var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + + var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + + var _zoomable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + + var element = this.element, + options = this.options, + pointers = this.pointers, + imageData = this.imageData; + var width = imageData.width, + height = imageData.height, + left = imageData.left, + top = imageData.top, + naturalWidth = imageData.naturalWidth, + naturalHeight = imageData.naturalHeight; + ratio = Math.max(0, ratio); + + if (isNumber(ratio) && this.viewed && !this.played && (_zoomable || options.zoomable)) { + if (!_zoomable) { + var minZoomRatio = Math.max(0.01, options.minZoomRatio); + var maxZoomRatio = Math.min(100, options.maxZoomRatio); + ratio = Math.min(Math.max(ratio, minZoomRatio), maxZoomRatio); + } + + if (_originalEvent && ratio > 0.95 && ratio < 1.05) { + ratio = 1; + } + + var newWidth = naturalWidth * ratio; + var newHeight = naturalHeight * ratio; + var offsetWidth = newWidth - width; + var offsetHeight = newHeight - height; + var oldRatio = width / naturalWidth; + + if (isFunction(options.zoom)) { + addListener(element, EVENT_ZOOM, options.zoom, { + once: true + }); + } + + if (dispatchEvent(element, EVENT_ZOOM, { + ratio: ratio, + oldRatio: oldRatio, + originalEvent: _originalEvent + }) === false) { + return this; + } + + this.zooming = true; + + if (_originalEvent) { + var offset = getOffset(this.viewer); + var center = pointers && Object.keys(pointers).length ? getPointersCenter(pointers) : { + pageX: _originalEvent.pageX, + pageY: _originalEvent.pageY + }; // Zoom from the triggering point of the event + + imageData.left -= offsetWidth * ((center.pageX - offset.left - left) / width); + imageData.top -= offsetHeight * ((center.pageY - offset.top - top) / height); + } else { + // Zoom from the center of the image + imageData.left -= offsetWidth / 2; + imageData.top -= offsetHeight / 2; + } + + imageData.width = newWidth; + imageData.height = newHeight; + imageData.ratio = ratio; + this.renderImage(function () { + _this2.zooming = false; + + if (isFunction(options.zoomed)) { + addListener(element, EVENT_ZOOMED, options.zoomed, { + once: true + }); + } + + dispatchEvent(element, EVENT_ZOOMED, { + ratio: ratio, + oldRatio: oldRatio, + originalEvent: _originalEvent + }); + }); + + if (hasTooltip) { + this.tooltip(); + } + } + + return this; + }, + + /** + * Rotate the image with a relative degree. + * @param {number} degree - The rotate degree. + * @returns {Viewer} this + */ + rotate: function rotate(degree) { + this.rotateTo((this.imageData.rotate || 0) + Number(degree)); + return this; + }, + + /** + * Rotate the image to an absolute degree. + * @param {number} degree - The rotate degree. + * @returns {Viewer} this + */ + rotateTo: function rotateTo(degree) { + var imageData = this.imageData; + degree = Number(degree); + + if (isNumber(degree) && this.viewed && !this.played && this.options.rotatable) { + imageData.rotate = degree; + this.renderImage(); + } + + return this; + }, + + /** + * Scale the image on the x-axis. + * @param {number} scaleX - The scale ratio on the x-axis. + * @returns {Viewer} this + */ + scaleX: function scaleX(_scaleX) { + this.scale(_scaleX, this.imageData.scaleY); + return this; + }, + + /** + * Scale the image on the y-axis. + * @param {number} scaleY - The scale ratio on the y-axis. + * @returns {Viewer} this + */ + scaleY: function scaleY(_scaleY) { + this.scale(this.imageData.scaleX, _scaleY); + return this; + }, + + /** + * Scale the image. + * @param {number} scaleX - The scale ratio on the x-axis. + * @param {number} [scaleY=scaleX] - The scale ratio on the y-axis. + * @returns {Viewer} this + */ + scale: function scale(scaleX) { + var scaleY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : scaleX; + var imageData = this.imageData; + scaleX = Number(scaleX); + scaleY = Number(scaleY); + + if (this.viewed && !this.played && this.options.scalable) { + var changed = false; + + if (isNumber(scaleX)) { + imageData.scaleX = scaleX; + changed = true; + } + + if (isNumber(scaleY)) { + imageData.scaleY = scaleY; + changed = true; + } + + if (changed) { + this.renderImage(); + } + } + + return this; + }, + + /** + * Play the images + * @param {boolean} [fullscreen=false] - Indicate if request fullscreen or not. + * @returns {Viewer} this + */ + play: function play() { + var _this3 = this; + + var fullscreen = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + + if (!this.isShown || this.played) { + return this; + } + + var options = this.options, + player = this.player; + var onLoad = this.loadImage.bind(this); + var list = []; + var total = 0; + var index = 0; + this.played = true; + this.onLoadWhenPlay = onLoad; + + if (fullscreen) { + this.requestFullscreen(); + } + + addClass(player, CLASS_SHOW); + forEach(this.items, function (item, i) { + var img = item.querySelector('img'); + var image = document.createElement('img'); + image.src = getData(img, 'originalUrl'); + image.alt = img.getAttribute('alt'); + total += 1; + addClass(image, CLASS_FADE); + toggleClass(image, CLASS_TRANSITION, options.transition); + + if (hasClass(item, CLASS_ACTIVE)) { + addClass(image, CLASS_IN); + index = i; + } + + list.push(image); + addListener(image, EVENT_LOAD, onLoad, { + once: true + }); + player.appendChild(image); + }); + + if (isNumber(options.interval) && options.interval > 0) { + var play = function play() { + _this3.playing = setTimeout(function () { + removeClass(list[index], CLASS_IN); + index += 1; + index = index < total ? index : 0; + addClass(list[index], CLASS_IN); + play(); + }, options.interval); + }; + + if (total > 1) { + play(); + } + } + + return this; + }, + // Stop play + stop: function stop() { + var _this4 = this; + + if (!this.played) { + return this; + } + + var player = this.player; + this.played = false; + clearTimeout(this.playing); + forEach(player.getElementsByTagName('img'), function (image) { + removeListener(image, EVENT_LOAD, _this4.onLoadWhenPlay); + }); + removeClass(player, CLASS_SHOW); + player.innerHTML = ''; + this.exitFullscreen(); + return this; + }, + // Enter modal mode (only available in inline mode) + full: function full() { + var _this5 = this; + + var options = this.options, + viewer = this.viewer, + image = this.image, + list = this.list; + + if (!this.isShown || this.played || this.fulled || !options.inline) { + return this; + } + + this.fulled = true; + this.open(); + addClass(this.button, CLASS_FULLSCREEN_EXIT); + + if (options.transition) { + removeClass(list, CLASS_TRANSITION); + + if (this.viewed) { + removeClass(image, CLASS_TRANSITION); + } + } + + addClass(viewer, CLASS_FIXED); + viewer.setAttribute('style', ''); + setStyle(viewer, { + zIndex: options.zIndex + }); + this.initContainer(); + this.viewerData = assign({}, this.containerData); + this.renderList(); + + if (this.viewed) { + this.initImage(function () { + _this5.renderImage(function () { + if (options.transition) { + setTimeout(function () { + addClass(image, CLASS_TRANSITION); + addClass(list, CLASS_TRANSITION); + }, 0); + } + }); + }); + } + + return this; + }, + // Exit modal mode (only available in inline mode) + exit: function exit() { + var _this6 = this; + + var options = this.options, + viewer = this.viewer, + image = this.image, + list = this.list; + + if (!this.isShown || this.played || !this.fulled || !options.inline) { + return this; + } + + this.fulled = false; + this.close(); + removeClass(this.button, CLASS_FULLSCREEN_EXIT); + + if (options.transition) { + removeClass(list, CLASS_TRANSITION); + + if (this.viewed) { + removeClass(image, CLASS_TRANSITION); + } + } + + removeClass(viewer, CLASS_FIXED); + setStyle(viewer, { + zIndex: options.zIndexInline + }); + this.viewerData = assign({}, this.parentData); + this.renderViewer(); + this.renderList(); + + if (this.viewed) { + this.initImage(function () { + _this6.renderImage(function () { + if (options.transition) { + setTimeout(function () { + addClass(image, CLASS_TRANSITION); + addClass(list, CLASS_TRANSITION); + }, 0); + } + }); + }); + } + + return this; + }, + // Show the current ratio of the image with percentage + tooltip: function tooltip() { + var _this7 = this; + + var options = this.options, + tooltipBox = this.tooltipBox, + imageData = this.imageData; + + if (!this.viewed || this.played || !options.tooltip) { + return this; + } + + tooltipBox.textContent = "".concat(Math.round(imageData.ratio * 100), "%"); + + if (!this.tooltipping) { + if (options.transition) { + if (this.fading) { + dispatchEvent(tooltipBox, EVENT_TRANSITION_END); + } + + addClass(tooltipBox, CLASS_SHOW); + addClass(tooltipBox, CLASS_FADE); + addClass(tooltipBox, CLASS_TRANSITION); // Force reflow to enable CSS3 transition + // eslint-disable-next-line + + tooltipBox.offsetWidth; + addClass(tooltipBox, CLASS_IN); + } else { + addClass(tooltipBox, CLASS_SHOW); + } + } else { + clearTimeout(this.tooltipping); + } + + this.tooltipping = setTimeout(function () { + if (options.transition) { + addListener(tooltipBox, EVENT_TRANSITION_END, function () { + removeClass(tooltipBox, CLASS_SHOW); + removeClass(tooltipBox, CLASS_FADE); + removeClass(tooltipBox, CLASS_TRANSITION); + _this7.fading = false; + }, { + once: true + }); + removeClass(tooltipBox, CLASS_IN); + _this7.fading = true; + } else { + removeClass(tooltipBox, CLASS_SHOW); + } + + _this7.tooltipping = false; + }, 1000); + return this; + }, + // Toggle the image size between its natural size and initial size + toggle: function toggle() { + if (this.imageData.ratio === 1) { + this.zoomTo(this.initialImageData.ratio, true); + } else { + this.zoomTo(1, true); + } + + return this; + }, + // Reset the image to its initial state + reset: function reset() { + if (this.viewed && !this.played) { + this.imageData = assign({}, this.initialImageData); + this.renderImage(); + } + + return this; + }, + // Update viewer when images changed + update: function update() { + var element = this.element, + options = this.options, + isImg = this.isImg; // Destroy viewer if the target image was deleted + + if (isImg && !element.parentNode) { + return this.destroy(); + } + + var images = []; + forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) { + if (options.filter) { + if (options.filter(image)) { + images.push(image); + } + } else { + images.push(image); + } + }); + + if (!images.length) { + return this; + } + + this.images = images; + this.length = images.length; + + if (this.ready) { + var indexes = []; + forEach(this.items, function (item, i) { + var img = item.querySelector('img'); + var image = images[i]; + + if (image) { + if (image.src !== img.src) { + indexes.push(i); + } + } else { + indexes.push(i); + } + }); + setStyle(this.list, { + width: 'auto' + }); + this.initList(); + + if (this.isShown) { + if (this.length) { + if (this.viewed) { + var index = indexes.indexOf(this.index); + + if (index >= 0) { + this.viewed = false; + this.view(Math.max(this.index - (index + 1), 0)); + } else { + addClass(this.items[this.index], CLASS_ACTIVE); + } + } + } else { + this.image = null; + this.viewed = false; + this.index = 0; + this.imageData = {}; + this.canvas.innerHTML = ''; + this.title.innerHTML = ''; + } + } + } else { + this.build(); + } + + return this; + }, + // Destroy the viewer + destroy: function destroy() { + var element = this.element, + options = this.options; + + if (!element[NAMESPACE]) { + return this; + } + + this.destroyed = true; + + if (this.ready) { + if (this.played) { + this.stop(); + } + + if (options.inline) { + if (this.fulled) { + this.exit(); + } + + this.unbind(); + } else if (this.isShown) { + if (this.viewing) { + if (this.imageRendering) { + this.imageRendering.abort(); + } else if (this.imageInitializing) { + this.imageInitializing.abort(); + } + } + + if (this.hiding) { + this.transitioning.abort(); + } + + this.hidden(); + } else if (this.showing) { + this.transitioning.abort(); + this.hidden(); + } + + this.ready = false; + this.viewer.parentNode.removeChild(this.viewer); + } else if (options.inline) { + if (this.delaying) { + this.delaying.abort(); + } else if (this.initializing) { + this.initializing.abort(); + } + } + + if (!options.inline) { + removeListener(element, EVENT_CLICK, this.onStart); + } + + element[NAMESPACE] = undefined; + return this; + } + }; + + var others = { + open: function open() { + var body = this.body; + addClass(body, CLASS_OPEN); + body.style.paddingRight = "".concat(this.scrollbarWidth + (parseFloat(this.initialBodyPaddingRight) || 0), "px"); + }, + close: function close() { + var body = this.body; + removeClass(body, CLASS_OPEN); + body.style.paddingRight = this.initialBodyPaddingRight; + }, + shown: function shown() { + var element = this.element, + options = this.options; + this.fulled = true; + this.isShown = true; + this.render(); + this.bind(); + this.showing = false; + + if (isFunction(options.shown)) { + addListener(element, EVENT_SHOWN, options.shown, { + once: true + }); + } + + if (dispatchEvent(element, EVENT_SHOWN) === false) { + return; + } + + if (this.ready && this.isShown && !this.hiding) { + this.view(this.index); + } + }, + hidden: function hidden() { + var element = this.element, + options = this.options; + this.fulled = false; + this.viewed = false; + this.isShown = false; + this.close(); + this.unbind(); + addClass(this.viewer, CLASS_HIDE); + this.resetList(); + this.resetImage(); + this.hiding = false; + + if (!this.destroyed) { + if (isFunction(options.hidden)) { + addListener(element, EVENT_HIDDEN, options.hidden, { + once: true + }); + } + + dispatchEvent(element, EVENT_HIDDEN); + } + }, + requestFullscreen: function requestFullscreen() { + var document = this.element.ownerDocument; + + if (this.fulled && !(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)) { + var documentElement = document.documentElement; // Element.requestFullscreen() + + if (documentElement.requestFullscreen) { + documentElement.requestFullscreen(); + } else if (documentElement.webkitRequestFullscreen) { + documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); + } else if (documentElement.mozRequestFullScreen) { + documentElement.mozRequestFullScreen(); + } else if (documentElement.msRequestFullscreen) { + documentElement.msRequestFullscreen(); + } + } + }, + exitFullscreen: function exitFullscreen() { + var document = this.element.ownerDocument; + + if (this.fulled && (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)) { + // Document.exitFullscreen() + if (document.exitFullscreen) { + document.exitFullscreen(); + } else if (document.webkitExitFullscreen) { + document.webkitExitFullscreen(); + } else if (document.mozCancelFullScreen) { + document.mozCancelFullScreen(); + } else if (document.msExitFullscreen) { + document.msExitFullscreen(); + } + } + }, + change: function change(event) { + var options = this.options, + pointers = this.pointers; + var pointer = pointers[Object.keys(pointers)[0]]; + var offsetX = pointer.endX - pointer.startX; + var offsetY = pointer.endY - pointer.startY; + + switch (this.action) { + // Move the current image + case ACTION_MOVE: + this.move(offsetX, offsetY); + break; + // Zoom the current image + + case ACTION_ZOOM: + this.zoom(getMaxZoomRatio(pointers), false, event); + break; + + case ACTION_SWITCH: + { + this.action = 'switched'; + var absoluteOffsetX = Math.abs(offsetX); + + if (absoluteOffsetX > 1 && absoluteOffsetX > Math.abs(offsetY)) { + // Empty `pointers` as `touchend` event will not be fired after swiped in iOS browsers. + this.pointers = {}; + + if (offsetX > 1) { + this.prev(options.loop); + } else if (offsetX < -1) { + this.next(options.loop); + } + } + + break; + } + + default: + } // Override + + + forEach(pointers, function (p) { + p.startX = p.endX; + p.startY = p.endY; + }); + }, + isSwitchable: function isSwitchable() { + var imageData = this.imageData, + viewerData = this.viewerData; + return this.length > 1 && imageData.left >= 0 && imageData.top >= 0 && imageData.width <= viewerData.width && imageData.height <= viewerData.height; + } + }; + + var AnotherViewer = WINDOW.Viewer; + + var Viewer = + /*#__PURE__*/ + function () { + /** + * Create a new Viewer. + * @param {Element} element - The target element for viewing. + * @param {Object} [options={}] - The configuration options. + */ + function Viewer(element) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + _classCallCheck(this, Viewer); + + if (!element || element.nodeType !== 1) { + throw new Error('The first argument is required and must be an element.'); + } + + this.element = element; + this.options = assign({}, DEFAULTS, isPlainObject(options) && options); + this.action = false; + this.fading = false; + this.fulled = false; + this.hiding = false; + this.imageClicked = false; + this.imageData = {}; + this.index = this.options.initialViewIndex; + this.isImg = false; + this.isShown = false; + this.length = 0; + this.played = false; + this.playing = false; + this.pointers = {}; + this.ready = false; + this.showing = false; + this.timeout = false; + this.tooltipping = false; + this.viewed = false; + this.viewing = false; + this.wheeling = false; + this.zooming = false; + this.init(); + } + + _createClass(Viewer, [{ + key: "init", + value: function init() { + var _this = this; + + var element = this.element, + options = this.options; + + if (element[NAMESPACE]) { + return; + } + + element[NAMESPACE] = this; + var isImg = element.tagName.toLowerCase() === 'img'; + var images = []; + forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) { + if (isFunction(options.filter)) { + if (options.filter.call(_this, image)) { + images.push(image); + } + } else { + images.push(image); + } + }); + this.isImg = isImg; + this.length = images.length; + this.images = images; + var ownerDocument = element.ownerDocument; + var body = ownerDocument.body || ownerDocument.documentElement; + this.body = body; + this.scrollbarWidth = window.innerWidth - ownerDocument.documentElement.clientWidth; + this.initialBodyPaddingRight = window.getComputedStyle(body).paddingRight; // Override `transition` option if it is not supported + + if (isUndefined(document.createElement(NAMESPACE).style.transition)) { + options.transition = false; + } + + if (options.inline) { + var count = 0; + + var progress = function progress() { + count += 1; + + if (count === _this.length) { + var timeout; + _this.initializing = false; + _this.delaying = { + abort: function abort() { + clearTimeout(timeout); + } + }; // build asynchronously to keep `this.viewer` is accessible in `ready` event handler. + + timeout = setTimeout(function () { + _this.delaying = false; + + _this.build(); + }, 0); + } + }; + + this.initializing = { + abort: function abort() { + forEach(images, function (image) { + if (!image.complete) { + removeListener(image, EVENT_LOAD, progress); + } + }); + } + }; + forEach(images, function (image) { + if (image.complete) { + progress(); + } else { + addListener(image, EVENT_LOAD, progress, { + once: true + }); + } + }); + } else { + addListener(element, EVENT_CLICK, this.onStart = function (_ref) { + var target = _ref.target; + + if (target.tagName.toLowerCase() === 'img' && (!isFunction(options.filter) || options.filter.call(_this, target))) { + _this.view(_this.images.indexOf(target)); + } + }); + } + } + }, { + key: "build", + value: function build() { + if (this.ready) { + return; + } + + var element = this.element, + options = this.options; + var parent = element.parentNode; + var template = document.createElement('div'); + template.innerHTML = TEMPLATE; + var viewer = template.querySelector(".".concat(NAMESPACE, "-container")); + var title = viewer.querySelector(".".concat(NAMESPACE, "-title")); + var toolbar = viewer.querySelector(".".concat(NAMESPACE, "-toolbar")); + var navbar = viewer.querySelector(".".concat(NAMESPACE, "-navbar")); + var button = viewer.querySelector(".".concat(NAMESPACE, "-button")); + var canvas = viewer.querySelector(".".concat(NAMESPACE, "-canvas")); + this.parent = parent; + this.viewer = viewer; + this.title = title; + this.toolbar = toolbar; + this.navbar = navbar; + this.button = button; + this.canvas = canvas; + this.footer = viewer.querySelector(".".concat(NAMESPACE, "-footer")); + this.tooltipBox = viewer.querySelector(".".concat(NAMESPACE, "-tooltip")); + this.player = viewer.querySelector(".".concat(NAMESPACE, "-player")); + this.list = viewer.querySelector(".".concat(NAMESPACE, "-list")); + addClass(title, !options.title ? CLASS_HIDE : getResponsiveClass(Array.isArray(options.title) ? options.title[0] : options.title)); + addClass(navbar, !options.navbar ? CLASS_HIDE : getResponsiveClass(options.navbar)); + toggleClass(button, CLASS_HIDE, !options.button); + + if (options.backdrop) { + addClass(viewer, "".concat(NAMESPACE, "-backdrop")); + + if (!options.inline && options.backdrop !== 'static') { + setData(canvas, DATA_ACTION, 'hide'); + } + } + + if (isString(options.className) && options.className) { + // In case there are multiple class names + options.className.split(REGEXP_SPACES).forEach(function (className) { + addClass(viewer, className); + }); + } + + if (options.toolbar) { + var list = document.createElement('ul'); + var custom = isPlainObject(options.toolbar); + var zoomButtons = BUTTONS.slice(0, 3); + var rotateButtons = BUTTONS.slice(7, 9); + var scaleButtons = BUTTONS.slice(9); + + if (!custom) { + addClass(toolbar, getResponsiveClass(options.toolbar)); + } + + forEach(custom ? options.toolbar : BUTTONS, function (value, index) { + var deep = custom && isPlainObject(value); + var name = custom ? hyphenate(index) : value; + var show = deep && !isUndefined(value.show) ? value.show : value; + + if (!show || !options.zoomable && zoomButtons.indexOf(name) !== -1 || !options.rotatable && rotateButtons.indexOf(name) !== -1 || !options.scalable && scaleButtons.indexOf(name) !== -1) { + return; + } + + var size = deep && !isUndefined(value.size) ? value.size : value; + var click = deep && !isUndefined(value.click) ? value.click : value; + var item = document.createElement('li'); + item.setAttribute('role', 'button'); + addClass(item, "".concat(NAMESPACE, "-").concat(name)); + + if (!isFunction(click)) { + setData(item, DATA_ACTION, name); + } + + if (isNumber(show)) { + addClass(item, getResponsiveClass(show)); + } + + if (['small', 'large'].indexOf(size) !== -1) { + addClass(item, "".concat(NAMESPACE, "-").concat(size)); + } else if (name === 'play') { + addClass(item, "".concat(NAMESPACE, "-large")); + } + + if (isFunction(click)) { + addListener(item, EVENT_CLICK, click); + } + + list.appendChild(item); + }); + toolbar.appendChild(list); + } else { + addClass(toolbar, CLASS_HIDE); + } + + if (!options.rotatable) { + var rotates = toolbar.querySelectorAll('li[class*="rotate"]'); + addClass(rotates, CLASS_INVISIBLE); + forEach(rotates, function (rotate) { + toolbar.appendChild(rotate); + }); + } + + if (options.inline) { + addClass(button, CLASS_FULLSCREEN); + setStyle(viewer, { + zIndex: options.zIndexInline + }); + + if (window.getComputedStyle(parent).position === 'static') { + setStyle(parent, { + position: 'relative' + }); + } + + parent.insertBefore(viewer, element.nextSibling); + } else { + addClass(button, CLASS_CLOSE); + addClass(viewer, CLASS_FIXED); + addClass(viewer, CLASS_FADE); + addClass(viewer, CLASS_HIDE); + setStyle(viewer, { + zIndex: options.zIndex + }); + var container = options.container; + + if (isString(container)) { + container = element.ownerDocument.querySelector(container); + } + + if (!container) { + container = this.body; + } + + container.appendChild(viewer); + } + + if (options.inline) { + this.render(); + this.bind(); + this.isShown = true; + } + + this.ready = true; + + if (isFunction(options.ready)) { + addListener(element, EVENT_READY, options.ready, { + once: true + }); + } + + if (dispatchEvent(element, EVENT_READY) === false) { + this.ready = false; + return; + } + + if (this.ready && options.inline) { + this.view(this.index); + } + } + /** + * Get the no conflict viewer class. + * @returns {Viewer} The viewer class. + */ + + }], [{ + key: "noConflict", + value: function noConflict() { + window.Viewer = AnotherViewer; + return Viewer; + } + /** + * Change the default options. + * @param {Object} options - The new default options. + */ + + }, { + key: "setDefaults", + value: function setDefaults(options) { + assign(DEFAULTS, isPlainObject(options) && options); + } + }]); + + return Viewer; + }(); + + assign(Viewer.prototype, render, events, handlers, methods, others); + + return Viewer; + +}))); \ No newline at end of file diff --git a/muk_web_preview_image/static/src/js/image.js b/muk_web_preview_image/static/src/js/image.js new file mode 100644 index 0000000..881e9a6 --- /dev/null +++ b/muk_web_preview_image/static/src/js/image.js @@ -0,0 +1,92 @@ +/********************************************************************************** +* +* Copyright (C) 2017 MuK IT GmbH +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +**********************************************************************************/ + +odoo.define('muk_preview_markdown.PreviewContentImage', function (require) { +"use strict"; + +var core = require('web.core'); +var ajax = require('web.ajax'); +var utils = require('web.utils'); +var session = require('web.session'); + +var registry = require('muk_preview.registry'); + +var AbstractPreviewContent = require('muk_preview.AbstractPreviewContent'); + +var QWeb = core.qweb; +var _t = core._t; + +var PreviewContentImage = AbstractPreviewContent.extend({ + template: "muk_preview.PreviewContentImage", + cssLibs: [ + '/muk_web_preview_image/static/lib/viewer/viewer.css', + ], + jsLibs: [ + '/muk_web_preview_image/static/lib/viewer/viewer.js', + '/muk_web_preview_image/static/lib/viewer/jquery-viewer.js', + ], + renderPreviewContent: function() { + this.$('img').viewer({ + inline: true, + button: false, + navbar: false, + title: false, + toolbar: { + zoomIn: 1, + zoomOut: 1, + oneToOne: 1, + reset: 1, + prev: 0, + next: 0, + play: { + show: 1, + size: 'large', + }, + rotateLeft: 1, + rotateRight: 1, + flipHorizontal: 1, + flipVertical: 1, + }, + }); + }, + downloadable: true, + printable: true, +}); + +_.each([ + 'cod', 'ras', 'fif', 'gif', 'ief', 'jpeg', 'jpg', 'jpe', 'png', 'tiff', + 'tif', 'mcf', 'wbmp', 'fh4', 'fh5', 'fhc', 'ico', 'pnm', 'pbm', 'pgm', + 'ppm', 'rgb', 'xwd', 'xbm', 'xpm' +], function(extension) { + registry.add(extension, PreviewContentImage); + registry.add("." + extension, PreviewContentImage); +}); +_.each([ + 'image/cis-cod', 'image/cmu-raster', 'image/fif', 'image/gif', 'image/ief', + 'image/png', 'image/tiff', 'image/vasa', 'image/vnd.wap.wbmp', 'image/x-freehand', + 'image/x-portable-anymap', 'image/x-portable-bitmap', 'image/x-portable-graymap', + 'image/x-portable-pixmap', 'image/x-rgb', 'image/x-windowdump', 'image/x-xbitmap', + 'image/jpeg', 'image/x-icon', 'image/x-xpixmap' +], function(mimetype) { + registry.add(mimetype, PreviewContentImage); +}); + +return PreviewContentImage; + +}); diff --git a/muk_web_preview_image/static/src/js/vector.js b/muk_web_preview_image/static/src/js/vector.js new file mode 100644 index 0000000..ce1e821 --- /dev/null +++ b/muk_web_preview_image/static/src/js/vector.js @@ -0,0 +1,94 @@ +/********************************************************************************** +* +* Copyright (C) 2017 MuK IT GmbH +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +**********************************************************************************/ + +odoo.define('muk_preview_markdown.PreviewContentVector', function (require) { +"use strict"; + +var core = require('web.core'); +var ajax = require('web.ajax'); +var utils = require('web.utils'); +var session = require('web.session'); + +var registry = require('muk_preview.registry'); + +var AbstractPreviewContent = require('muk_preview.AbstractPreviewContent'); + +var QWeb = core.qweb; +var _t = core._t; + +var PreviewContentVector = AbstractPreviewContent.extend({ + events: _.extend({}, AbstractPreviewContent.prototype.events, { + 'click .zoom-plus': '_onZoomIn', + 'click .zoom-minus': '_onZoomOut', + 'click .zoom-reset': '_onReset', + }), + template: "muk_preview.PreviewContentVector", + jsLibs: [ + '/muk_web_preview_image/static/lib/svg-pan-zoom/svg-pan-zoom.js', + ], + willStart: function() { + var def = $.ajax({ + url: this.url, + dataType: "text", + }).fail(function(jqXHR, textStatus) { + console.error(textStatus); + }).done(function(vector) { + this.vector = vector; + }.bind(this)); + return $.when(this._super.apply(this, arguments), def); + }, + renderPreviewContent: function() { + this.$('.vector-content').html(this.vector); + this.svgPanZoom = this.$("svg").svgPanZoom({ + events: { + mouseWheel: true, + doubleClick: true, + drag: true, + dragCursor: "move", + }, + animationTime: 300, + zoomFactor: 0.1, + maxZoom: 5, + panFactor: 100, + }); + return this._super.apply(this, arguments); + }, + _onZoomIn: function(event) { + console.log(this.svgPanZoom); + this.svgPanZoom.zoomIn(); + }, + _onZoomOut: function(event) { + this.svgPanZoom.zoomOut(); + }, + _onReset: function(event) { + this.svgPanZoom.reset(); + }, + downloadable: true, + printable: true, +}); + + + +registry.add('svg', PreviewContentVector); +registry.add('.svg', PreviewContentVector); +registry.add('image/svg+xml', PreviewContentVector); + +return PreviewContentVector; + +}); diff --git a/muk_web_preview_image/static/src/scss/image.scss b/muk_web_preview_image/static/src/scss/image.scss new file mode 100644 index 0000000..b92db5e --- /dev/null +++ b/muk_web_preview_image/static/src/scss/image.scss @@ -0,0 +1,39 @@ +/********************************************************************************** +* +* Copyright (C) 2017 MuK IT GmbH +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +**********************************************************************************/ + +.mk_preview_image { + width: 100%; + height: 100%; + .viewer-container { + width: 100% ! important; + height: 100% ! important; + } + img { + display: none; + } +} + +@media print { + .mk_preview_image { + img { + display: block; + } + } +} + diff --git a/muk_web_preview_image/static/src/scss/vector.scss b/muk_web_preview_image/static/src/scss/vector.scss new file mode 100644 index 0000000..8aa9ff4 --- /dev/null +++ b/muk_web_preview_image/static/src/scss/vector.scss @@ -0,0 +1,41 @@ +/********************************************************************************** +* +* Copyright (C) 2017 MuK IT GmbH +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +**********************************************************************************/ + +.mk_preview_vector { + width: 100%; + height: 100%; + position: absolute; + .vector-controls { + position: absolute; + bottom: 15px; + right: 25px; + z-index: 1; + .btn { + color: gray('700'); + background: transparent; + font-size: 25px; + } + } + svg { + width: 100%; + height: 100%; + position: absolute; + } +} + diff --git a/muk_web_preview_image/static/src/xml/image.xml b/muk_web_preview_image/static/src/xml/image.xml new file mode 100644 index 0000000..88bba11 --- /dev/null +++ b/muk_web_preview_image/static/src/xml/image.xml @@ -0,0 +1,30 @@ + + + + + + + + +
    + +
    +
    +
    + +
    \ No newline at end of file diff --git a/muk_web_preview_image/static/src/xml/vector.xml b/muk_web_preview_image/static/src/xml/vector.xml new file mode 100644 index 0000000..e5197f5 --- /dev/null +++ b/muk_web_preview_image/static/src/xml/vector.xml @@ -0,0 +1,44 @@ + + + + + + + + +
    +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    + +
    \ No newline at end of file diff --git a/muk_web_preview_image/template/assets.xml b/muk_web_preview_image/template/assets.xml new file mode 100644 index 0000000..f9729c8 --- /dev/null +++ b/muk_web_preview_image/template/assets.xml @@ -0,0 +1,31 @@ + + + + + +