From a5c4a8da8f7c7c23aa8a2719fc821a8b94437899 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 8 Jan 2016 08:20:50 +0100 Subject: [PATCH] Bugfix von #22 with new option alertError and merged pull request #23 --- README.md | 2 + bower.json | 2 +- dist/simple-lightbox.js | 135 +++++++++++++++++++----------------- dist/simple-lightbox.min.js | 2 +- package.json | 2 +- 5 files changed, 78 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 4e5cb97..49e187c 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ var lightbox = $('.gallery a').simpleLightbox(options); | heightRatio: | 0.9 | float | Ratio of image height to screen height | | disableRightClick | false | bool | disable rightclick on image or not | | disableScroll | true | bool | stop scrolling page if lightbox is opened | +| alertError | true | bool | show an alert, if image was not found | ###Events | Name | Description | @@ -85,6 +86,7 @@ var lightbox2 = $('.lighbox-2 a').simpleLightbox(); ``` ### Changelog +**1.7.1 - Bugfix von #22 with new option alertError and merged pull request #23** **1.7.0 - Add support for fading between photos, Bugfix for single image navigation, option for caption delay** **1.6.0 - Option for caption position. Disable prev or next arrow if loop is false and position is first or last.** **1.5.1 - Bugfix for multiple lightboxes on one page** diff --git a/bower.json b/bower.json index 20d6f00..5eca6d6 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "simplelightbox", - "version": "1.7.0", + "version": "1.7.1", "homepage": "http://andreknieriem.de/simple-lightbox", "authors": [ "André Rinas (http://andreknieriem.de)" diff --git a/dist/simple-lightbox.js b/dist/simple-lightbox.js index 4dc34ac..7782d9a 100644 --- a/dist/simple-lightbox.js +++ b/dist/simple-lightbox.js @@ -7,10 +7,10 @@ ;( function( $, window, document, undefined ) { 'use strict'; - + $.fn.simpleLightbox = function( options ) { - + var options = $.extend({ overlay: true, spinner: true, @@ -37,9 +37,10 @@ $.fn.simpleLightbox = function( options ) widthRatio: 0.8, heightRatio: 0.9, disableRightClick: false, - disableScroll: true + disableScroll: true, + alertError: true }, options ); - + // global variables var touchDevice = ( 'ontouchstart' in window ), pointerEnabled = window.navigator.pointerEnabled || window.navigator.msPointerEnabled, @@ -71,8 +72,8 @@ $.fn.simpleLightbox = function( options ) return false; }, opened = false, - - selector = this.selector, + + objects = $( this.selector, this.context ), transPrefix = transPrefix(), canTransisions = (transPrefix !== false) ? true : false, prefix = 'simplelb', @@ -94,11 +95,11 @@ $.fn.simpleLightbox = function( options ) image = $('.sl-image'); if(options.close) closeBtn.appendTo(wrapper); if(options.showCounter){ - if($(selector).length > 1){ + if(objects.length > 1){ counter.appendTo(wrapper); - counter.find('.sl-total').text($(selector).length); + counter.find('.sl-total').text(objects.length); } - + } if(options.nav) nav.appendTo(wrapper); if(options.spinner) spinner.appendTo(wrapper); @@ -109,7 +110,7 @@ $.fn.simpleLightbox = function( options ) wrapper.appendTo('body'); if(options.overlay) overlay.appendTo($('body')); animating = true; - index = $(selector).index(elem); + index = objects.index(elem); curImg = $( '' ) .hide() .attr('src', elem.attr('href')); @@ -123,7 +124,7 @@ $.fn.simpleLightbox = function( options ) counter.fadeIn('fast'); adjustImage(); if(options.preloading) preload(); - setTimeout( function(){ elem.trigger($.Event('shown.simplelightbox'));} ,options.animationSpeed); + setTimeout( function(){ elem.trigger($.Event('shown.simplelightbox')); } ,options.animationSpeed); }, adjustImage = function(dir){ if(!curImg.length) return; @@ -131,17 +132,27 @@ $.fn.simpleLightbox = function( options ) windowWidth = $( window ).width() * options.widthRatio, windowHeight = $( window ).height() * options.heightRatio; tmpImage.src = curImg.attr( 'src' ); - + + $(tmpImage).bind('error',function(ev){ + //no image was found + animating = false; + if(options.alertError){ + alert('Image not found, next image will be loaded'); + } + loadImage(1); + return; + }) + tmpImage.onload = function() { var imageWidth = tmpImage.width, imageHeight = tmpImage.height; - + if( imageWidth > windowWidth || imageHeight > windowHeight ){ var ratio = imageWidth / imageHeight > windowWidth / windowHeight ? imageWidth / windowWidth : imageHeight / windowHeight; imageWidth /= ratio; imageHeight /= ratio; } - + $('.sl-image').css({ 'top': ( $( window ).height() - imageHeight ) / 2 + 'px', 'left': ( $( window ).width() - imageWidth ) / 2 + 'px' @@ -154,7 +165,7 @@ $.fn.simpleLightbox = function( options ) }) .fadeIn('fast'); opened = true; - var cSel = (options.captionSelector == 'self') ? $(selector).eq(index) : $(selector).eq(index).find(options.captionSelector); + var cSel = (options.captionSelector == 'self') ? objects.eq(index) : objects.eq(index).find(options.captionSelector); if(options.captionType == 'data'){ var captionText = cSel.data(options.captionsData); } else if(options.captionType == 'text'){ @@ -162,15 +173,15 @@ $.fn.simpleLightbox = function( options ) } else { var captionText = cSel.prop(options.captionsData); } - + if(!options.loop) { if(index == 0){ $('.sl-prev').hide();} - if(index >= $(selector).length -1) {$('.sl-next').hide();} - if(index > 0 && index < $(selector).length -1){ $('.sl-prev, .sl-next').show(); } + if(index >= objects.length -1) {$('.sl-next').hide();} + if(index > 0 && index < objects.length -1){ $('.sl-prev, .sl-next').show(); } } - - if($(selector).length == 1) $('.sl-prev, .sl-next').hide(); - + + if(objects.length == 1) $('.sl-prev, .sl-next').hide(); + if(dir == 1 || dir == -1){ var css = { 'opacity': 1.0 }; if( options.animationSlide ) { @@ -182,7 +193,7 @@ $.fn.simpleLightbox = function( options ) css.left = parseInt( $('.sl-image').css( 'left' ) ) + 100 * dir + 'px'; } } - + $('.sl-image').animate( css, options.animationSpeed, function(){ animating = false; setCaption(captionText); @@ -191,7 +202,7 @@ $.fn.simpleLightbox = function( options ) animating = false; setCaption(captionText); } - + } }, setCaption = function(captiontext){ @@ -206,17 +217,17 @@ $.fn.simpleLightbox = function( options ) $('.sl-image').css(styles); }, preload = function(){ - var next = (index+1 < 0) ? $(selector).length -1: (index+1 >= $(selector).length -1) ? 0 : index+1, - prev = (index-1 < 0) ? $(selector).length -1: (index-1 >= $(selector).length -1) ? 0 : index-1; - $( '' ).attr( 'src', $(selector).eq(next).attr( 'href' ) ).load(); - $( '' ).attr( 'src', $(selector).eq(prev).attr( 'href' ) ).load(); - + var next = (index+1 < 0) ? objects.length -1: (index+1 >= objects.length -1) ? 0 : index+1, + prev = (index-1 < 0) ? objects.length -1: (index-1 >= objects.length -1) ? 0 : index-1; + $( '' ).attr( 'src', objects.eq(next).attr( 'href' ) ).load(); + $( '' ).attr( 'src', objects.eq(prev).attr( 'href' ) ).load(); + }, loadImage = function(dir){ spinner.show(); var newIndex = index + dir; - if(animating || (newIndex < 0 || newIndex >= $(selector).length) && options.loop == false ) return; - index = (newIndex < 0) ? $(selector).length -1: (newIndex > $(selector).length -1) ? 0 : newIndex; + if(animating || (newIndex < 0 || newIndex >= objects.length) && options.loop == false ) return; + index = (newIndex < 0) ? objects.length -1: (newIndex > objects.length -1) ? 0 : newIndex; $('.sl-wrapper .sl-counter .sl-current').text(index +1); var css = { 'opacity': 0 }; if( options.animationSlide ) { @@ -226,7 +237,7 @@ $.fn.simpleLightbox = function( options ) $('.sl-image').animate( css, options.animationSpeed, function(){ setTimeout( function(){ // fadeout old image - var elem = $(selector).eq(index); + var elem = objects.eq(index); curImg .attr('src', elem.attr('href')); $('.sl-caption').remove(); @@ -237,7 +248,7 @@ $.fn.simpleLightbox = function( options ) }, close = function(){ if(animating) return; - var elem = $(selector).eq(index), + var elem = objects.eq(index), triggered = false; elem.trigger($.Event('close.simplelightbox')); $('.sl-image img, .sl-overlay, .sl-close, .sl-navigation, .sl-image .sl-caption, .sl-counter').fadeOut('fast', function(){ @@ -273,51 +284,51 @@ $.fn.simpleLightbox = function( options ) $('body').css({'padding-right':$('body').data('padding'), 'overflow':'auto'}); } } - + // events setup(); - + // resize/responsive - $( window ).on( 'resize', adjustImage ); - + $( window ).on( 'resize', adjustImage ); + // open lightbox - $( document ).on( 'click.'+prefix, this.selector, function( e ){ - if(isValidLink(this)){ - e.preventDefault(); - if(animating) return false; - openImage($(this)); - } + objects.on( 'click.'+prefix, function( e ){ + if(isValidLink(this)){ + e.preventDefault(); + if(animating) return false; + openImage($(this)); + } }); - + // close lightbox on close btn - $(document).on('click', '.sl-close', function(e){ + $( document ).on('click', '.sl-close', function(e){ e.preventDefault(); if(opened){ close();} }); - + // close on click on doc - $(document).click(function(e){ + $( document ).click(function(e){ if(opened){ if((options.docClose && $(e.target).closest('.sl-image').length == 0 && $(e.target).closest('.sl-navigation').length == 0)){ close(); } } }); - + // disable rightclick if(options.disableRightClick){ - $(document).on('contextmenu', '.sl-image img', function(e){ + $( document ).on('contextmenu', '.sl-image img', function(e){ return false; }); } - + // nav-buttons $(document).on('click', '.sl-navigation button', function(e){ e.preventDefault(); swipeDiff = 0; loadImage( $(this).hasClass('sl-next') ? 1 : -1 ); }); - + // keyboard-control if( options.enableKeyboard ){ $( document ).on( 'keyup.'+prefix, function( e ){ @@ -335,14 +346,14 @@ $.fn.simpleLightbox = function( options ) } }); } - + // touchcontrols var swipeStart = 0, swipeEnd = 0, mousedown = false, imageLeft = 0; - - $(document) + + $( document ) .on( 'touchstart mousedown pointerdown MSPointerDown', '.sl-image', function(e) { if(mousedown) return true; @@ -367,7 +378,7 @@ $.fn.simpleLightbox = function( options ) if(mousedown){ mousedown = false; if( Math.abs( swipeDiff ) > options.swipeTolerance ) { - loadImage( swipeDiff > 0 ? 1 : -1 ); + loadImage( swipeDiff > 0 ? 1 : -1 ); } else if( options.animationSlide ) { @@ -376,31 +387,31 @@ $.fn.simpleLightbox = function( options ) } } }); - + // Public methods this.open = function(elem){ openImage(elem); } - + this.next = function(){ loadImage( 1 ); } - + this.prev = function(){ loadImage( -1 ); } - + this.close = function(){ close(); } - + this.destroy = function(){ - $(document).unbind('click.'+prefix).unbind('keyup.'+prefix); + $( document ).unbind('click.'+prefix).unbind('keyup.'+prefix); close(); $('.sl-overlay, .sl-wrapper').remove(); } - + return this; - + }; })( jQuery, window, document ); \ No newline at end of file diff --git a/dist/simple-lightbox.min.js b/dist/simple-lightbox.min.js index f9c6aa8..d43ab74 100644 --- a/dist/simple-lightbox.min.js +++ b/dist/simple-lightbox.min.js @@ -2,4 +2,4 @@ By André Rinas, www.andreknieriem.de Available for use under the MIT License */ -!function(e,t,n,i){"use strict";e.fn.simpleLightbox=function(i){var i=e.extend({overlay:!0,spinner:!0,nav:!0,navText:["‹","›"],captions:!0,captionDelay:0,captionSelector:"img",captionType:"attr",captionsData:"title",captionPosition:"bottom",close:!0,closeText:"×",showCounter:!0,fileExt:"png|jpg|jpeg|gif",animationSlide:!0,animationSpeed:250,preloading:!0,enableKeyboard:!0,loop:!0,docClose:!0,swipeTolerance:50,className:"simple-lightbox",widthRatio:.8,heightRatio:.9,disableRightClick:!1,disableScroll:!0},i),a=(t.navigator.pointerEnabled||t.navigator.msPointerEnabled,0),o=e(),s=function(){var e=n.body||n.documentElement,e=e.style;return""==e.WebkitTransition?"-webkit-":""==e.MozTransition?"-moz-":""==e.OTransition?"-o-":""==e.transition?"":!1},l=!1,r=this.selector,s=s(),c=s!==!1?!0:!1,d="simplelb",p=e("
").addClass("sl-overlay"),h=e(""),u=e("
").addClass("sl-counter").html('/'),m=!1,v=0,b=e(),x=e("
").addClass("sl-caption pos-"+i.captionPosition),y=e("
").addClass("sl-wrapper").addClass(i.className).html('
'),w=function(t){return i.fileExt?"a"==e(t).prop("tagName").toLowerCase()&&new RegExp(".("+i.fileExt+")$","i").test(e(t).attr("href")):!0},T=function(){b=e(".sl-image"),i.close&&h.appendTo(y),i.showCounter&&e(r).length>1&&(u.appendTo(y),u.find(".sl-total").text(e(r).length)),i.nav&&g.appendTo(y),i.spinner&&f.appendTo(y)},S=function(t){t.trigger(e.Event("show.simplelightbox")),i.disableScroll&&M("hide"),y.appendTo("body"),i.overlay&&p.appendTo(e("body")),m=!0,v=e(r).index(t),o=e("").hide().attr("src",t.attr("href")),e(".sl-image").html(""),o.appendTo(e(".sl-image")),p.fadeIn("fast"),e(".sl-close").fadeIn("fast"),f.show(),g.fadeIn("fast"),e(".sl-wrapper .sl-counter .sl-current").text(v+1),u.fadeIn("fast"),C(),i.preloading&&D(),setTimeout(function(){t.trigger(e.Event("shown.simplelightbox"))},i.animationSpeed)},C=function(n){if(o.length){var a=new Image,s=e(t).width()*i.widthRatio,d=e(t).height()*i.heightRatio;a.src=o.attr("src"),a.onload=function(){var p=a.width,h=a.height;if(p>s||h>d){var g=p/h>s/d?p/s:h/d;p/=g,h/=g}e(".sl-image").css({top:(e(t).height()-h)/2+"px",left:(e(t).width()-p)/2+"px"}),f.hide(),o.css({width:p+"px",height:h+"px"}).fadeIn("fast"),l=!0;var u="self"==i.captionSelector?e(r).eq(v):e(r).eq(v).find(i.captionSelector);if("data"==i.captionType)var b=u.data(i.captionsData);else if("text"==i.captionType)var b=u.html();else var b=u.prop(i.captionsData);if(i.loop||(0==v&&e(".sl-prev").hide(),v>=e(r).length-1&&e(".sl-next").hide(),v>0&&vv+1?e(r).length-1:v+1>=e(r).length-1?0:v+1,n=0>v-1?e(r).length-1:v-1>=e(r).length-1?0:v-1;e("").attr("src",e(r).eq(t).attr("href")).load(),e("").attr("src",e(r).eq(n).attr("href")).load()},I=function(t){f.show();var n=v+t;if(!(m||(0>n||n>=e(r).length)&&0==i.loop)){v=0>n?e(r).length-1:n>e(r).length-1?0:n,e(".sl-wrapper .sl-counter .sl-current").text(v+1);var s={opacity:0};i.animationSlide&&(c?k(i.animationSpeed/1e3,-100*t-a+"px"):s.left=parseInt(e(".sl-image").css("left"))+-100*t+"px"),e(".sl-image").animate(s,i.animationSpeed,function(){setTimeout(function(){var n=e(r).eq(v);o.attr("src",n.attr("href")),e(".sl-caption").remove(),C(t),i.preloading&&D()},100)})}},q=function(){if(!m){var t=e(r).eq(v),n=!1;t.trigger(e.Event("close.simplelightbox")),e(".sl-image img, .sl-overlay, .sl-close, .sl-navigation, .sl-image .sl-caption, .sl-counter").fadeOut("fast",function(){i.disableScroll&&M("show"),e(".sl-wrapper, .sl-overlay").remove(),n||t.trigger(e.Event("closed.simplelightbox")),n=!0}),o=e(),l=!1,m=!1}},M=function(i){if("hide"==i){var a=t.innerWidth;if(!a){var o=n.documentElement.getBoundingClientRect();a=o.right-Math.abs(o.left)}if(n.body.clientWidth0&&e("body").css({"padding-right":l+r,overflow:"hidden"})}}else e("body").css({"padding-right":e("body").data("padding"),overflow:"auto"})};T(),e(t).on("resize",C),e(n).on("click."+d,this.selector,function(t){if(w(this)){if(t.preventDefault(),m)return!1;S(e(this))}}),e(n).on("click",".sl-close",function(e){e.preventDefault(),l&&q()}),e(n).click(function(t){l&&i.docClose&&0==e(t.target).closest(".sl-image").length&&0==e(t.target).closest(".sl-navigation").length&&q()}),i.disableRightClick&&e(n).on("contextmenu",".sl-image img",function(e){return!1}),e(n).on("click",".sl-navigation button",function(t){t.preventDefault(),a=0,I(e(this).hasClass("sl-next")?1:-1)}),i.enableKeyboard&&e(n).on("keyup."+d,function(e){if(e.preventDefault(),a=0,l){var t=e.keyCode;27==t&&q(),(37==t||39==e.keyCode)&&I(39==e.keyCode?1:-1)}});var R=0,P=0,W=!1,X=0;return e(n).on("touchstart mousedown pointerdown MSPointerDown",".sl-image",function(e){return W?!0:(c&&(X=parseInt(b.css("left"))),W=!0,R=e.originalEvent.pageX||e.originalEvent.touches[0].pageX,!1)}).on("touchmove mousemove pointermove MSPointerMove",function(e){return W?(e.preventDefault(),P=e.originalEvent.pageX||e.originalEvent.touches[0].pageX,a=R-P,void(i.animationSlide&&(c?k(0,-a+"px"):b.css("left",X-a+"px")))):!0}).on("touchend mouseup touchcancel pointerup pointercancel MSPointerUp MSPointerCancel",function(e){W&&(W=!1,Math.abs(a)>i.swipeTolerance?I(a>0?1:-1):i.animationSlide&&(c?k(i.animationSpeed/1e3,"0px"):b.animate({left:X+"px"},i.animationSpeed/2)))}),this.open=function(e){S(e)},this.next=function(){I(1)},this.prev=function(){I(-1)},this.close=function(){q()},this.destroy=function(){e(n).unbind("click."+d).unbind("keyup."+d),q(),e(".sl-overlay, .sl-wrapper").remove()},this}}(jQuery,window,document); \ No newline at end of file +!function(e,t,n,i){"use strict";e.fn.simpleLightbox=function(i){var i=e.extend({overlay:!0,spinner:!0,nav:!0,navText:["‹","›"],captions:!0,captionDelay:0,captionSelector:"img",captionType:"attr",captionsData:"title",captionPosition:"bottom",close:!0,closeText:"×",showCounter:!0,fileExt:"png|jpg|jpeg|gif",animationSlide:!0,animationSpeed:250,preloading:!0,enableKeyboard:!0,loop:!0,docClose:!0,swipeTolerance:50,className:"simple-lightbox",widthRatio:.8,heightRatio:.9,disableRightClick:!1,disableScroll:!0,alertError:!0},i),a=(t.navigator.pointerEnabled||t.navigator.msPointerEnabled,0),o=e(),s=function(){var e=n.body||n.documentElement,e=e.style;return""==e.WebkitTransition?"-webkit-":""==e.MozTransition?"-moz-":""==e.OTransition?"-o-":""==e.transition?"":!1},l=!1,r=e(this.selector,this.context),s=s(),d=s!==!1?!0:!1,c="simplelb",p=e("
").addClass("sl-overlay"),h=e(""),u=e("
").addClass("sl-counter").html('/'),m=!1,v=0,b=e(),x=e("
").addClass("sl-caption pos-"+i.captionPosition),y=e("
").addClass("sl-wrapper").addClass(i.className).html('
'),w=function(t){return i.fileExt?"a"==e(t).prop("tagName").toLowerCase()&&new RegExp(".("+i.fileExt+")$","i").test(e(t).attr("href")):!0},T=function(){b=e(".sl-image"),i.close&&h.appendTo(y),i.showCounter&&r.length>1&&(u.appendTo(y),u.find(".sl-total").text(r.length)),i.nav&&g.appendTo(y),i.spinner&&f.appendTo(y)},S=function(t){t.trigger(e.Event("show.simplelightbox")),i.disableScroll&&M("hide"),y.appendTo("body"),i.overlay&&p.appendTo(e("body")),m=!0,v=r.index(t),o=e("").hide().attr("src",t.attr("href")),e(".sl-image").html(""),o.appendTo(e(".sl-image")),p.fadeIn("fast"),e(".sl-close").fadeIn("fast"),f.show(),g.fadeIn("fast"),e(".sl-wrapper .sl-counter .sl-current").text(v+1),u.fadeIn("fast"),C(),i.preloading&&I(),setTimeout(function(){t.trigger(e.Event("shown.simplelightbox"))},i.animationSpeed)},C=function(n){if(o.length){var a=new Image,s=e(t).width()*i.widthRatio,c=e(t).height()*i.heightRatio;a.src=o.attr("src"),e(a).bind("error",function(e){m=!1,i.alertError&&alert("Image not found, next image will be loaded"),D(1)}),a.onload=function(){var p=a.width,h=a.height;if(p>s||h>c){var g=p/h>s/c?p/s:h/c;p/=g,h/=g}e(".sl-image").css({top:(e(t).height()-h)/2+"px",left:(e(t).width()-p)/2+"px"}),f.hide(),o.css({width:p+"px",height:h+"px"}).fadeIn("fast"),l=!0;var u="self"==i.captionSelector?r.eq(v):r.eq(v).find(i.captionSelector);if("data"==i.captionType)var b=u.data(i.captionsData);else if("text"==i.captionType)var b=u.html();else var b=u.prop(i.captionsData);if(i.loop||(0==v&&e(".sl-prev").hide(),v>=r.length-1&&e(".sl-next").hide(),v>0&&vv+1?r.length-1:v+1>=r.length-1?0:v+1,n=0>v-1?r.length-1:v-1>=r.length-1?0:v-1;e("").attr("src",r.eq(t).attr("href")).load(),e("").attr("src",r.eq(n).attr("href")).load()},D=function(t){f.show();var n=v+t;if(!(m||(0>n||n>=r.length)&&0==i.loop)){v=0>n?r.length-1:n>r.length-1?0:n,e(".sl-wrapper .sl-counter .sl-current").text(v+1);var s={opacity:0};i.animationSlide&&(d?k(i.animationSpeed/1e3,-100*t-a+"px"):s.left=parseInt(e(".sl-image").css("left"))+-100*t+"px"),e(".sl-image").animate(s,i.animationSpeed,function(){setTimeout(function(){var n=r.eq(v);o.attr("src",n.attr("href")),e(".sl-caption").remove(),C(t),i.preloading&&I()},100)})}},q=function(){if(!m){var t=r.eq(v),n=!1;t.trigger(e.Event("close.simplelightbox")),e(".sl-image img, .sl-overlay, .sl-close, .sl-navigation, .sl-image .sl-caption, .sl-counter").fadeOut("fast",function(){i.disableScroll&&M("show"),e(".sl-wrapper, .sl-overlay").remove(),n||t.trigger(e.Event("closed.simplelightbox")),n=!0}),o=e(),l=!1,m=!1}},M=function(i){if("hide"==i){var a=t.innerWidth;if(!a){var o=n.documentElement.getBoundingClientRect();a=o.right-Math.abs(o.left)}if(n.body.clientWidth0&&e("body").css({"padding-right":l+r,overflow:"hidden"})}}else e("body").css({"padding-right":e("body").data("padding"),overflow:"auto"})};T(),e(t).on("resize",C),r.on("click."+c,function(t){if(w(this)){if(t.preventDefault(),m)return!1;S(e(this))}}),e(n).on("click",".sl-close",function(e){e.preventDefault(),l&&q()}),e(n).click(function(t){l&&i.docClose&&0==e(t.target).closest(".sl-image").length&&0==e(t.target).closest(".sl-navigation").length&&q()}),i.disableRightClick&&e(n).on("contextmenu",".sl-image img",function(e){return!1}),e(n).on("click",".sl-navigation button",function(t){t.preventDefault(),a=0,D(e(this).hasClass("sl-next")?1:-1)}),i.enableKeyboard&&e(n).on("keyup."+c,function(e){if(e.preventDefault(),a=0,l){var t=e.keyCode;27==t&&q(),(37==t||39==e.keyCode)&&D(39==e.keyCode?1:-1)}});var R=0,P=0,W=!1,X=0;return e(n).on("touchstart mousedown pointerdown MSPointerDown",".sl-image",function(e){return W?!0:(d&&(X=parseInt(b.css("left"))),W=!0,R=e.originalEvent.pageX||e.originalEvent.touches[0].pageX,!1)}).on("touchmove mousemove pointermove MSPointerMove",function(e){return W?(e.preventDefault(),P=e.originalEvent.pageX||e.originalEvent.touches[0].pageX,a=R-P,void(i.animationSlide&&(d?k(0,-a+"px"):b.css("left",X-a+"px")))):!0}).on("touchend mouseup touchcancel pointerup pointercancel MSPointerUp MSPointerCancel",function(e){W&&(W=!1,Math.abs(a)>i.swipeTolerance?D(a>0?1:-1):i.animationSlide&&(d?k(i.animationSpeed/1e3,"0px"):b.animate({left:X+"px"},i.animationSpeed/2)))}),this.open=function(e){S(e)},this.next=function(){D(1)},this.prev=function(){D(-1)},this.close=function(){q()},this.destroy=function(){e(n).unbind("click."+c).unbind("keyup."+c),q(),e(".sl-overlay, .sl-wrapper").remove()},this}}(jQuery,window,document); \ No newline at end of file diff --git a/package.json b/package.json index 4d3504a..9d485a7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simplelightbox", - "version": "1.7.0", + "version": "1.7.1", "description": "Touch-friendly image lightbox for mobile and desktop with jQuery", "main": "dist/simple-lightbox.js", "repository": {