From 06a1249d235b14e84b7d1d4a2fabd5471961fbc1 Mon Sep 17 00:00:00 2001 From: Maksim Krylosov Date: Sun, 14 Feb 2016 11:52:50 +0300 Subject: [PATCH] Release v2.0.0 --- Gruntfile.js | 159 +++++++++ LICENSE | 394 ++--------------------- README.md | 196 +++++++----- abigimage.jquery.css | 152 +++++++++ abigimage.jquery.js | 675 ++++++++++++++++++--------------------- abigimage.jquery.json | 44 --- abigimage.jquery.min.css | 2 + abigimage.jquery.min.js | 3 +- bower.json | 55 ++++ index.html | 438 ++++++++++++------------- package.json | 25 +- tpl/example.tpl.html | 24 ++ tpl/index.tpl.html | 127 ++++++++ 13 files changed, 1179 insertions(+), 1115 deletions(-) create mode 100644 Gruntfile.js create mode 100644 abigimage.jquery.css delete mode 100644 abigimage.jquery.json create mode 100644 abigimage.jquery.min.css create mode 100644 bower.json create mode 100644 tpl/example.tpl.html create mode 100644 tpl/index.tpl.html diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..b621062 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,159 @@ +module.exports = function (grunt) { + + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + + uglify: { + files: { + src: 'abigimage.jquery.js', + dest: 'abigimage.jquery.min.js' + } + }, + + cssmin: { + files: { + src: 'abigimage.jquery.css', + dest: 'abigimage.jquery.min.css' + } + }, + + usebanner: { + options: { + position: 'top', + banner: '/*! <%= pkg.name %> v<%= pkg.version %> (<%= grunt.template.today("yyyy-mm-dd") %>) */\n', + linebreak: false + }, + files: { + src: [ + 'abigimage.jquery.min.js', + 'abigimage.jquery.min.css' + ] + } + }, + + file_info: { + source_files: { + src: [ + 'abigimage.jquery.js', + 'abigimage.jquery.min.js', + 'abigimage.jquery.css', + 'abigimage.jquery.min.css' + ], + options: { + stdout: false, + inject: { + dest: 'README.md', + text: '* [abigimage.jquery.js](abigimage.jquery.js) ' + + '({{= sizeText(size(src[0])) }}) ' + + '[min](abigimage.jquery.min.js) ' + + '({{= sizeText(size(src[1])) }}, gzipped {{= sizeText(gzipSize(src[1])) }})' + + '\n* [abigimage.jquery.css](abigimage.jquery.css) ' + + '({{= sizeText(size(src[2])) }}) ' + + '[min](abigimage.jquery.min.css) ' + + '({{= sizeText(size(src[3])) }}, gzipped {{= sizeText(gzipSize(src[3])) }})' + } + } + } + }, + + replace: { + readme: { + options: { + patterns: [ + { + match: /version \*\*.*\*\* \(.*\)/, + replacement: 'version **<%= pkg.version %>** (<%= grunt.template.today("yyyy-mm-dd") %>)' + } + ] + }, + files: [ + { + src: 'README.md', + dest: 'README.md' + } + ] + }, + example: { + options: { + patterns: [ + { + match: //, + replacement: '<%= grunt.file.read("tpl/example.tpl.html") %>' + } + ] + }, + files: [ + { + src: 'index.html', + dest: 'index.html' + } + ] + } + }, + + markdown: { + index: { + options: { + template: 'tpl/index.tpl.html', + markdownOptions: { + gfm: true, + highlight: 'manual', + langPrefix: 'hljs lang-' + } + }, + files: [ + { + src: 'README.md', + dest: 'index.html' + } + ] + } + }, + + clean: [ + "abigimage.jquery.min.js.gz" + ], + + bump: { + options: { + pushTo: 'origin', + commitFiles: ['.'], + updateConfigs: ['pkg'] + } + } + }); + + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-cssmin'); + grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-file-info'); + grunt.loadNpmTasks('grunt-replace'); + grunt.loadNpmTasks('grunt-markdown'); + grunt.loadNpmTasks('grunt-bump'); + grunt.loadNpmTasks('grunt-npm'); + grunt.loadNpmTasks('grunt-banner'); + + grunt.registerTask('default', [ + 'bump-only:prerelease', + 'build' + ]); + + grunt.registerTask('build', [ + 'uglify', + 'cssmin', + 'usebanner', + 'file_info', + 'replace:readme', + 'markdown', + 'replace:example', + 'clean' + ]); + + grunt.registerTask('release', function (type) { + grunt.task.run('bump-only:' + (type || 'patch')); + grunt.task.run('build'); + grunt.task.run('bump-commit'); + grunt.task.run('npm-publish'); + }); + +}; diff --git a/LICENSE b/LICENSE index a612ad9..44d6134 100644 --- a/LICENSE +++ b/LICENSE @@ -1,373 +1,21 @@ -Mozilla Public License Version 2.0 -================================== - -1. Definitions --------------- - -1.1. "Contributor" - means each individual or legal entity that creates, contributes to - the creation of, or owns Covered Software. - -1.2. "Contributor Version" - means the combination of the Contributions of others (if any) used - by a Contributor and that particular Contributor's Contribution. - -1.3. "Contribution" - means Covered Software of a particular Contributor. - -1.4. "Covered Software" - means Source Code Form to which the initial Contributor has attached - the notice in Exhibit A, the Executable Form of such Source Code - Form, and Modifications of such Source Code Form, in each case - including portions thereof. - -1.5. "Incompatible With Secondary Licenses" - means - - (a) that the initial Contributor has attached the notice described - in Exhibit B to the Covered Software; or - - (b) that the Covered Software was made available under the terms of - version 1.1 or earlier of the License, but not also under the - terms of a Secondary License. - -1.6. "Executable Form" - means any form of the work other than Source Code Form. - -1.7. "Larger Work" - means a work that combines Covered Software with other material, in - a separate file or files, that is not Covered Software. - -1.8. "License" - means this document. - -1.9. "Licensable" - means having the right to grant, to the maximum extent possible, - whether at the time of the initial grant or subsequently, any and - all of the rights conveyed by this License. - -1.10. "Modifications" - means any of the following: - - (a) any file in Source Code Form that results from an addition to, - deletion from, or modification of the contents of Covered - Software; or - - (b) any new file in Source Code Form that contains any Covered - Software. - -1.11. "Patent Claims" of a Contributor - means any patent claim(s), including without limitation, method, - process, and apparatus claims, in any patent Licensable by such - Contributor that would be infringed, but for the grant of the - License, by the making, using, selling, offering for sale, having - made, import, or transfer of either its Contributions or its - Contributor Version. - -1.12. "Secondary License" - means either the GNU General Public License, Version 2.0, the GNU - Lesser General Public License, Version 2.1, the GNU Affero General - Public License, Version 3.0, or any later versions of those - licenses. - -1.13. "Source Code Form" - means the form of the work preferred for making modifications. - -1.14. "You" (or "Your") - means an individual or a legal entity exercising rights under this - License. For legal entities, "You" includes any entity that - controls, is controlled by, or is under common control with You. For - purposes of this definition, "control" means (a) the power, direct - or indirect, to cause the direction or management of such entity, - whether by contract or otherwise, or (b) ownership of more than - fifty percent (50%) of the outstanding shares or beneficial - ownership of such entity. - -2. License Grants and Conditions --------------------------------- - -2.1. Grants - -Each Contributor hereby grants You a world-wide, royalty-free, -non-exclusive license: - -(a) under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or - as part of a Larger Work; and - -(b) under Patent Claims of such Contributor to make, use, sell, offer - for sale, have made, import, and otherwise transfer either its - Contributions or its Contributor Version. - -2.2. Effective Date - -The licenses granted in Section 2.1 with respect to any Contribution -become effective for each Contribution on the date the Contributor first -distributes such Contribution. - -2.3. Limitations on Grant Scope - -The licenses granted in this Section 2 are the only rights granted under -this License. No additional rights or licenses will be implied from the -distribution or licensing of Covered Software under this License. -Notwithstanding Section 2.1(b) above, no patent license is granted by a -Contributor: - -(a) for any code that a Contributor has removed from Covered Software; - or - -(b) for infringements caused by: (i) Your and any other third party's - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - -(c) under Patent Claims infringed by Covered Software in the absence of - its Contributions. - -This License does not grant any rights in the trademarks, service marks, -or logos of any Contributor (except as may be necessary to comply with -the notice requirements in Section 3.4). - -2.4. Subsequent Licenses - -No Contributor makes additional grants as a result of Your choice to -distribute the Covered Software under a subsequent version of this -License (see Section 10.2) or under the terms of a Secondary License (if -permitted under the terms of Section 3.3). - -2.5. Representation - -Each Contributor represents that the Contributor believes its -Contributions are its original creation(s) or it has sufficient rights -to grant the rights to its Contributions conveyed by this License. - -2.6. Fair Use - -This License is not intended to limit any rights You have under -applicable copyright doctrines of fair use, fair dealing, or other -equivalents. - -2.7. Conditions - -Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted -in Section 2.1. - -3. Responsibilities -------------------- - -3.1. Distribution of Source Form - -All distribution of Covered Software in Source Code Form, including any -Modifications that You create or to which You contribute, must be under -the terms of this License. You must inform recipients that the Source -Code Form of the Covered Software is governed by the terms of this -License, and how they can obtain a copy of this License. You may not -attempt to alter or restrict the recipients' rights in the Source Code -Form. - -3.2. Distribution of Executable Form - -If You distribute Covered Software in Executable Form then: - -(a) such Covered Software must also be made available in Source Code - Form, as described in Section 3.1, and You must inform recipients of - the Executable Form how they can obtain a copy of such Source Code - Form by reasonable means in a timely manner, at a charge no more - than the cost of distribution to the recipient; and - -(b) You may distribute such Executable Form under the terms of this - License, or sublicense it under different terms, provided that the - license for the Executable Form does not attempt to limit or alter - the recipients' rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - -You may create and distribute a Larger Work under terms of Your choice, -provided that You also comply with the requirements of this License for -the Covered Software. If the Larger Work is a combination of Covered -Software with a work governed by one or more Secondary Licenses, and the -Covered Software is not Incompatible With Secondary Licenses, this -License permits You to additionally distribute such Covered Software -under the terms of such Secondary License(s), so that the recipient of -the Larger Work may, at their option, further distribute the Covered -Software under the terms of either this License or such Secondary -License(s). - -3.4. Notices - -You may not remove or alter the substance of any license notices -(including copyright notices, patent notices, disclaimers of warranty, -or limitations of liability) contained within the Source Code Form of -the Covered Software, except that You may alter any license notices to -the extent required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - -You may choose to offer, and to charge a fee for, warranty, support, -indemnity or liability obligations to one or more recipients of Covered -Software. However, You may do so only on Your own behalf, and not on -behalf of any Contributor. You must make it absolutely clear that any -such warranty, support, indemnity, or liability obligation is offered by -You alone, and You hereby agree to indemnify every Contributor for any -liability incurred by such Contributor as a result of warranty, support, -indemnity or liability terms You offer. You may include additional -disclaimers of warranty and limitations of liability specific to any -jurisdiction. - -4. Inability to Comply Due to Statute or Regulation ---------------------------------------------------- - -If it is impossible for You to comply with any of the terms of this -License with respect to some or all of the Covered Software due to -statute, judicial order, or regulation then You must: (a) comply with -the terms of this License to the maximum extent possible; and (b) -describe the limitations and the code they affect. Such description must -be placed in a text file included with all distributions of the Covered -Software under this License. Except to the extent prohibited by statute -or regulation, such description must be sufficiently detailed for a -recipient of ordinary skill to be able to understand it. - -5. Termination --------------- - -5.1. The rights granted under this License will terminate automatically -if You fail to comply with any of its terms. However, if You become -compliant, then the rights granted under this License from a particular -Contributor are reinstated (a) provisionally, unless and until such -Contributor explicitly and finally terminates Your grants, and (b) on an -ongoing basis, if such Contributor fails to notify You of the -non-compliance by some reasonable means prior to 60 days after You have -come back into compliance. Moreover, Your grants from a particular -Contributor are reinstated on an ongoing basis if such Contributor -notifies You of the non-compliance by some reasonable means, this is the -first time You have received notice of non-compliance with this License -from such Contributor, and You become compliant prior to 30 days after -Your receipt of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent -infringement claim (excluding declaratory judgment actions, -counter-claims, and cross-claims) alleging that a Contributor Version -directly or indirectly infringes any patent, then the rights granted to -You by any and all Contributors for the Covered Software under Section -2.1 of this License shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all -end user license agreements (excluding distributors and resellers) which -have been validly granted by You or Your distributors under this License -prior to termination shall survive termination. - -************************************************************************ -* * -* 6. Disclaimer of Warranty * -* ------------------------- * -* * -* Covered Software is provided under this License on an "as is" * -* basis, without warranty of any kind, either expressed, implied, or * -* statutory, including, without limitation, warranties that the * -* Covered Software is free of defects, merchantable, fit for a * -* particular purpose or non-infringing. The entire risk as to the * -* quality and performance of the Covered Software is with You. * -* Should any Covered Software prove defective in any respect, You * -* (not any Contributor) assume the cost of any necessary servicing, * -* repair, or correction. This disclaimer of warranty constitutes an * -* essential part of this License. No use of any Covered Software is * -* authorized under this License except under this disclaimer. * -* * -************************************************************************ - -************************************************************************ -* * -* 7. Limitation of Liability * -* -------------------------- * -* * -* Under no circumstances and under no legal theory, whether tort * -* (including negligence), contract, or otherwise, shall any * -* Contributor, or anyone who distributes Covered Software as * -* permitted above, be liable to You for any direct, indirect, * -* special, incidental, or consequential damages of any character * -* including, without limitation, damages for lost profits, loss of * -* goodwill, work stoppage, computer failure or malfunction, or any * -* and all other commercial damages or losses, even if such party * -* shall have been informed of the possibility of such damages. This * -* limitation of liability shall not apply to liability for death or * -* personal injury resulting from such party's negligence to the * -* extent applicable law prohibits such limitation. Some * -* jurisdictions do not allow the exclusion or limitation of * -* incidental or consequential damages, so this exclusion and * -* limitation may not apply to You. * -* * -************************************************************************ - -8. Litigation -------------- - -Any litigation relating to this License may be brought only in the -courts of a jurisdiction where the defendant maintains its principal -place of business and such litigation shall be governed by laws of that -jurisdiction, without reference to its conflict-of-law provisions. -Nothing in this Section shall prevent a party's ability to bring -cross-claims or counter-claims. - -9. Miscellaneous ----------------- - -This License represents the complete agreement concerning the subject -matter hereof. If any provision of this License is held to be -unenforceable, such provision shall be reformed only to the extent -necessary to make it enforceable. Any law or regulation which provides -that the language of a contract shall be construed against the drafter -shall not be used to construe this License against a Contributor. - -10. Versions of the License ---------------------------- - -10.1. New Versions - -Mozilla Foundation is the license steward. Except as provided in Section -10.3, no one other than the license steward has the right to modify or -publish new versions of this License. Each version will be given a -distinguishing version number. - -10.2. Effect of New Versions - -You may distribute the Covered Software under the terms of the version -of the License under which You originally received the Covered Software, -or under the terms of any subsequent version published by the license -steward. - -10.3. Modified Versions - -If you create software not governed by this License, and you want to -create a new license for such software, you may create and use a -modified version of this License if you rename the license and remove -any references to the name of the license steward (except to note that -such modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary -Licenses - -If You choose to distribute Source Code Form that is Incompatible With -Secondary Licenses under the terms of this version of the License, the -notice described in Exhibit B of this License must be attached. - -Exhibit A - Source Code Form License Notice -------------------------------------------- - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular -file, then You may include the notice in a location (such as a LICENSE -file in a relevant directory) where a recipient would be likely to look -for such a notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - "Incompatible With Secondary Licenses" Notice ---------------------------------------------------------- - - This Source Code Form is "Incompatible With Secondary Licenses", as - defined by the Mozilla Public License, v. 2.0. +License (MIT) + +Copyright (c) 2014-2016 Maksim Krylosov + +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. diff --git a/README.md b/README.md index 2183dee..49e503f 100644 --- a/README.md +++ b/README.md @@ -2,42 +2,67 @@ `ABigImage` is jQuery plugin for viewing big versions of images. +Current version **2.0.0** (2016-02-14). + +
+
+ + + + +
+
+ +* [abigimage.jquery.js](abigimage.jquery.js) (14.1 kB) [min](abigimage.jquery.min.js) (5.9 kB, gzipped 2.2 kB) +* [abigimage.jquery.css](abigimage.jquery.css) (2.6 kB) [min](abigimage.jquery.min.css) (1.5 kB, gzipped 549 bytes) +* Fork at [Github](https://github.com/makryl/ABigImage) + ## Features - Fit mobile devices. - Uses CSS3 transform and transition for smooth touch sliding. - Touch slide left or right opens next or previous image, touch slide up or down closes image. +- Multi-touch and double-tap zoom. - Clicking image opens next one, clicking left side opens previous, clicking right side closes image. - Hotkeys for next, previous and close buttons. - Closing after viewing of all images. - Preloading of next and previous images. -- Multi-touch zoom. - Uses link's `href` or `data-href` attribute for large images. - Fully customizable styles. - Customizable bottom area. -- Customizable `onopen` event. +- Customizable `onopen` and `onclose` event. + + ## Usage ### Basic -Add jQuery and ABigImage scripts in head of page. +Add jQuery and ABigImage scripts, and ABigImage styles at your page. - - +```html + + + +``` Call plugin on selector of enlargeable images links. - $(function() { - /* all links with class "myimgclass" */ - $('.myimgclass').abigimage(); - - /* or all links to "*.jpg" images */ - $('a[href$=".jpg"]').abigimage(); - - /* or all links to images under dir "/my/images/dir/" */ - $('a[href^="/my/images/dir/"]').abigimage(); - }); +```js +$(function(){ + /* all links with class "myimgclass" */ + $('.myimgclass').abigimage(); + + /* or all links inside element with class "myimgboxclass" */ + $('.myimgboxclass a').abigimage(); + + /* or all links to "*.jpg" images */ + $('a[href$=".jpg"]').abigimage(); + + /* or all links to images under dir "/my/images/dir/" */ + $('a[href^="/my/images/dir/"]').abigimage(); +}); +``` ### Options @@ -47,110 +72,105 @@ Call plugin on selector of enlargeable images links. - `slideVelocity` - slide velocity to switch or close image (pixels per millisecond, default: 0.4). - `zoomMin` - minimal zoom that will hold (default: 1.5). - `zoomMax` - maximal zoom (default: 5). +- `doubleTapInterval` - zoom double-tap interval (milliseconds, default: 400). - `prevBtnHtml` - html of "previous" button (default: `←`). - `closeBtnHtml` - html of "close" button (default: `x`). - `keyNext` - hotkeys for "next" button (default: 13 enter, 32 space, 39 right, 40 down). - `keyPrev` - hotkeys for "previous" button (default: 8 backspace, 37 left, 38 up). - `keyNext` - hotkeys for "close" button (default: 27 escape, 35 end, 36 home). - `onopen` - function called when image opens. -- `*Attrs` - plugin elements attributes. -- `*CSS` - plugin elements CSS. -- `prevBtnHoverCSS` - "previous" button on hover CSS. -- `closeBtnHoverCSS` - "close" button on hover CSS. -- `bottomHoverCSS` - bottom area on hover CSS. - -Plugin generates next html code: - - -
- -
- -
- -
- -
- -
-
-
- -
- -
- -
-
-
- - - - - - -
- -
+- `onclose` - function called when image closes. + +To change styles use CSS classes of plugin's elements: + +```html +
+
+
+ +
+ +
+ + +
+
+
+
+
+``` ### Using onopen handler Function, defined as `onopen` handler, executes in context of plugin, and receives target element as argument. Plugin elements available in this context as properties. - $(function() { - $('a[href$=".jpg"]').abigimage({ - bottomCSS: { - fontSize: '2em', - textAlign: 'center' - }, - onopen: function (target) { - this.bottom.html( - $('img', target).attr('alt') - ); - } - }); - }); +```js +$('a[href$=".jpg"]').abigimage({ + onopen: function (target) { + this.bottom.html( + $('img', target).attr('alt') + ); + } +}); +``` ### Using custom links with data-href attribute If you want different link for plugin's big image and for non-javascript clients (search engines or browsers without javascript) - use `data-href` attribute: - ... +```html + ... +``` Also, you can use `data-href` attribute on any element, not only links. ### Static methods - /* open image by URL */ - $.abigimage.open('/some_image.jpg'); +- `open([src], [index], [sel])` - open image by URL or index. +- `next([sel])` - open next image. +- `prev([sel])` - open previous image. +- `close([sel])` - close image. +- `unbind([sel])` - unbind plugin events. + +```js +/* open image by URL */ +$.abigimage.open('/awesomeimage.jpg'); + +/* open image by index */ +$.abigimage.open(2); - /* open image by index in current list */ - $.abigimage.open(5); +/* open image by URL at specified position */ +$.abigimage.open('/awesomeimage.jpg', 5); - /* open image by URL at specified position in current list */ - $.abigimage.open('/some_image.jpg', 5); +/* open next image */ +$.abigimage.next(); - /* open next image */ - $.abigimage.next(); +/* open previous image */ +$.abigimage.prev(); - /* open previous image */ - $.abigimage.prev(); +/* close image */ +$.abigimage.close(); - /* close image */ - $.abigimage.close(); +/* unbind plugin events */ +$.abigimage.unbind(); +``` - /* unbind abigimage events */ - $.abigimage.unbind(); +All static methods by default tries to execute on current opened plugin insatnce, if no instances opened, tries to execute on last created instance. You can specify instance by passing it's selector in last argument `sel`. + +```js +$myimgs1 = $('.myimgs1 a').abigimage(); +$myimgs2 = $('.myimgs2 a').abigimage(); + +$.abigimage.open('/awesomeimage.jpg', null, $myimgs2); +$.abigimage.unbind($myimgs1); +``` ## Changes +- **2.0.0** - fixed multiple plugin instances context, added double-tap zoom, optimized touch event handlers, styles moved to CSS file, license changed to MIT. - **1.3.1** - fixed image caching, added `unbind` method. -## License - -Copyright © 2014 Maksim Krylosov +## MIT License -This Source Code Form is subject to the terms of the Mozilla Public -License, v. 2.0. If a copy of the MPL was not distributed with this -file, You can obtain one at http://mozilla.org/MPL/2.0/. +Copyright (c) 2014-2016 Maksim Krylosov diff --git a/abigimage.jquery.css b/abigimage.jquery.css new file mode 100644 index 0000000..2b0f5b8 --- /dev/null +++ b/abigimage.jquery.css @@ -0,0 +1,152 @@ +/** + * http://aeqdev.com/tools/js/abigimage/ + * + * MIT License + * + * Copyright (c) 2014-2016 Maksim Krylosov + */ + +.abigimage-overlay { + position: fixed; + z-index: 100; + top: 0; + right: 0; + bottom: 0; + left: 0; + background-color: #000; + border: 1px solid #000; /* android chrome fix O_o */ + opacity: .9; +} + +.abigimage-layout { + position: fixed; + z-index: 100; + top: 0; + right: 0; + bottom: 0; + left: 0; + -webkit-user-select: none; + -moz-user-select: none; + user-select: none; + -webkit-tap-highlight-color: rgba(0, 0, 0, 0); + line-height: 2.5; +} + +.abigimage-prevBtnBox { + cursor: pointer; + position: absolute; + top: 0; + right: 50%; + bottom: 0; + left: 0; +} + +.abigimage-closeBtnBox { + cursor: pointer; + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 50%; +} + +.abigimage-prevBtn { + color: #fff; + background-color: #000; + opacity: .5; + padding: 0 1em; + border-radius: 0 0 1ex 0; + position: absolute; + top: 0; + left: 0; + transition: all .2s ease-in-out; +} + +.abigimage-closeBtn { + color: #fff; + background-color: #000; + opacity: .5; + padding: 0 1em; + border-radius: 0 0 0 1ex; + position: absolute; + top: 0; + right: 0; + transition: all .2s ease-in-out; +} + +.abigimage-prevBtn:hover, .abigimage-prevBtn-hover, +.abigimage-closeBtn:hover, .abigimage-closeBtn-hover { + opacity: 1; +} + +.abigimage-box { + position: absolute; + width: 312.5%; + height: 100%; + left: -106.25%; + top: 0; +} + +.abigimage-box-zoom { + z-index: 101; +} + +.abigimage-img { + position: absolute; + margin: auto; + width: auto; + top: 0; + right: 0; + bottom: 0; + left: 0; + display: block; + cursor: pointer; + max-width: 32%; + max-height: 100%; +} + +.abigimage-imgNext { + position: absolute; + margin: auto; + width: auto; + top: 0; + right: 0; + bottom: 0; + left: 68%; + display: block; + max-width: 32%; + max-height: 100%; +} + +.abigimage-imgPrev { + position: absolute; + margin: auto; + width: auto; + top: 0; + right: 68%; + bottom: 0; + left: 0; + display: block; + max-width: 32%; + max-height: 100%; +} + +.abigimage-bottom { + position: fixed; + right: 0; + bottom: 0; + left: 0; + -webkit-user-select: text; + -moz-user-select: text; + user-select: text; + background-color: #000; + color: #fff; + opacity: .5; + padding: 0 1em; + text-align: center; + transition: all .2s ease-in-out; +} + +.abigimage-bottom:hover { + opacity: 1; +} diff --git a/abigimage.jquery.js b/abigimage.jquery.js index 24b42cd..8397a6c 100644 --- a/abigimage.jquery.js +++ b/abigimage.jquery.js @@ -1,164 +1,280 @@ /** * http://aeqdev.com/tools/js/abigimage/ - * v 1.3.1 * - * Copyright © 2014 Maksim Krylosov + * MIT License * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * Copyright (c) 2014-2016 Maksim Krylosov */ (function ($) { - var overlay = $('
').css({display: 'none'}).appendTo('body'), - layout = $('
').css({display: 'none'}).appendTo('body'), - box = $('
').appendTo(layout), - prevBtnWrapper = $('
').appendTo(box), - prevBtnBox = $('
').appendTo(prevBtnWrapper), - prevBtn = $('
').appendTo(prevBtnBox), - closeBtnWrapper = $('
').appendTo(box), - closeBtnBox = $('
').appendTo(closeBtnWrapper), - closeBtn = $('
').appendTo(closeBtnBox), - img = $('').appendTo(box), - imgNext = $('').appendTo(box), - imgPrev = $('').appendTo(box), - bottom = $('
').appendTo(layout); - - var opts = {}, - t = null, - i = null, - d = 0, - opened = false; - - function nextI() { - var j = i + 1; - if (j >= t.length) { - j = 0; - } - return j; - } + var last, + current, + overlay = $('
').addClass('abigimage-overlay') .appendTo('body') .hide(), + layout = $('
').addClass('abigimage-layout') .appendTo('body') .hide(), + box = $('
').addClass('abigimage-box') .appendTo(layout), + prevBtnBox = $('
').addClass('abigimage-prevBtnBox') .appendTo(box), + closeBtnBox = $('
').addClass('abigimage-closeBtnBox').appendTo(box), + prevBtn = $('
').addClass('abigimage-prevBtn') .appendTo(layout), + closeBtn = $('
').addClass('abigimage-closeBtn') .appendTo(layout), + bottom = $('
').addClass('abigimage-bottom') .appendTo(layout), + boxe = box[0]; - function prevI() { - var j = i - 1; - if (j < 0) { - j = t.length - 1; - } - return j; - } + $.fn.abigimage = function(options) { + var plugin = new ABigImage(this, options); + this._abigimage = plugin; + last = plugin; + return this.each(function(i) { + $(this).unbind('click.abigimage').bind('click.abigimage', function(event) { + prevent(event); + plugin.open(i); + }); + }); + }; - function next() { - if (d === t.length - 1) { - return close(); - } else { - ++d; - return open(nextI()); - } - } + $.fn.abigimage.defaults = { + fadeIn: 'fast', + fadeOut: 'fast', + slideWidth: .4, + slideVelocity: .4, + zoomMin: 1.5, + zoomMax: 5, + doubleTapInterval: 400, + prevBtnHtml: '←', + closeBtnHtml: 'x', + keyNext: [13 /* enter */, 32 /* space */, 39 /* right */, 40 /* down */], + keyPrev: [8 /* backspace */, 37 /* left */, 38 /* up */], + keyClose: [27 /* escape */, 35 /* end */, 36 /* home */], + onopen: null, + onclose: null + }; - function prev() { - if (d === 1 - t.length) { - return close(); - } else { - --d; - return open(prevI()); + $.abigimage = { + overlay: overlay, + layout: layout, + prevBtnBox: prevBtnBox, + prevBtn: prevBtn, + closeBtnBox: closeBtnBox, + closeBtn: closeBtn, + box: box, + bottom: bottom, + + open: function(src, index, sel) { + ((sel && sel._abigimage) || current || last).open(src, index); + }, + close: function(sel) { + ((sel && sel._abigimage) || current || last).close(); + }, + next: function(sel) { + ((sel && sel._abigimage) || current || last).next(); + }, + prev: function(sel) { + ((sel && sel._abigimage) || current || last).prev(); + }, + unbind: function(sel) { + ((sel && sel._abigimage) || current || last).unbind(); } - } + }; + + prevBtnBox.click(function(event) { + prevent(event); + if (current) current.prev(); + }).hover(function() { + prevBtn.addClass('abigimage-prevBtn-hover'); + }, function() { + prevBtn.removeClass('abigimage-prevBtn-hover'); + }); + + closeBtnBox.click(function(event) { + prevent(event); + if (current) current.close(); + }).hover(function() { + closeBtn.addClass('abigimage-closeBtn-hover'); + }, function() { + closeBtn.removeClass('abigimage-closeBtn-hover'); + }); + + prevBtn.click(function(event) { + prevent(event); + if (current) current.prev(); + }); - function key(event) { - if (opts.keyNext.indexOf(event.which) !== -1) { - next(); - return false; - } else if (opts.keyPrev.indexOf(event.which) !== -1) { - prev(); - return false; - } else if (opts.keyClose.indexOf(event.which) !== -1) { - close(); - return false; + closeBtn.click(function(event) { + prevent(event); + if (current) current.close(); + }); + + layout + .on('touchmove', prevent) + .on('wheel', prevent); + + if (boxe.addEventListener) { + function listen(element, event, listener) { // just for minification + element.addEventListener(event, listener); } + listen(boxe, 'touchstart', touchstart); + listen(boxe, 'touchmove', touchmove); + listen(boxe, 'touchend', touchend); + listen(boxe, 'touchcancel', touchend); + + listen(boxe, 'webkitTransitionEnd', transitionEnd); + listen(boxe, 'mozTransitionEnd', transitionEnd); + listen(boxe, 'msTransitionEnd', transitionEnd); + listen(boxe, 'oTransitionEnd', transitionEnd); + listen(boxe, 'transitionend', transitionEnd); } - function replaceImage(oldImage, newSrc) { - // force clear cache - var newImage = oldImage.removeAttr('src').clone(true).attr('src', newSrc); - oldImage.replaceWith(newImage); - return newImage; + function ABigImage(elements, options) { + $.extend(this, $.fn.abigimage.defaults, options); + + this.elements = elements; + + this.overlay = overlay; + this.layout = layout; + this.prevBtnBox = prevBtnBox; + this.prevBtn = prevBtn; + this.closeBtnBox = closeBtnBox; + this.closeBtn = closeBtn; + this.box = box; + this.bottom = bottom; + + this.index = -1; + this.distance = 0; } - function open(src, openI) { - if ('number' === typeof src) { - if (src === i || src < 0 || src > t.length - 1) { + ABigImage.prototype.open = function(src, index) { + current = this; + + var currLink; + if ('number' == typeof src) { + index = src; + if (index == this.index || index < 0 || index > this.elements.length - 1) { return; } - i = src; - var $t = $(t[i]); - src = $t.data('href') || $t.attr('href'); + currLink = $(this.elements[index]); + src = currLink.data('href') || currLink.attr('href'); } else { - if ('number' !== typeof openI) { - openI = -1; - } - if (i === openI) { + if ('number' != typeof index) { + index = this.index; + } else if (index == this.index) { return; } - i = openI; } - opened = true; + this.index = index; + + this.prevBtn.html(this.prevBtnHtml); + this.closeBtn.html(this.closeBtnHtml); + this.bottom.html(''); - img = replaceImage(img, src); - listenTouchEvents(); - var $tn = $(t[nextI()]); - imgNext = replaceImage(imgNext, $tn.data('href') || $tn.attr('href')); - var $tp = $(t[prevI()]); - imgPrev = replaceImage(imgPrev, $tp.data('href') || $tp.attr('href')); + $('img', this.box).remove(); - overlay.fadeIn(opts.fadeIn); - layout.fadeIn(opts.fadeIn); + this.box.removeClass('abigimage-box-zoom'); + slideAnimate(0, 0, 1); - opts.onopen.call(t, t[i], i); + this.img = createImage('abigimage-img', src) + .click(function(event) { + prevent(event); + if (current) current.next(); + }); - $(document).unbind('keydown', key).bind('keydown', key); + var nextElement = $(this.elements[this.nextIndex()]); + this.imgNext = createImage('abigimage-imgNext', nextElement.data('href') || nextElement.attr('href')); + var prevElement = $(this.elements[this.prevIndex()]); + this.imgPrev = createImage('abigimage-imgPrev', prevElement.data('href') || prevElement.attr('href')); - return false; - } + overlay.fadeIn(); + layout.fadeIn(); - function close() { - if (!opened) { - return; + $(document).unbind('keydown', documentKeydown).bind('keydown', documentKeydown); + + if (this.onopen) this.onopen.call(this, currLink); + }; + + ABigImage.prototype.next = function() { + if (this.distance == this.elements.length - 1) { + this.close(); + } else { + ++this.distance; + this.elements[this.nextIndex()].click(); + //this.open(this.nextIndex()); } - opened = false; - i = null; - d = 0; - overlay.fadeOut(opts.fadeOut); - layout.fadeOut(opts.fadeOut, transitionEnd); + }; - opts.onclose.call(t); + ABigImage.prototype.prev = function() { + if (this.distance == 1 - this.elements.length) { + this.close(); + } else { + --this.distance; + this.elements[this.prevIndex()].click(); + //this.open(this.prevIndex()); + } + }; - $(document).unbind('keydown', key); - return false; - } + ABigImage.prototype.close = function() { + if (!current) return; - function unbind() { - t.unbind('click.abigimage'); - } + $(document).unbind('keydown', documentKeydown); - prevBtnWrapper.click(function() { - return prev(); - }); + overlay.fadeOut(this.fadeOut); + layout.fadeOut(this.fadeOut, transitionEnd); - closeBtnWrapper.click(function() { - return close(); - }); + if (this.onclose) this.onclose.call(this); + + this.index = -1; + this.distance = 0; - var prevent = function(e) { - e.preventDefault(); + current = null; }; - layout - .on('touchmove', prevent) - .on('wheel', prevent); + ABigImage.prototype.unbind = function() { + this.close(); + this.elements.each(function() { + $(this).unbind('click.abigimage'); + }) + }; + ABigImage.prototype.key = function(keyCode) { + if (this.keyNext.indexOf(keyCode) != -1) { + this.next(); + } else if (this.keyPrev.indexOf(keyCode) != -1) { + this.prev(); + } else if (this.keyClose.indexOf(keyCode) != -1) { + this.close(); + } + }; + ABigImage.prototype.nextIndex = function() { + var index = this.index + 1; + if (index >= this.elements.length) { + index = 0; + } + return index; + }; + + ABigImage.prototype.prevIndex = function() { + var index = this.index - 1; + if (index < 0) { + index = this.elements.length - 1; + } + return index; + }; + + function createImage(className, src) { + return $('').addClass(className).attr('src', src).appendTo(box); + } + + function documentKeydown(event) { + if (current) { + prevent(event); + current.key(event.which); + } + } + + function prevent(event) { + event.preventDefault(); + event.stopPropagation(); + } var sx, sy, @@ -172,68 +288,32 @@ iw, ih, + dstart, start, width, height, minD, vert, touches, - multi, - - slideTransition = false, - slideQueueFn = [null, null, null], - bs = box[0].style; - - touchReset(); - listenTouchEvents(); - - function listenTouchEvents() { - img[0].addEventListener('touchstart', touchstart); - img[0].addEventListener('touchmove', touchmove); - img[0].addEventListener('touchend', touchend); - img[0].addEventListener('touchcancel', touchend); - } - - function touchReset() { - x = 0; - y = 0; - s = 1; - vert = null; - multi = false; - if (opts.imgCSS) { - img.css({zIndex: opts.imgCSS.zIndex}); - } - } - - function med(ts, c) { - var p = 0; - for (var t = 0, l = ts.length; t < l; t++) { - p += ts[t]['page' + c]; - } - return p / l; - } - - function dis(e) { - return Math.sqrt( - Math.pow(e.touches[0].pageX - e.touches[1].pageX, 2) + - Math.pow(e.touches[0].pageY - e.touches[1].pageY, 2) - ); - } + intr, + ontr, + bs = boxe.style; function touchstart(e) { - if (!opened) return; + if (!current) return; + if (e.touches.length > 1) { - multi = true; k = dis(e); - img.css({zIndex: opts.prevBtnBoxCSS.zIndex}); + current.box.addClass('abigimage-box-zoom'); } else { vert = null; + dstart = start; start = (new Date()).getTime(); width = box.width() * 0.34; height = box.height(); - minD = opts.slideWidth * width; - iw = img.width(); - ih = img.height(); + minD = current.slideWidth * width; + iw = current.img.width(); + ih = current.img.height(); } sx = x; sy = y; @@ -241,11 +321,12 @@ dx = 0; dy = 0; touches = e.touches; - e.preventDefault(); + prevent(e); } function touchmove(e) { - if (!opened) return; + if (!current) return; + dx = (med(e.touches, 'X') - med(touches, 'X')); dy = (med(e.touches, 'Y') - med(touches, 'Y')); x = sx + dx / s; @@ -253,7 +334,7 @@ if (e.touches.length > 1) { s = Math.max(1, ss * (dis(e) / k)); } - if (s > opts.zoomMin) { + if (s > current.zoomMin) { var mx = 0.5 * (iw - (iw / s)); var my = 0.5 * (ih - (ih / s)); x = Math.max(-mx, Math.min(mx, x)); @@ -271,21 +352,24 @@ y = 0; } } - slideQueueAnimate(x, y, s, false); - e.preventDefault(); + slideAnimate(x, y, s); + prevent(e); } function touchend(e) { - if (!opened) return; - var time = (new Date()).getTime() - start; + if (!current) return; + + var end = (new Date()).getTime(); + var time = end - start; if (!e.touches.length) { - if (s <= opts.zoomMin) { + if (s <= current.zoomMin) { if (time <= 1 || (dx >= -1 && dx <= 1 && dy >= -1 && dy <= 1)) { - if (multi) { - slideAnimate(0, 0, 1); + if (start - dstart <= current.doubleTapInterval) { + current.box.addClass('abigimage-box-zoom'); + slideAnimate(x, y, current.zoomMax, true); } else { - slideNext(true); + slideAnimate(0, 0, 1, true); } } else { if (vert) { @@ -293,7 +377,7 @@ if (ady > minD) { slideClose(); } else { - if (ady / time > opts.slideVelocity) { + if (ady / time > current.slideVelocity) { slideClose(); } else { slideBack(); @@ -305,7 +389,7 @@ } else if (dx > minD) { slidePrev(); } else { - if (Math.abs(dx) / time > opts.slideVelocity) { + if (Math.abs(dx) / time > current.slideVelocity) { if (dx < 0) { slideNext(); } else { @@ -317,77 +401,62 @@ } } } - touchReset(); - } else if (s > opts.zoomMax) { - s = opts.zoomMax; - - slideQueueAnimate(x, y, s, true); + } else if (s > current.zoomMax) { + slideAnimate(x, y, current.zoomMax, true); + } else if (s > current.zoomMin) { + if (end - dstart <= current.doubleTapInterval) { + slideBack(); + } } } - if (s <= opts.zoomMin) { - img.css({zIndex: opts.imgCSS.zIndex}); - } - touches = e.touches; - e.preventDefault(); + prevent(e); } - box.on('transitionend webkitTransitionEnd msTransitionEnd oTransitionEnd', transitionEnd); - - function transitionEnd() { - slideTransition = false; - for (var i = 0; i < 2 ; i++) { - if (slideQueueFn[i]) { - slideQueueFn[i](); - slideQueueFn[i] = null; - if (slideTransition) break; - } + function med(ts, c) { + var p = 0; + for (var t = 0, l = ts.length; t < l; t++) { + p += ts[t]['page' + c]; } + return p / l; } - img.click(function() { - return next(); - }); + function dis(e) { + return Math.sqrt( + Math.pow(e.touches[0].pageX - e.touches[1].pageX, 2) + + Math.pow(e.touches[0].pageY - e.touches[1].pageY, 2) + ); + } - function slideNext(reset) { - slideQueueAnimate(reset ? 0 : -width, 0, 1, !reset); - slideQueueEnd(next); + function slideNext() { + slideAnimate(-width, 0, 1, true, function() { + current.next(); + }); } function slidePrev() { - slideQueueAnimate(width, 0, 1, true); - slideQueueEnd(prev); + slideAnimate(width, 0, 1, true, function() { + current.prev(); + }); } function slideBack() { - slideQueueAnimate(0, 0, 1, true); + current.box.removeClass('abigimage-box-zoom'); + slideAnimate(0, 0, 1, true); } function slideClose() { slideBack(); - slideQueueEnd(); - close(); - } - - function slideQueue(fn, i) { - if (slideTransition) { - slideQueueFn[i || 0] = fn; - } else { - fn(); - } + current.close(); } - function slideQueueAnimate(x, y, s, transition, i) { - slideQueue(function() {slideAnimate(x, y, s, transition)}, i); - } - - function slideQueueEnd(fn) { - slideQueue(function() {slideAnimate(0, 0, 1, false); if (fn) fn();}, 1); - } - - function slideAnimate(x, y, s, transition) { - slideTransition = transition; + function slideAnimate(tx, ty, ts, transition, onend) { + x = tx; + y = ty; + s = ts; + intr = transition; + ontr = onend; var transform = 'scale(' + s + ') translate3d(' + x + 'px, ' + y + 'px, 0)'; bs.transition = transition ? 'all .2s ease-out' : ''; bs.webkitTransform = transform; @@ -397,149 +466,13 @@ bs.transform = transform; } - $.fn.abigimage = function(options) { - - t = this; - - opts = $.extend(true, $.fn.abigimage.defaults, options); - - this.overlay = overlay .attr(opts.overlayAttrs) .css(opts.overlayCSS); - this.layout = layout .attr(opts.layoutAttrs) .css(opts.layoutCSS); - this.box = box .attr(opts.boxAttrs) .css(opts.boxCSS); - this.prevBtnWrapper = prevBtnWrapper .attr(opts.prevBtnWrapperAttrs) .css(opts.prevBtnWrapperCSS); - this.prevBtnBox = prevBtnBox .attr(opts.prevBtnBoxAttrs) .css(opts.prevBtnBoxCSS); - this.prevBtn = prevBtn .attr(opts.prevBtnAttrs) .css(opts.prevBtnCSS) .html(opts.prevBtnHtml); - this.closeBtnWrapper = closeBtnWrapper .attr(opts.closeBtnWrapperAttrs) .css(opts.closeBtnWrapperCSS); - this.closeBtnBox = closeBtnBox .attr(opts.closeBtnBoxAttrs) .css(opts.closeBtnBoxCSS); - this.closeBtn = closeBtn .attr(opts.closeBtnAttrs) .css(opts.closeBtnCSS) .html(opts.closeBtnHtml); - this.img = img .attr(opts.imgAttrs) .css(opts.imgCSS); - this.imgNext = imgNext .attr(opts.imgNextAttrs) .css(opts.imgNextCSS); - this.imgPrev = imgPrev .attr(opts.imgPrevAttrs) .css(opts.imgPrevCSS); - this.bottom = bottom .attr(opts.bottomAttrs) .css(opts.bottomCSS); - - var prevBtnUnHoverCSS = {}; - for (var p in opts.prevBtnHoverCSS) { - if (opts.prevBtnCSS) { - prevBtnUnHoverCSS[p] = opts.prevBtnCSS[p]; - } - } - var closeBtnUnHoverCSS = {}; - for (var p in opts.closeBtnHoverCSS) { - if (opts.closeBtnCSS) { - closeBtnUnHoverCSS[p] = opts.closeBtnCSS[p]; - } - } - var bottomUnHoverCSS = {}; - for (var p in opts.bottomHoverCSS) { - if (opts.bottomCSS) { - bottomUnHoverCSS[p] = opts.bottomCSS[p]; - } + function transitionEnd() { + intr = false; + if (ontr) { + var f = ontr; + ontr = null; + f(); } - - this.prevBtnWrapper.hover(function() { - prevBtn.stop().animate(opts.prevBtnHoverCSS, opts.fadeIn); - }, function() { - prevBtn.stop().animate(prevBtnUnHoverCSS, opts.fadeOut); - }); - - this.closeBtnWrapper.hover(function() { - closeBtn.stop().animate(opts.closeBtnHoverCSS, opts.fadeIn); - }, function () { - closeBtn.stop().animate(closeBtnUnHoverCSS, opts.fadeOut); - }); - - this.bottom.hover(function() { - bottom.stop().animate(opts.bottomHoverCSS, opts.fadeIn); - }, function () { - bottom.stop().animate(bottomUnHoverCSS, opts.fadeOut); - }); - - return this.each(function(i) { - $(this).unbind('click.abigimage').bind('click.abigimage', function() { - return open(i); - }); - }); - }; - - $.abigimage = { - open: open, - next: next, - prev: prev, - close: close, - unbind: unbind - }; - - $.fn.abigimage.defaults = { - fadeIn: 'fast', - fadeOut: 'fast', - - slideWidth: .4, - slideVelocity: .4, - - zoomMin: 1.5, - zoomMax: 5, - - prevBtnHtml: '←', - closeBtnHtml: 'x', - - keyNext: [13 /* enter */, 32 /* space */, 39 /* right */, 40 /* down */], - keyPrev: [8 /* backspace */, 37 /* left */, 38 /* up */], - keyClose: [27 /* escape */, 35 /* end */, 36 /* home */], - - onopen: function() {}, - onclose: function() {}, - - overlayCSS: {position: 'fixed', zIndex: 101, top: 0, right: 0, bottom: 0, left: 0, - backgroundColor: '#000', opacity: .9}, - layoutCSS: {position: 'fixed', zIndex: 101, top: 0, right: 0, bottom: 0, left: 0, - '-webkit-user-select': 'none', '-moz-user-select': 'none', 'user-select': 'none', - '-webkit-tap-highlight-color': 'rgba(0, 0, 0, 0)', - lineHeight: 2.5}, - boxCSS: {position: 'absolute', width: '312.5%', height: '100%', left: '-106.25%', top: 0}, - - prevBtnWrapperCSS: {cursor: 'pointer', position: 'absolute', top: 0, right: '50%', bottom: 0, left: 0}, - closeBtnWrapperCSS: {cursor: 'pointer', position: 'absolute', top: 0, right: 0, bottom: 0, left: '50%'}, - - prevBtnBoxCSS: {position: 'absolute', zIndex: 103, top: 0, bottom: 0, left: '68%'}, - closeBtnBoxCSS: {position: 'absolute', zIndex: 103, top: 0, bottom: 0, right: '68%'}, - - prevBtnCSS: {color: '#fff', backgroundColor: '#000', opacity: .5, - padding: '0 1em', borderRadius: '0 0 1ex 0'}, - closeBtnCSS: {color: '#fff', backgroundColor: '#000', opacity: .5, - padding: '0 1em', borderRadius: '0 0 0 1ex'}, - - prevBtnHoverCSS: {opacity: 1}, - closeBtnHoverCSS: {opacity: 1}, - - imgCSS: {position: 'absolute', zIndex: 102, margin: 'auto', width: 'auto', - top: 0, right: 0, bottom: 0, left: 0, - display: 'block', cursor: 'pointer', maxWidth: '32%', maxHeight: '100%'}, - imgNextCSS: {position: 'absolute', margin: 'auto', width: 'auto', - top: 0, right: 0, bottom: 0, left: '68%', - display: 'block', maxWidth: '32%', maxHeight: '100%'}, - imgPrevCSS: {position: 'absolute', margin: 'auto', width: 'auto', - top: 0, right: '68%', bottom: 0, left: 0, - display: 'block', maxWidth: '32%', maxHeight: '100%'}, - - bottomCSS: {position: 'fixed', zIndex: 104, right: 0, bottom: 0, left: 0, - '-webkit-user-select': 'text', '-moz-user-select': 'text', 'user-select': 'text', - backgroundColor: '#000', color: '#fff', opacity: .5, - padding: '0 1em', textAlign: 'center'}, - bottomHoverCSS: {opacity: 1}, - - overlayAttrs: {}, - layoutAttrs: {}, - boxAttrs: {}, - prevBtnWrapperAttrs: {}, - prevBtnBoxAttrs: {}, - prevBtnAttrs: {}, - closeBtnWrapperAttrs: {}, - closeBtnBoxAttrs: {}, - closeBtnAttrs: {}, - imgAttrs: {}, - imgNextAttrs: {}, - imgPrevAttrs: {}, - bottomAttrs: {} - }; + } }(jQuery)); diff --git a/abigimage.jquery.json b/abigimage.jquery.json deleted file mode 100644 index 4e26f4a..0000000 --- a/abigimage.jquery.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "name": "abigimage", - "version": "1.3.1", - "title": "ABigImage - view big versions of images", - "author": { - "name": "Maksim Krylosov", - "email": "aequiternus@gmail.com", - "url": "http://aeqdev.com/" - }, - "licenses": [{ - "type": "Mozilla Public License 2.0 (MPL-2.0)", - "url": "http://mozilla.org/MPL/2.0/" - }], - "dependencies": { - "jquery": ">=1.9" - }, - "description": "Fit mobile devices. Uses CSS3 transform and transition for smooth touch sliding. Touch slide left or right opens next or previous image, touch slide up or down closes image. Clicking image opens next one, clicking left side opens previous, clicking right side closes image. Hotkeys for next, previous and close buttons. Closing after viewing of all images. Preloading of next and previous images. Multi-touch zoom. Uses link's `href` or `data-href` attribute for large images. Fully customizable styles. Customizable bottom area. Customizable `onopen` event.", - "keywords": [ - "image", - "picture", - "photo", - "view", - "viewer", - "big", - "large", - "enlarge", - "lightbox", - "popup", - "mobile", - "desktop", - "slideshow", - "touch", - "slide", - "keyboard", - "hotkey", - "responsive", - "html5", - "jquery" - ], - "homepage": "http://aeqdev.com/tools/js/abigimage/", - "docs": "http://aeqdev.com/tools/js/abigimage/", - "demo": "http://aeqdev.com/tools/js/abigimage/", - "bugs": "https://github.com/Aequiternus/ABigImage/issues" -} diff --git a/abigimage.jquery.min.css b/abigimage.jquery.min.css new file mode 100644 index 0000000..1eb748a --- /dev/null +++ b/abigimage.jquery.min.css @@ -0,0 +1,2 @@ +/*! abigimage v2.0.0 (2016-02-14) */ +.abigimage-layout,.abigimage-overlay{position:fixed;z-index:100;right:0;left:0;bottom:0}.abigimage-overlay{top:0;background-color:#000;border:1px solid #000;opacity:.9}.abigimage-closeBtn,.abigimage-prevBtn{opacity:.5;top:0;background-color:#000;color:#fff;padding:0 1em;transition:all .2s ease-in-out}.abigimage-layout{top:0;-webkit-user-select:none;-moz-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent;line-height:2.5}.abigimage-prevBtnBox{cursor:pointer;position:absolute;top:0;right:50%;bottom:0;left:0}.abigimage-closeBtnBox{cursor:pointer;position:absolute;top:0;right:0;bottom:0;left:50%}.abigimage-prevBtn{border-radius:0 0 1ex;position:absolute;left:0}.abigimage-closeBtn{border-radius:0 0 0 1ex;position:absolute;right:0}.abigimage-closeBtn-hover,.abigimage-closeBtn:hover,.abigimage-prevBtn-hover,.abigimage-prevBtn:hover{opacity:1}.abigimage-box{position:absolute;width:312.5%;height:100%;left:-106.25%;top:0}.abigimage-img,.abigimage-imgNext,.abigimage-imgPrev{position:absolute;margin:auto;width:auto;top:0;display:block;max-width:32%;max-height:100%;bottom:0}.abigimage-box-zoom{z-index:101}.abigimage-img{right:0;left:0;cursor:pointer}.abigimage-imgNext{right:0;left:68%}.abigimage-imgPrev{right:68%;left:0}.abigimage-bottom{position:fixed;right:0;bottom:0;left:0;-webkit-user-select:text;-moz-user-select:text;user-select:text;background-color:#000;color:#fff;opacity:.5;padding:0 1em;text-align:center;transition:all .2s ease-in-out}.abigimage-bottom:hover{opacity:1} \ No newline at end of file diff --git a/abigimage.jquery.min.js b/abigimage.jquery.min.js index 8e2199c..6a5d04d 100644 --- a/abigimage.jquery.min.js +++ b/abigimage.jquery.min.js @@ -1 +1,2 @@ -(function(U){var ao=U("
").css({display:"none"}).appendTo("body"),S=U("
").css({display:"none"}).appendTo("body"),n=U("
").appendTo(S),Y=U("
").appendTo(n),G=U("
").appendTo(Y),v=U("
").appendTo(G),B=U("
").appendTo(n),O=U("
").appendTo(B),Z=U("
").appendTo(O),p=U("").appendTo(n),z=U("").appendTo(n),ag=U("").appendTo(n),b=U("
").appendTo(S);var P={},ah=null,an=null,aq=0,D=false;function al(){var d=an+1;if(d>=ah.length){d=0}return d}function o(){var d=an-1;if(d<0){d=ah.length-1}return d}function f(){if(aq===ah.length-1){return aj()}else{++aq;return M(al())}}function Q(){if(aq===1-ah.length){return aj()}else{--aq;return M(o())}}function H(d){if(P.keyNext.indexOf(d.which)!==-1){f();return false}else{if(P.keyPrev.indexOf(d.which)!==-1){Q();return false}else{if(P.keyClose.indexOf(d.which)!==-1){aj();return false}}}}function V(i,d){var k=i.removeAttr("src").clone(true).attr("src",d);i.replaceWith(k);return k}function M(k,d){if("number"===typeof k){if(k===an||k<0||k>ah.length-1){return}an=k;var t=U(ah[an]);k=t.data("href")||t.attr("href")}else{if("number"!==typeof d){d=-1}if(an===d){return}an=d}D=true;p=V(p,k);R();var s=U(ah[al()]);z=V(z,s.data("href")||s.attr("href"));var i=U(ah[o()]);ag=V(ag,i.data("href")||i.attr("href"));ao.fadeIn(P.fadeIn);S.fadeIn(P.fadeIn);P.onopen.call(ah,ah[an],an);U(document).unbind("keydown",H).bind("keydown",H);return false}function aj(){if(!D){return}D=false;an=null;aq=0;ao.fadeOut(P.fadeOut);S.fadeOut(P.fadeOut,K);P.onclose.call(ah);U(document).unbind("keydown",H);return false}function I(){ah.unbind("click.abigimage")}Y.click(function(){return Q()});B.click(function(){return aj()});var h=function(d){d.preventDefault()};S.on("touchmove",h).on("wheel",h);var r,q,w,af,ad,ai,am,l,g,L,X,N,a,e,at,C,av,ae,A=false,ab=[null,null,null],ak=n[0].style;au();R();function R(){p[0].addEventListener("touchstart",ar);p[0].addEventListener("touchmove",E);p[0].addEventListener("touchend",aa);p[0].addEventListener("touchcancel",aa)}function au(){af=0;ad=0;ai=1;C=null;ae=false;if(P.imgCSS){p.css({zIndex:P.imgCSS.zIndex})}}function F(k,x){var s=0;for(var i=0,d=k.length;i1){ae=true;am=ap(d);p.css({zIndex:P.prevBtnBoxCSS.zIndex})}else{C=null;N=(new Date()).getTime();a=n.width()*0.34;e=n.height();at=P.slideWidth*a;L=p.width();X=p.height()}r=af;q=ad;w=ai;l=0;g=0;av=d.touches;d.preventDefault()}function E(k){if(!D){return}l=(F(k.touches,"X")-F(av,"X"));g=(F(k.touches,"Y")-F(av,"Y"));af=r+l/ai;ad=q+g/ai;if(k.touches.length>1){ai=Math.max(1,w*(ap(k)/am))}if(ai>P.zoomMin){var s=0.5*(L-(L/ai));var i=0.5*(X-(X/ai));af=Math.max(-s,Math.min(s,af));ad=Math.max(-i,Math.min(i,ad))}else{if(null===C){var d=Math.abs(g)-Math.abs(l);if(Math.abs(d)>2){C=d>0}}if(C){af=0}else{ad=0}}W(af,ad,ai,false);k.preventDefault()}function aa(i){if(!D){return}var d=(new Date()).getTime()-N;if(!i.touches.length){if(ai<=P.zoomMin){if(d<=1||(l>=-1&&l<=1&&g>=-1&&g<=1)){if(ae){u(0,0,1)}else{T(true)}}else{if(C){var k=Math.abs(g);if(k>at){c()}else{if(k/d>P.slideVelocity){c()}else{j()}}}else{if(l<-at){T()}else{if(l>at){m()}else{if(Math.abs(l)/d>P.slideVelocity){if(l<0){T()}else{m()}}else{j()}}}}}au()}else{if(ai>P.zoomMax){ai=P.zoomMax;W(af,ad,ai,true)}}}if(ai<=P.zoomMin){p.css({zIndex:P.imgCSS.zIndex})}av=i.touches;i.preventDefault()}n.on("transitionend webkitTransitionEnd msTransitionEnd oTransitionEnd",K);function K(){A=false;for(var d=0;d<2;d++){if(ab[d]){ab[d]();ab[d]=null;if(A){break}}}}p.click(function(){return f()});function T(d){W(d?0:-a,0,1,!d);ac(f)}function m(){W(a,0,1,true);ac(Q)}function j(){W(0,0,1,true)}function c(){j();ac();aj()}function J(k,d){if(A){ab[d||0]=k}else{k()}}function W(d,ax,t,aw,k){J(function(){u(d,ax,t,aw)},k)}function ac(d){J(function(){u(0,0,1,false);if(d){d()}},1)}function u(d,aw,k,t){A=t;var i="scale("+k+") translate3d("+d+"px, "+aw+"px, 0)";ak.transition=t?"all .2s ease-out":"";ak.webkitTransform=i;ak.mozTransform=i;ak.msTransform=i;ak.oTransform=i;ak.transform=i}U.fn.abigimage=function(s){ah=this;P=U.extend(true,U.fn.abigimage.defaults,s);this.overlay=ao.attr(P.overlayAttrs).css(P.overlayCSS);this.layout=S.attr(P.layoutAttrs).css(P.layoutCSS);this.box=n.attr(P.boxAttrs).css(P.boxCSS);this.prevBtnWrapper=Y.attr(P.prevBtnWrapperAttrs).css(P.prevBtnWrapperCSS);this.prevBtnBox=G.attr(P.prevBtnBoxAttrs).css(P.prevBtnBoxCSS);this.prevBtn=v.attr(P.prevBtnAttrs).css(P.prevBtnCSS).html(P.prevBtnHtml);this.closeBtnWrapper=B.attr(P.closeBtnWrapperAttrs).css(P.closeBtnWrapperCSS);this.closeBtnBox=O.attr(P.closeBtnBoxAttrs).css(P.closeBtnBoxCSS);this.closeBtn=Z.attr(P.closeBtnAttrs).css(P.closeBtnCSS).html(P.closeBtnHtml);this.img=p.attr(P.imgAttrs).css(P.imgCSS);this.imgNext=z.attr(P.imgNextAttrs).css(P.imgNextCSS);this.imgPrev=ag.attr(P.imgPrevAttrs).css(P.imgPrevCSS);this.bottom=b.attr(P.bottomAttrs).css(P.bottomCSS);var k={};for(var t in P.prevBtnHoverCSS){if(P.prevBtnCSS){k[t]=P.prevBtnCSS[t]}}var d={};for(var t in P.closeBtnHoverCSS){if(P.closeBtnCSS){d[t]=P.closeBtnCSS[t]}}var i={};for(var t in P.bottomHoverCSS){if(P.bottomCSS){i[t]=P.bottomCSS[t]}}this.prevBtnWrapper.hover(function(){v.stop().animate(P.prevBtnHoverCSS,P.fadeIn)},function(){v.stop().animate(k,P.fadeOut)});this.closeBtnWrapper.hover(function(){Z.stop().animate(P.closeBtnHoverCSS,P.fadeIn)},function(){Z.stop().animate(d,P.fadeOut)});this.bottom.hover(function(){b.stop().animate(P.bottomHoverCSS,P.fadeIn)},function(){b.stop().animate(i,P.fadeOut)});return this.each(function(x){U(this).unbind("click.abigimage").bind("click.abigimage",function(){return M(x)})})};U.abigimage={open:M,next:f,prev:Q,close:aj,unbind:I};U.fn.abigimage.defaults={fadeIn:"fast",fadeOut:"fast",slideWidth:0.4,slideVelocity:0.4,zoomMin:1.5,zoomMax:5,prevBtnHtml:"←",closeBtnHtml:"x",keyNext:[13,32,39,40],keyPrev:[8,37,38],keyClose:[27,35,36],onopen:function(){},onclose:function(){},overlayCSS:{position:"fixed",zIndex:101,top:0,right:0,bottom:0,left:0,backgroundColor:"#000",opacity:0.9},layoutCSS:{position:"fixed",zIndex:101,top:0,right:0,bottom:0,left:0,"-webkit-user-select":"none","-moz-user-select":"none","user-select":"none","-webkit-tap-highlight-color":"rgba(0, 0, 0, 0)",lineHeight:2.5},boxCSS:{position:"absolute",width:"312.5%",height:"100%",left:"-106.25%",top:0},prevBtnWrapperCSS:{cursor:"pointer",position:"absolute",top:0,right:"50%",bottom:0,left:0},closeBtnWrapperCSS:{cursor:"pointer",position:"absolute",top:0,right:0,bottom:0,left:"50%"},prevBtnBoxCSS:{position:"absolute",zIndex:103,top:0,bottom:0,left:"68%"},closeBtnBoxCSS:{position:"absolute",zIndex:103,top:0,bottom:0,right:"68%"},prevBtnCSS:{color:"#fff",backgroundColor:"#000",opacity:0.5,padding:"0 1em",borderRadius:"0 0 1ex 0"},closeBtnCSS:{color:"#fff",backgroundColor:"#000",opacity:0.5,padding:"0 1em",borderRadius:"0 0 0 1ex"},prevBtnHoverCSS:{opacity:1},closeBtnHoverCSS:{opacity:1},imgCSS:{position:"absolute",zIndex:102,margin:"auto",width:"auto",top:0,right:0,bottom:0,left:0,display:"block",cursor:"pointer",maxWidth:"32%",maxHeight:"100%"},imgNextCSS:{position:"absolute",margin:"auto",width:"auto",top:0,right:0,bottom:0,left:"68%",display:"block",maxWidth:"32%",maxHeight:"100%"},imgPrevCSS:{position:"absolute",margin:"auto",width:"auto",top:0,right:"68%",bottom:0,left:0,display:"block",maxWidth:"32%",maxHeight:"100%"},bottomCSS:{position:"fixed",zIndex:104,right:0,bottom:0,left:0,"-webkit-user-select":"text","-moz-user-select":"text","user-select":"text",backgroundColor:"#000",color:"#fff",opacity:0.5,padding:"0 1em",textAlign:"center"},bottomHoverCSS:{opacity:1},overlayAttrs:{},layoutAttrs:{},boxAttrs:{},prevBtnWrapperAttrs:{},prevBtnBoxAttrs:{},prevBtnAttrs:{},closeBtnWrapperAttrs:{},closeBtnBoxAttrs:{},closeBtnAttrs:{},imgAttrs:{},imgNextAttrs:{},imgPrevAttrs:{},bottomAttrs:{}}}(jQuery)); \ No newline at end of file +/*! abigimage v2.0.0 (2016-02-14) */ +!function(a){function b(a,b,c){a.addEventListener(b,c)}function c(b,c){a.extend(this,a.fn.abigimage.defaults,c),this.elements=b,this.overlay=t,this.layout=u,this.prevBtnBox=w,this.prevBtn=y,this.closeBtnBox=x,this.closeBtn=z,this.box=v,this.bottom=A,this.index=-1,this.distance=0}function d(b,c){return a("").addClass(b).attr("src",c).appendTo(v)}function e(a){s&&(f(a),s.key(a.which))}function f(a){a.preventDefault(),a.stopPropagation()}function g(a){s&&(a.touches.length>1?(I=k(a),s.box.addClass("abigimage-box-zoom")):(S=null,N=O,O=(new Date).getTime(),P=.34*v.width(),Q=v.height(),R=s.slideWidth*P,L=s.img.width(),M=s.img.height()),C=F,D=G,E=H,J=0,K=0,T=a.touches,f(a))}function h(a){if(s){if(J=j(a.touches,"X")-j(T,"X"),K=j(a.touches,"Y")-j(T,"Y"),F=C+J/H,G=D+K/H,a.touches.length>1&&(H=Math.max(1,E*(k(a)/I))),H>s.zoomMin){var b=.5*(L-L/H),c=.5*(M-M/H);F=Math.max(-b,Math.min(b,F)),G=Math.max(-c,Math.min(c,G))}else{if(null===S){var d=Math.abs(K)-Math.abs(J);Math.abs(d)>2&&(S=d>0)}S?F=0:G=0}p(F,G,H),f(a)}}function i(a){if(s){var b=(new Date).getTime(),c=b-O;if(!a.touches.length)if(H<=s.zoomMin)if(1>=c||J>=-1&&1>=J&&K>=-1&&1>=K)O-N<=s.doubleTapInterval?(s.box.addClass("abigimage-box-zoom"),p(F,G,s.zoomMax,!0)):p(0,0,1,!0);else if(S){var d=Math.abs(K);d>R?o():d/c>s.slideVelocity?o():n()}else-R>J?l():J>R?m():Math.abs(J)/c>s.slideVelocity?0>J?l():m():n();else H>s.zoomMax?p(F,G,s.zoomMax,!0):H>s.zoomMin&&b-N<=s.doubleTapInterval&&n();T=a.touches,f(a)}}function j(a,b){for(var c=0,d=0,e=a.length;e>d;d++)c+=a[d]["page"+b];return c/e}function k(a){return Math.sqrt(Math.pow(a.touches[0].pageX-a.touches[1].pageX,2)+Math.pow(a.touches[0].pageY-a.touches[1].pageY,2))}function l(){p(-P,0,1,!0,function(){s.next()})}function m(){p(P,0,1,!0,function(){s.prev()})}function n(){s.box.removeClass("abigimage-box-zoom"),p(0,0,1,!0)}function o(){n(),s.close()}function p(a,b,c,d,e){F=a,G=b,H=c,U=d,V=e;var f="scale("+H+") translate3d("+F+"px, "+G+"px, 0)";W.transition=d?"all .2s ease-out":"",W.webkitTransform=f,W.mozTransform=f,W.msTransform=f,W.oTransform=f,W.transform=f}function q(){if(U=!1,V){var a=V;V=null,a()}}var r,s,t=a("
").addClass("abigimage-overlay").appendTo("body").hide(),u=a("
").addClass("abigimage-layout").appendTo("body").hide(),v=a("
").addClass("abigimage-box").appendTo(u),w=a("
").addClass("abigimage-prevBtnBox").appendTo(v),x=a("
").addClass("abigimage-closeBtnBox").appendTo(v),y=a("
").addClass("abigimage-prevBtn").appendTo(u),z=a("
").addClass("abigimage-closeBtn").appendTo(u),A=a("
").addClass("abigimage-bottom").appendTo(u),B=v[0];a.fn.abigimage=function(b){var d=new c(this,b);return this._abigimage=d,r=d,this.each(function(b){a(this).unbind("click.abigimage").bind("click.abigimage",function(a){f(a),d.open(b)})})},a.fn.abigimage.defaults={fadeIn:"fast",fadeOut:"fast",slideWidth:.4,slideVelocity:.4,zoomMin:1.5,zoomMax:5,doubleTapInterval:400,prevBtnHtml:"←",closeBtnHtml:"x",keyNext:[13,32,39,40],keyPrev:[8,37,38],keyClose:[27,35,36],onopen:null,onclose:null},a.abigimage={overlay:t,layout:u,prevBtnBox:w,prevBtn:y,closeBtnBox:x,closeBtn:z,box:v,bottom:A,open:function(a,b,c){(c&&c._abigimage||s||r).open(a,b)},close:function(a){(a&&a._abigimage||s||r).close()},next:function(a){(a&&a._abigimage||s||r).next()},prev:function(a){(a&&a._abigimage||s||r).prev()},unbind:function(a){(a&&a._abigimage||s||r).unbind()}},w.click(function(a){f(a),s&&s.prev()}).hover(function(){y.addClass("abigimage-prevBtn-hover")},function(){y.removeClass("abigimage-prevBtn-hover")}),x.click(function(a){f(a),s&&s.close()}).hover(function(){z.addClass("abigimage-closeBtn-hover")},function(){z.removeClass("abigimage-closeBtn-hover")}),y.click(function(a){f(a),s&&s.prev()}),z.click(function(a){f(a),s&&s.close()}),u.on("touchmove",f).on("wheel",f),B.addEventListener&&(b(B,"touchstart",g),b(B,"touchmove",h),b(B,"touchend",i),b(B,"touchcancel",i),b(B,"webkitTransitionEnd",q),b(B,"mozTransitionEnd",q),b(B,"msTransitionEnd",q),b(B,"oTransitionEnd",q),b(B,"transitionend",q)),c.prototype.open=function(b,c){s=this;var g;if("number"==typeof b){if(c=b,c==this.index||0>c||c>this.elements.length-1)return;g=a(this.elements[c]),b=g.data("href")||g.attr("href")}else if("number"!=typeof c)c=this.index;else if(c==this.index)return;this.index=c,this.prevBtn.html(this.prevBtnHtml),this.closeBtn.html(this.closeBtnHtml),this.bottom.html(""),a("img",this.box).remove(),this.box.removeClass("abigimage-box-zoom"),p(0,0,1),this.img=d("abigimage-img",b).click(function(a){f(a),s&&s.next()});var h=a(this.elements[this.nextIndex()]);this.imgNext=d("abigimage-imgNext",h.data("href")||h.attr("href"));var i=a(this.elements[this.prevIndex()]);this.imgPrev=d("abigimage-imgPrev",i.data("href")||i.attr("href")),t.fadeIn(),u.fadeIn(),a(document).unbind("keydown",e).bind("keydown",e),this.onopen&&this.onopen.call(this,g)},c.prototype.next=function(){this.distance==this.elements.length-1?this.close():(++this.distance,this.elements[this.nextIndex()].click())},c.prototype.prev=function(){this.distance==1-this.elements.length?this.close():(--this.distance,this.elements[this.prevIndex()].click())},c.prototype.close=function(){s&&(a(document).unbind("keydown",e),t.fadeOut(this.fadeOut),u.fadeOut(this.fadeOut,q),this.onclose&&this.onclose.call(this),this.index=-1,this.distance=0,s=null)},c.prototype.unbind=function(){this.close(),this.elements.each(function(){a(this).unbind("click.abigimage")})},c.prototype.key=function(a){-1!=this.keyNext.indexOf(a)?this.next():-1!=this.keyPrev.indexOf(a)?this.prev():-1!=this.keyClose.indexOf(a)&&this.close()},c.prototype.nextIndex=function(){var a=this.index+1;return a>=this.elements.length&&(a=0),a},c.prototype.prevIndex=function(){var a=this.index-1;return 0>a&&(a=this.elements.length-1),a};var C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W=B.style}(jQuery); \ No newline at end of file diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..7a91f7d --- /dev/null +++ b/bower.json @@ -0,0 +1,55 @@ +{ + "name": "jquery-abigimage", + "description": "ABigImage - view big versions of images. Fit mobile devices. Uses CSS3 transform and transition for smooth touch sliding. Touch slide left or right opens next or previous image, touch slide up or down closes image. Multi-touch and double-tap zoom. Clicking image opens next one, clicking left side opens previous, clicking right side closes image. Hotkeys for next, previous and close buttons. Closing after viewing of all images. Preloading of next and previous images. Uses link's `href` or `data-href` attribute for large images. Fully customizable styles. Customizable bottom area. Customizable `onopen` and `onclose` event.", + "main": "abigimage.jquery.min.js", + "authors": [ + "Maksim Krylosov (http://aeqdev.com/)" + ], + "license": "MIT", + "keywords": [ + "jquery-plugin", + "ecosystem:jquery", + "image", + "picture", + "photo", + "view", + "viewer", + "big", + "large", + "enlarge", + "zoom", + "lightbox", + "popup", + "mobile", + "desktop", + "slideshow", + "touch", + "slide", + "keyboard", + "hotkey", + "responsive", + "html5", + "jquery" + ], + "repository": { + "type": "git", + "url": "https://github.com/makryl/ABigImage.git" + }, + "moduleType": [], + "homepage": "http://aeqdev.com/tools/js/abigimage/", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests", + "tpl", + "img", + "Gruntfile.js", + "index.html", + "package.json" + ], + "dependencies": { + "jquery": ">=1.9" + } +} diff --git a/index.html b/index.html index 24664d5..64e6c25 100644 --- a/index.html +++ b/index.html @@ -1,91 +1,117 @@ - - ABigImage | js | tools | aeqdev.com - - - - - - - + .hljs { + display: block; + overflow-x: auto; + padding: 0.5em; + background: #2b2b2b; + } -
+ .hljs { + color: #bababa; + } -

- + .hljs-strong, + .hljs-emphasis { + color: #a8a8a2; + } + .hljs-bullet, + .hljs-quote, + .hljs-link, + .hljs-number, + .hljs-regexp, + .hljs-literal { + color: #6896ba; + } + .hljs-code, + .hljs-selector-class { + color: #a6e22e; + } -

ABigImage

+ .hljs-emphasis { + font-style: italic; + } -

ABigImage is jQuery plugin for viewing big versions of images.

+ .hljs-keyword, + .hljs-selector-tag, + .hljs-section, + .hljs-attribute, + .hljs-name, + .hljs-variable { + color: #cb7832; + } -

Current version: 1.3.0 (2015-06-23).

+ .hljs-params { + color: #b9b9b9; + } + .hljs-string, + .hljs-subst, + .hljs-type, + .hljs-built_in, + .hljs-builtin-name, + .hljs-symbol, + .hljs-selector-id, + .hljs-selector-attr, + .hljs-selector-pseudo, + .hljs-template-tag, + .hljs-template-variable, + .hljs-addition { + color: #e0c46c; + } + .hljs-comment, + .hljs-deletion, + .hljs-meta { + color: #7f7f7f; + } + + + -
- -
+
+

ABigImage

+

ABigImage is jQuery plugin for viewing big versions of images.

+

Current version 2.0.0 (2016-02-14).

@@ -95,36 +121,26 @@

ABigImage

- - -

Features

- -
-
    -
  • Fit mobile devices.
  • -
  • Uses CSS3 transform and transition for smooth touch sliding.
  • -
  • Touch slide left or right opens next or previous image, touch slide up or down closes image.
  • -
  • Clicking image opens next one, clicking left side opens previous, clicking right side closes image.
  • -
  • Hotkeys for next, previous and close buttons.
  • -
  • Closing after viewing of all images.
  • -
  • Preloading of next and previous images.
  • -
  • Multi-touch zoom.
  • -
  • Uses link's href or data-href attribute for large images.
  • -
  • Fully customizable styles.
  • -
  • Customizable bottom area.
  • -
  • Customizable onopen event.
  • -
-
- -
- -
- - - + +

Features

+
    +
  • Fit mobile devices.
  • +
  • Uses CSS3 transform and transition for smooth touch sliding.
  • +
  • Touch slide left or right opens next or previous image, touch slide up or down closes image.
  • +
  • Multi-touch and double-tap zoom.
  • +
  • Clicking image opens next one, clicking left side opens previous, clicking right side closes image.
  • +
  • Hotkeys for next, previous and close buttons.
  • +
  • Closing after viewing of all images.
  • +
  • Preloading of next and previous images.
  • +
  • Uses link's href or data-href attribute for large images.
  • +
  • Fully customizable styles.
  • +
  • Customizable bottom area.
  • +
  • Customizable onopen and onclose event.
  • +

Example

@@ -136,32 +152,43 @@

Example

Live example, where I'm using and testing this plugin at the moment: kawaiinyan.com.

-

Usage

- -

Basic

+ + + -

Add jQuery and ABigImage scripts in head of page.

+ -
<script src="jquery.js"></script>
-<script src="abigimage.jquery.js"></script>
+

Usage

+

Basic

+

Add jQuery and ABigImage scripts, and ABigImage styles at your page.

+
<script src="jquery.js"></script>
+<script src="abigimage.jquery.js"></script>
+<link rel="stylesheet" href="abigimage.jquery.css">
 
-

Call plugin on selector of enlargeable images links.

+
$(function(){
+    /* all links with class "myimgclass" */
+    $('.myimgclass').abigimage();
 
-
$(function() {
-    /* all links with class "myimgclass" */
-    $('.myimgclass').abigimage();
+    /* or all links inside element with class "myimgboxclass" */
+    $('.myimgboxclass a').abigimage();
 
-    /* or all links to "*.jpg" images */
-    $('a[href$=".jpg"]').abigimage();
+    /* or all links to "*.jpg" images */
+    $('a[href$=".jpg"]').abigimage();
 
-    /* or all links to images under dir "/my/images/dir/" */
-    $('a[href^="/my/images/dir/"]').abigimage();
+    /* or all links to images under dir "/my/images/dir/" */
+    $('a[href^="/my/images/dir/"]').abigimage();
 });
 
- -

Options

- +

Options

  • fadeIn - fade in duration or options (default: fast).
  • fadeOut - fade out duration or options (default: fast).
  • @@ -169,148 +196,95 @@

    Options

  • slideVelocity - slide velocity to switch or close image (pixels per millisecond, default: 0.4).
  • zoomMin - minimal zoom that will hold (default: 1.5).
  • zoomMax - maximal zoom (default: 5).
  • -
  • prevBtnHtml - html of "previous" button (default: ).
  • -
  • closeBtnHtml - html of "close" button (default: x).
  • -
  • keyNext - hotkeys for "next" button (by default: 13 enter, 32 space, 39 right, 40 down).
  • -
  • keyPrev - hotkeys for "previous" button (by default: 8 backspace, 37 left, 38 up).
  • -
  • keyClose - hotkeys for "close" button (by default: 27 escape, 35 end, 36 home).
  • +
  • doubleTapInterval - zoom double-tap interval (milliseconds, default: 400).
  • +
  • prevBtnHtml - html of "previous" button (default: &larr;).
  • +
  • closeBtnHtml - html of "close" button (default: x).
  • +
  • keyNext - hotkeys for "next" button (default: 13 enter, 32 space, 39 right, 40 down).
  • +
  • keyPrev - hotkeys for "previous" button (default: 8 backspace, 37 left, 38 up).
  • +
  • keyNext - hotkeys for "close" button (default: 27 escape, 35 end, 36 home).
  • onopen - function called when image opens.
  • -
  • *Attrs - plugin elements attributes.
  • -
  • *CSS - plugin elements CSS.
  • -
  • prevBtnHoverCSS - "previous" button on hover CSS.
  • -
  • closeBtnHoverCSS - "close" button on hover CSS.
  • -
  • bottomHoverCSS - bottom area on hover CSS.
  • +
  • onclose - function called when image closes.
- -

Plugin generates next html code:

- -
<!-- overlay -->
-<div></div>
-<!-- layout -->
-<div>
-    <!-- box -->
-    <div>
-        <!-- prevBtnWrapper (clickable behind the image, width 50%) -->
-        <div>
-            <!-- prevBtnBox (clickable above the image, button width) -->
-            <div>
-                <!-- prevBtn -->
-                <div><!-- prevBtnHtml --></div>
-            </div>
-        </div>
-        <!-- closeBtnWrapper (clickable behind the image, width 50%) -->
-        <div>
-            <!-- closeBtnBox (clickable above the image, button width) -->
-            <div>
-                <!-- closeBtn -->
-                <div><!-- closeBtnHtml --></div>
-            </div>
-        </div>
-        <!-- img -->
-        <img>
-        <!-- imgNext -->
-        <img>
-        <!-- imgPrev -->
-        <img>
-    </div>
-    <!-- bottom -->
-    <div></div>
-</div>
+

To change styles use CSS classes of plugin's elements:

+
<div class="abigimage-overlay"></div>
+<div class="abigimage-layout">
+    <div class="abigimage-box">
+        <!-- prevBtnBox (clickable behind the image, width 50%) -->
+        <div class="abigimage-prevBtnBox"></div>
+        <!-- closeBtnBox (clickable behind the image, width 50%) -->
+        <div class="abigimage-closeBtnBox"></div>
+        <img class="abigimage-img">
+        <img class="abigimage-imgNext">
+        <img class="abigimage-imgPrev">
+    </div>
+    <div class="abigimage-prevBtn"><!-- prevBtnHtml --></div>
+    <div class="abigimage-closeBtn"><!-- closeBtnHtml --></div>
+    <div class="abigimage-bottom"></div>
+</div>
 
- -

Using onopen handler

- +

Using onopen handler

Function, defined as onopen handler, executes in context of plugin, and receives target element as argument. Plugin elements available in this context as properties.

- -
$(function() {
-    $('a[href$=".jpg"]').abigimage({
-        bottomCSS: {
-            fontSize: '2em'
-        },
-        onopen: function (target) {
-            this.bottom.html(
-                $('img', target).attr('alt')
-            );
-        }
-    });
+
$('a[href$=".jpg"]').abigimage({
+    onopen: function (target) {
+        this.bottom.html(
+            $('img', target).attr('alt')
+        );
+    }
 });
 
- -

Using data-href attribute

- -

If you want different link for plugin's big image and for non-javascript clients (search engines or browsers without javascript) - use data-href attribute:

- -
<a href="/non_javascript_link.html" data-href="/images/big/myimage.jpg"> ... </a>
- + +

If you want different link for plugin's big image and for non-javascript clients (search engines or browsers without javascript) - use data-href attribute:

+
<a href="/non_javascript_link.html" data-href="/images/big/myimage.jpg"> ... </a>
+

Also, you can use data-href attribute on any element, not only links.

+

Static methods

+
    +
  • open([src], [index], [sel]) - open image by URL or index.
  • +
  • next([sel]) - open next image.
  • +
  • prev([sel]) - open previous image.
  • +
  • close([sel]) - close image.
  • +
  • unbind([sel]) - unbind plugin events.
  • +
+
/* open image by URL */
+$.abigimage.open('/awesomeimage.jpg');
 
-

Static methods

- -
/* open image by URL */
-$.abigimage.open('/some_image.jpg');
-
-/* open image by index in current list */
-$.abigimage.open(5);
+/* open image by index */
+$.abigimage.open(2);
 
-/* open image by URL at specified position in current list */
-$.abigimage.open('/some_image.jpg', 5);
+/* open image by URL at specified position */
+$.abigimage.open('/awesomeimage.jpg', 5);
 
-/* open next image */
+/* open next image */
 $.abigimage.next();
 
-/* open previous image */
+/* open previous image */
 $.abigimage.prev();
 
-/* close image */
+/* close image */
 $.abigimage.close();
 
-/* unbind abigimage events */
+/* unbind plugin events */
 $.abigimage.unbind();
 
+

All static methods by default tries to execute on current opened plugin insatnce, if no instances opened, tries to execute on last created instance. You can specify instance by passing it's selector in last argument sel.

+
$myimgs1 = $('.myimgs1 a').abigimage();
+$myimgs2 = $('.myimgs2 a').abigimage();
 
-
-
-

Changes

- +$.abigimage.open('/awesomeimage.jpg', null, $myimgs2); +$.abigimage.unbind($myimgs1); +
+

Changes

    -
  • 1.3.1 - fixed image caching, added unbind method.
  • +
  • 2.0.0 - fixed multiple plugin instances context, added double-tap zoom, optimized touch event handlers, styles moved to CSS file, license changed to MIT.
  • +
  • 1.3.1 - fixed image caching, added unbind method.
+

MIT License

+

Copyright (c) 2014-2016 Maksim Krylosov aequiternus@gmail.com

- -

P. S.

- -

I WANT your comments, feature requests, bug reports, suggestions, thoughts... on GitHub.

- - - -
- - - - - - - - - - +
- + diff --git a/package.json b/package.json index 6c00010..ddc9e29 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "abigimage", - "version": "1.3.1", - "author": "Maksim Krylosov (http://aeqdev.com/)", - "license": "MPL-2.0", + "version": "2.0.0", + "author": "Maksim Krylosov (http://aeqdev.com/)", + "license": "MIT", "homepage": "http://aeqdev.com/tools/js/abigimage/", - "bugs": "https://github.com/Aequiternus/ABigImage/issues", - "description": "ABigImage - view big versions of images. Fit mobile devices. Uses CSS3 transform and transition for smooth touch sliding. Touch slide left or right opens next or previous image, touch slide up or down closes image. Clicking image opens next one, clicking left side opens previous, clicking right side closes image. Hotkeys for next, previous and close buttons. Closing after viewing of all images. Preloading of next and previous images. Multi-touch zoom. Uses link's `href` or `data-href` attribute for large images. Fully customizable styles. Customizable bottom area. Customizable `onopen` event.", + "bugs": "https://github.com/makryl/ABigImage/issues", + "description": "ABigImage - view big versions of images. Fit mobile devices. Uses CSS3 transform and transition for smooth touch sliding. Touch slide left or right opens next or previous image, touch slide up or down closes image. Multi-touch and double-tap zoom. Clicking image opens next one, clicking left side opens previous, clicking right side closes image. Hotkeys for next, previous and close buttons. Closing after viewing of all images. Preloading of next and previous images. Uses link's `href` or `data-href` attribute for large images. Fully customizable styles. Customizable bottom area. Customizable `onopen` and `onclose` event.", "keywords": [ "jquery-plugin", "ecosystem:jquery", @@ -17,6 +17,7 @@ "big", "large", "enlarge", + "zoom", "lightbox", "popup", "mobile", @@ -33,9 +34,21 @@ "main": "abigimage.jquery.js", "repository": { "type": "git", - "url": "https://github.com/Aequiternus/ABigImage.git" + "url": "https://github.com/makryl/ABigImage.git" }, "dependencies": { "jquery": ">=1.9" + }, + "devDependencies": { + "grunt": "*", + "grunt-banner": "*", + "grunt-bump": "*", + "grunt-contrib-clean": "*", + "grunt-contrib-cssmin": "*", + "grunt-contrib-uglify": "*", + "grunt-file-info": "*", + "grunt-markdown": "*", + "grunt-npm": "*", + "grunt-replace": "*" } } diff --git a/tpl/example.tpl.html b/tpl/example.tpl.html new file mode 100644 index 0000000..22a00d4 --- /dev/null +++ b/tpl/example.tpl.html @@ -0,0 +1,24 @@ +

Example

+ +

+ First image + Second image + Third image + Fourth image +

+ +

Live example, where I'm using and testing this plugin at the moment: kawaiinyan.com.

+ + + + + + diff --git a/tpl/index.tpl.html b/tpl/index.tpl.html new file mode 100644 index 0000000..31702a4 --- /dev/null +++ b/tpl/index.tpl.html @@ -0,0 +1,127 @@ + + + + ABigImage | js | tools | aeqdev.com + + + + + + + + + +
+ +<%=content%> + +
+ + + + +