imagelightbox
Advanced tools
Comparing version 0.5.4 to 0.6.0
{ | ||
"name": "imagelightbox", | ||
"version": "0.5.4", | ||
"version": "0.6.0", | ||
"description": "Image Lightbox, Responsive and Touch‑friendly", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/rejas/imagelightbox.git", |
@@ -1,1 +0,1 @@ | ||
!function(t,n,i,e){"use strict";var o=t("<div/>").attr("id","imagelightbox-loading").append(t("<div/>")),a=t("<button/>",{type:"button",class:"imagelightbox-arrow imagelightbox-arrow-left"}),r=t("<button/>",{type:"button",class:"imagelightbox-arrow imagelightbox-arrow-right"}),l=a.add(r),c=t("<div/>",{id:"imagelightbox-caption"}),u=t("<a/>",{id:"imagelightbox-close"}),d=t("<div/>",{id:"imagelightbox-overlay"}),f=t("<div/>",{id:"imagelightbox-nav"}),g=t("<div/>",{id:"imagelightbox-wrapper"}),s=function(){var t=i.body||i.documentElement;return t=t.style,""===t.WebkitTransition?"-webkit-":""===t.MozTransition?"-moz-":""===t.OTransition?"-o-":""===t.transition&&""},p=s()!==!1,h=function(t,n,i){var e={},o=s();e[o+"transform"]="translateX("+n+")",e[o+"transition"]=o+"transform "+i+"s linear",t.css(e)},v="ontouchstart"in n,b=n.navigator.pointerEnabled||n.navigator.msPointerEnabled,m=function(t){if(v)return!0;if(!b||"undefined"==typeof t||"undefined"==typeof t.pointerType)return!1;if("undefined"!=typeof t.MSPOINTER_TYPE_MOUSE){if(t.MSPOINTER_TYPE_MOUSE!==t.pointerType)return!0}else if("mouse"!==t.pointerType)return!0;return!1};t.fn.imageLightbox=function(e){var a=t.extend({selector:"a[data-imagelightbox]",id:"imagelightbox",allowedTypes:"png|jpg|jpeg||gif",animationSpeed:250,activity:!1,arrows:!1,button:!1,caption:!1,enableKeyboard:!0,lockBody:!1,navigation:!1,overlay:!1,preloadNext:!0,quitOnEnd:!1,quitOnImgClick:!1,quitOnDocClick:!0,quitOnEscKey:!0,onStart:function(){a.arrows&&q(this),a.navigation&&T(this,a.selector),a.overlay&&y(),a.button&&E(),a.lockBody&&x(!0)},onEnd:function(){g.remove().find("*").remove(),a.lockBody&&x(!1)},onLoadStart:function(){a.activity&&r(),a.caption&&S()},onLoadEnd:function(){a.activity&&s(),a.arrows&&l.css("display","block"),a.navigation&&w(a.selector),a.caption&&k()},previousTarget:function(){return this.previousTargetDefault()},previousTargetDefault:function(){var t=O.index(C)-1;if(t<0){if(a.quitOnEnd===!0)return z(),!1;t=O.length-1}C=O.eq(t)},nextTarget:function(){return this.nextTargetDefault()},nextTargetDefault:function(){var t=O.index(C)+1;if(t>=O.length){if(a.quitOnEnd===!0)return z(),!1;t=0}C=O.eq(t)}},e),r=function(){g.append(o)},s=function(){t("#imagelightbox-loading").remove()},x=function(n){n?t("body").css("overflow","hidden"):t("body").css("overflow","scroll")},y=function(){g.append(d)},E=function(){u.appendTo(g).on("click.ilb7",function(){return z(),!1})},k=function(){var n="";t(C).data("ilb2-caption")?n=t(C).data("ilb2-caption"):t(C).find("img").length&&(n=t(C).find("img").attr("alt")),n&&n.length>0&&g.append(c.text(n))},S=function(){c.html(" ")},T=function(n,i){var e=t(i);if(e.length){for(var o=0;o<e.length;o++)f.append(t("<a/>",{href:"#"}));g.append(f),f.on("click.ilb7 touchend.ilb7",function(){return!1});var a=f.find("a");a.on("click.ilb7 touchend.ilb7",function(){var n=t(this);if(e.eq(n.index()).attr("href")!==t("#imagelightbox").attr("src")){var i=O.eq(n.index());if(i.length){var o=O.index(C);C=i,N(n.index()<o?"left":"right")}}return a.removeClass("active"),a.eq(n.index()).addClass("active"),!1}).on("touchend.ilb7",function(){return!1})}},w=function(n){var i=f.find("a");i.removeClass("active"),i.eq(t(n).filter('[href="'+t("#imagelightbox").attr("src")+'"]').index(n)).addClass("active")},q=function(){g.append(l),l.on("click.ilb7 touchend.ilb7",function(n){return n.preventDefault(),t(this).hasClass("imagelightbox-arrow-left")?K():U(),!1})},O=t([]),C=t(),I=t(),D=0,L=0,M=0,P=!1,X=function(){if(!I.length)return!0;var i=.8*t(n).width(),e=n.innerHeight?n.innerHeight:t(n).height(),o=.9*e,a=new Image;a.src=I.attr("src"),a.onload=function(){if(D=a.width,L=a.height,D>i||L>o){var r=D/L>i/o?D/i:L/o;D/=r,L/=r}I.css({width:D+"px",height:L+"px",top:(e-L)/2+"px",left:(t(n).width()-D)/2+"px"})}},N=function(n){if(P)return!1;if(n="undefined"!=typeof n&&("left"===n?1:-1),I.length){var i={opacity:0};p?h(I,100*n-M+"px",a.animationSpeed/1e3):i.left=parseInt(I.css("left"))+100*n+"px",I.animate(i,a.animationSpeed,function(){_()}),M=0}P=!0,a.onLoadStart!==!1&&a.onLoadStart(),setTimeout(function(){var i=C.attr("href");I=t('<img id="'+a.id+'" />').attr("src",i).on("load.ilb7",function(){var i={opacity:1};if(I.appendTo(g),X(),I.css("opacity",0),p)h(I,-100*n+"px",0),setTimeout(function(){h(I,"0px",a.animationSpeed/1e3)},50);else{var e=parseInt(I.css("left"));i.left=e+"px",I.css("left",e-100*n+"px")}if(I.animate(i,a.animationSpeed,function(){P=!1,a.onLoadEnd!==!1&&a.onLoadEnd()}),a.preloadNext){var o=O.eq(O.index(C)+1);o.length||(o=O.eq(0)),t("<img />").attr("src",o.attr("href"))}}).on("error.ilb7",function(){a.onLoadEnd!==!1&&a.onLoadEnd()});var e=0,o=0,r=0;I.on(b?"pointerup.ilb7 MSPointerUp.ilb7":"click.ilb7",function(t){if(t.preventDefault(),a.quitOnImgClick)return z(),!1;if(m(t.originalEvent))return!0;var n=(t.pageX||t.originalEvent.pageX)-t.target.offsetLeft;D/2>n?K():U()}).on("touchstart.ilb7 pointerdown.ilb7 MSPointerDown.ilb7",function(t){return!(m(t.originalEvent)&&!a.quitOnImgClick)||(p&&(r=parseInt(I.css("left"))),void(e=t.originalEvent.pageX||t.originalEvent.touches[0].pageX))}).on("touchmove.ilb7 pointermove.ilb7 MSPointerMove.ilb7",function(t){return!(m(t.originalEvent)&&!a.quitOnImgClick)||(t.preventDefault(),o=t.originalEvent.pageX||t.originalEvent.touches[0].pageX,M=e-o,void(p?h(I,-M+"px",0):I.css("left",r-M+"px")))}).on("touchend.ilb7 touchcancel.ilb7 pointerup.ilb7 pointercancel.ilb7 MSPointerUp.ilb7 MSPointerCancel.ilb7",function(t){return!(m(t.originalEvent)&&!a.quitOnImgClick)||void(Math.abs(M)>50?M<0?K():U():p?h(I,"0px",a.animationSpeed/1e3):I.animate({left:r+"px"},a.animationSpeed/2))})},a.animationSpeed+100)},K=function(){a.previousTarget()!==!1&&N("left")},U=function(){a.nextTarget()!==!1&&N("right")},_=function(){return!!I.length&&(I.remove(),void(I=t()))},j=function(n){return!P&&(P=!1,a.onStart!==!1&&a.onStart(),t("body").append(g),C=n,void N())},z=function(){return!!I.length&&void I.animate({opacity:0},a.animationSpeed,function(){_(),P=!1,a.onEnd!==!1&&a.onEnd()})},B=function(n){n.each(function(){O=O.add(t(this))}),n.on("click.ilb7",function(n){n.preventDefault(),j(t(this))})};return this.startImageLightbox=function(){this.length>0&&j(t(this[0]))},t(n).on("resize.ilb7",X),t(i).ready(function(){a.quitOnDocClick&&t(i).on(v?"touchend.ilb7":"click.ilb7",function(n){I.length&&!t(n.target).is(I)&&(n.preventDefault(),z())}),a.enableKeyboard&&t(i).on("keyup.ilb7",function(t){return!I.length||(t.preventDefault(),27===t.keyCode&&a.quitOnEscKey===!0&&z(),void(37===t.keyCode?K():39===t.keyCode&&U()))})}),t(i).off("click",this.selector),B(t(this)),this.loadPreviousImage=function(){K()},this.loadNextImage=function(){U()},this.quitImageLightbox=function(){return z(),this},this.addToImageLightbox=function(t){B(t)},this}}(jQuery,window,document); | ||
!function(t,i,n,e){"use strict";var o=t("<div/>").attr("id","imagelightbox-loading").append(t("<div/>")),a=t("<button/>",{type:"button",class:"imagelightbox-arrow imagelightbox-arrow-left"}),r=t("<button/>",{type:"button",class:"imagelightbox-arrow imagelightbox-arrow-right"}),l=a.add(r),c=t("<div/>",{id:"imagelightbox-caption"}),u=t("<a/>",{id:"imagelightbox-close"}),f=t("<div/>",{id:"imagelightbox-overlay"}),d=t("<a/>",{href:"#",class:"imagelightbox-navitem"}),s=t("<div/>",{id:"imagelightbox-nav"}),g=t("<div/>",{id:"imagelightbox-wrapper"}),h=function(){var t=n.body||n.documentElement;return t=t.style,""===t.WebkitTransition?"-webkit-":""===t.MozTransition?"-moz-":""===t.OTransition?"-o-":""===t.transition&&""},p=h()!==!1,v=function(t,i,n){var e={},o=h();e[o+"transform"]="translateX("+i+")",e[o+"transition"]=o+"transform "+n+"s linear",t.css(e)},b="ontouchstart"in i,m=i.navigator.pointerEnabled||i.navigator.msPointerEnabled,x=function(t){if(b)return!0;if(!m||"undefined"==typeof t||"undefined"==typeof t.pointerType)return!1;if("undefined"!=typeof t.MSPOINTER_TYPE_MOUSE){if(t.MSPOINTER_TYPE_MOUSE!==t.pointerType)return!0}else if("mouse"!==t.pointerType)return!0;return!1};t.fn.imageLightbox=function(e){var a=t.extend({selector:"a[data-imagelightbox]",id:"imagelightbox",allowedTypes:"png|jpg|jpeg|gif",animationSpeed:250,activity:!1,arrows:!1,button:!1,caption:!1,enableKeyboard:!0,lockBody:!1,navigation:!1,overlay:!1,preloadNext:!0,quitOnEnd:!1,quitOnImgClick:!1,quitOnDocClick:!0,quitOnEscKey:!0},e),r=function(){a.arrows&&X(this),a.navigation&&P(this,a.selector),a.overlay&&T(),a.button&&I(),a.lockBody&&S(!0)},h=function(){N=t([]),g.remove().find("*").remove(),a.lockBody&&S(!1)},y=function(){a.activity&&q(),a.caption&&M()},w=function(){a.activity&&O(),a.arrows&&l.css("display","block"),a.navigation&&D(a.selector),a.caption&&C()},k=function(){g.trigger("previous.ilb2");var t=N.index(j)-1;if(t<0){if(a.quitOnEnd===!0)return $(),!1;t=N.length-1}j=N.eq(t),Y("left")},E=function(){g.trigger("next.ilb2");var t=N.index(j)+1;if(t>=N.length){if(a.quitOnEnd===!0)return $(),!1;t=0}j=N.eq(t),Y("right")},q=function(){g.append(o)},O=function(){t("#imagelightbox-loading").remove()},S=function(i){i?t("body").css("overflow","hidden"):t("body").css("overflow","scroll")},T=function(){g.append(f)},I=function(){u.appendTo(g).on("click.ilb7",function(){return $(),!1})},C=function(){var i="";t(j).data("ilb2-caption")?i=t(j).data("ilb2-caption"):t(j).find("img").length&&(i=t(j).find("img").attr("alt")),i&&i.length>0&&g.append(c.text(i))},M=function(){c.html(" ")},P=function(){var i=N;if(i.length){for(var n=0;n<i.length;n++)s.append(d.clone());g.append(s),s.on("click.ilb7 touchend.ilb7",function(){return!1});var e=s.find("a");e.on("click.ilb7 touchend.ilb7",function(){var n=t(this);if(i.eq(n.index()).attr("href")!==t("#imagelightbox").attr("src")){var o=N.eq(n.index());if(o.length){var a=N.index(j);j=o,Y(n.index()<a?"left":"right")}}return e.removeClass("active"),e.eq(n.index()).addClass("active"),!1}).on("touchend.ilb7",function(){return!1})}},D=function(){var t=s.find("a");t.removeClass("active"),t.eq(N.index(j)).addClass("active")},X=function(){g.append(l),l.on("click.ilb7 touchend.ilb7",function(i){return i.preventDefault(),t(this).hasClass("imagelightbox-arrow-left")?k():E(),!1})},L="",N=t([]),j=t(),B=t(),K=0,U=0,_=0,z=!1,R=function(t){function i(t){var i,e,o,a=n.createElement("a"),r={};for(a.href=t,i=a.search.replace(/^\?/,"").split("&"),o=0;o<i.length;o++)e=i[o].split("="),r[e[0]]=e[1];return{protocol:a.protocol,host:a.host,hostname:a.hostname,port:a.port,pathname:a.pathname,search:a.search,searchObject:r,hash:a.hash}}var e=a.allowedTypes,o=/^(?!\|)[\w\|]+(?!\|)$/.test(e);if(!o)return!1;var r=t.attr("href"),l=i(r).pathname,c=new RegExp(e,"i"),u=c.test(l);return u},H=function(){if(!B.length)return!0;var n=.8*t(i).width(),e=i.innerHeight?i.innerHeight:t(i).height(),o=.9*e,a=new Image;a.src=B.attr("src"),a.onload=function(){if(K=a.width,U=a.height,K>n||U>o){var r=K/U>n/o?K/n:U/o;K/=r,U/=r}B.css({width:K+"px",height:U+"px",top:(e-U)/2+"px",left:(t(i).width()-K)/2+"px"})}},Y=function(i){if(z)return!1;if(i="undefined"!=typeof i&&("left"===i?1:-1),B.length){var n={opacity:0};p?v(B,100*i-_+"px",a.animationSpeed/1e3):n.left=parseInt(B.css("left"))+100*i+"px",B.animate(n,a.animationSpeed,function(){Q()}),_=0}z=!0,y(),setTimeout(function(){var n=j.attr("href");B=t('<img id="'+a.id+'" />').attr("src",n).on("load.ilb7",function(){var n={opacity:1};if(B.appendTo(g),H(),B.css("opacity",0),p)v(B,-100*i+"px",0),setTimeout(function(){v(B,"0px",a.animationSpeed/1e3)},50);else{var e=parseInt(B.css("left"));n.left=e+"px",B.css("left",e-100*i+"px")}if(B.animate(n,a.animationSpeed,function(){z=!1,w()}),a.preloadNext){var o=N.eq(N.index(j)+1);o.length||(o=N.eq(0)),t("<img />").attr("src",o.attr("href"))}}).on("error.ilb7",function(){w()});var e=0,o=0,r=0;B.on(m?"pointerup.ilb7 MSPointerUp.ilb7":"click.ilb7",function(t){if(t.preventDefault(),a.quitOnImgClick)return $(),!1;if(x(t.originalEvent))return!0;var i=(t.pageX||t.originalEvent.pageX)-t.target.offsetLeft;K/2>i?k():E()}).on("touchstart.ilb7 pointerdown.ilb7 MSPointerDown.ilb7",function(t){return!(x(t.originalEvent)&&!a.quitOnImgClick)||(p&&(r=parseInt(B.css("left"))),void(e=t.originalEvent.pageX||t.originalEvent.touches[0].pageX))}).on("touchmove.ilb7 pointermove.ilb7 MSPointerMove.ilb7",function(t){return!(x(t.originalEvent)&&!a.quitOnImgClick)||(t.preventDefault(),o=t.originalEvent.pageX||t.originalEvent.touches[0].pageX,_=e-o,void(p?v(B,-_+"px",0):B.css("left",r-_+"px")))}).on("touchend.ilb7 touchcancel.ilb7 pointerup.ilb7 pointercancel.ilb7 MSPointerUp.ilb7 MSPointerCancel.ilb7",function(t){return!(x(t.originalEvent)&&!a.quitOnImgClick)||void(Math.abs(_)>50?_<0?k():E():p?v(B,"0px",a.animationSpeed/1e3):B.animate({left:r+"px"},a.animationSpeed/2))})},a.animationSpeed+100)},Q=function(){return!!B.length&&(B.remove(),void(B=t()))},W=function(i){return!z&&(z=!1,r(),t("body").append(g),g.trigger("start.ilb2"),j=i,void Y())},$=function(){return g.trigger("quit.ilb2"),!!B.length&&void B.animate({opacity:0},a.animationSpeed,function(){Q(),z=!1,h()})},A=function(i){function n(){i.filter(function(){return t(this).data("imagelightbox")===L}).filter(function(){return R(t(this))}).each(function(){N=N.add(t(this))})}i.on("click.ilb7",{set:L},function(i){i.preventDefault(),L=t(i.currentTarget).data("imagelightbox"),n(),W(t(this))})};return t(i).on("resize.ilb7",H),t(n).ready(function(){a.quitOnDocClick&&t(n).on(b?"touchend.ilb7":"click.ilb7",function(i){B.length&&!t(i.target).is(B)&&(i.preventDefault(),$())}),a.lockBody&&t(n).on("keydown.ilb7",function(t){return!B.length||([9,32,38,40].indexOf(t.which)>-1?(t.preventDefault(),!1):void 0)}),a.enableKeyboard&&t(n).on("keyup.ilb7",function(t){return!B.length||(t.preventDefault(),[27].indexOf(t.which)>-1&&a.quitOnEscKey&&$(),void([37].indexOf(t.which)>-1?k():[39].indexOf(t.which)>-1&&E()))})}),t(n).off("click",this.selector),A(t(this)),this.addToImageLightbox=function(t){A(t)},this.loadPreviousImage=function(){k()},this.loadNextImage=function(){E()},this.quitImageLightbox=function(){return $(),this},this.startImageLightbox=function(){t(this).trigger("click.ilb7")},this}}(jQuery,window,document); |
@@ -27,2 +27,5 @@ // | ||
}), | ||
$navItem = $('<a/>', { | ||
href:'#',class:"imagelightbox-navitem" | ||
}), | ||
$navObject = $('<div/>', { | ||
@@ -89,3 +92,3 @@ id: 'imagelightbox-nav' | ||
id: 'imagelightbox', | ||
allowedTypes: 'png|jpg|jpeg||gif', // TODO make it work again | ||
allowedTypes: 'png|jpg|jpeg|gif', // TODO make it work again | ||
animationSpeed: 250, | ||
@@ -104,81 +107,80 @@ activity: false, | ||
quitOnDocClick: true, | ||
quitOnEscKey: true, | ||
onStart: function () { | ||
if (options.arrows) { | ||
arrowsOn(this); | ||
quitOnEscKey: true | ||
}, opts), | ||
_onStart = function () { | ||
if (options.arrows) { | ||
arrowsOn(this); | ||
} | ||
if (options.navigation) { | ||
navigationOn(this, options.selector); | ||
} | ||
if (options.overlay) { | ||
overlayOn(); | ||
} | ||
if (options.button) { | ||
closeButtonOn(); | ||
} | ||
if (options.lockBody) { | ||
lockBody(true); | ||
} | ||
}, | ||
_onEnd = function () { | ||
targets = $([]); | ||
$wrapper.remove().find("*").remove(); | ||
if (options.lockBody) { | ||
lockBody(false); | ||
} | ||
}, | ||
_onLoadStart = function () { | ||
if (options.activity) { | ||
activityIndicatorOn(); | ||
} | ||
if (options.caption) { | ||
captionOff(); | ||
} | ||
}, | ||
_onLoadEnd = function () { | ||
if (options.activity) { | ||
activityIndicatorOff(); | ||
} | ||
if (options.arrows) { | ||
$arrows.css('display', 'block'); | ||
} | ||
if (options.navigation) { | ||
navigationUpdate(options.selector); | ||
} | ||
if (options.caption) { | ||
captionOn(); | ||
} | ||
}, | ||
_previousTarget = function () { | ||
$wrapper.trigger("previous.ilb2"); | ||
var targetIndex = targets.index(target) - 1; | ||
if (targetIndex < 0) { | ||
if (options.quitOnEnd === true) { | ||
_quitImageLightbox(); | ||
return false; | ||
} | ||
if (options.navigation) { | ||
navigationOn(this, options.selector); | ||
else { | ||
targetIndex = targets.length - 1; | ||
} | ||
if (options.overlay) { | ||
overlayOn(); | ||
} | ||
target = targets.eq(targetIndex); | ||
_loadImage("left"); | ||
}, | ||
_nextTarget = function () { | ||
$wrapper.trigger("next.ilb2"); | ||
var targetIndex = targets.index(target) + 1; | ||
if (targetIndex >= targets.length) { | ||
if (options.quitOnEnd === true) { | ||
_quitImageLightbox(); | ||
return false; | ||
} | ||
if (options.button) { | ||
closeButtonOn(); | ||
else { | ||
targetIndex = 0; | ||
} | ||
if (options.lockBody) { | ||
lockBody(true); | ||
} | ||
}, | ||
onEnd: function () { | ||
$wrapper.remove().find("*").remove(); | ||
if (options.lockBody) { | ||
lockBody(false); | ||
} | ||
}, | ||
onLoadStart: function () { | ||
if (options.activity) { | ||
activityIndicatorOn(); | ||
} | ||
if (options.caption) { | ||
captionOff(); | ||
} | ||
}, | ||
onLoadEnd: function () { | ||
if (options.activity) { | ||
activityIndicatorOff(); | ||
} | ||
if (options.arrows) { | ||
$arrows.css('display', 'block'); | ||
} | ||
if (options.navigation) { | ||
navigationUpdate(options.selector); | ||
} | ||
if (options.caption) { | ||
captionOn(); | ||
} | ||
}, | ||
previousTarget: function () { | ||
return this.previousTargetDefault(); | ||
}, | ||
previousTargetDefault: function () { | ||
var targetIndex = targets.index(target) - 1; | ||
if (targetIndex < 0) { | ||
if (options.quitOnEnd === true) { | ||
_quitImageLightbox(); | ||
return false; | ||
} | ||
else { | ||
targetIndex = targets.length - 1; | ||
} | ||
} | ||
target = targets.eq(targetIndex); | ||
}, | ||
nextTarget: function () { | ||
return this.nextTargetDefault(); | ||
}, | ||
nextTargetDefault: function () { | ||
var targetIndex = targets.index(target) + 1; | ||
if (targetIndex >= targets.length) { | ||
if (options.quitOnEnd === true) { | ||
_quitImageLightbox(); | ||
return false; | ||
} | ||
else { | ||
targetIndex = 0; | ||
} | ||
} | ||
target = targets.eq(targetIndex); | ||
} | ||
}, opts), | ||
target = targets.eq(targetIndex); | ||
_loadImage("right"); | ||
}, | ||
activityIndicatorOn = function () { | ||
@@ -220,7 +222,7 @@ $wrapper.append($activityObject); | ||
}, | ||
navigationOn = function (instance, selector) { | ||
var images = $(selector); | ||
navigationOn = function () { | ||
var images = targets; | ||
if (images.length) { | ||
for (var i = 0; i < images.length; i++) { | ||
$navObject.append($('<a/>',{href:'#'})); | ||
$navObject.append($navItem.clone()); | ||
} | ||
@@ -250,6 +252,6 @@ $wrapper.append($navObject); | ||
}, | ||
navigationUpdate = function (selector) { | ||
navigationUpdate = function () { | ||
var items = $navObject.find('a'); | ||
items.removeClass('active'); | ||
items.eq($(selector).filter('[href="' + $('#imagelightbox').attr('src') + '"]').index(selector)).addClass('active'); | ||
items.eq(targets.index(target)).addClass('active'); | ||
}, | ||
@@ -261,5 +263,5 @@ arrowsOn = function () { | ||
if ($(this).hasClass('imagelightbox-arrow-left')) { | ||
_loadPreviousImage(); | ||
_previousTarget(); | ||
} else { | ||
_loadNextImage(); | ||
_nextTarget(); | ||
} | ||
@@ -269,3 +271,3 @@ return false; | ||
}, | ||
targetSet = "", | ||
targets = $([]), | ||
@@ -279,2 +281,44 @@ target = $(), | ||
isTargetValid = function (validImage) { | ||
var allowedTypes = options.allowedTypes; | ||
//test that RegExp is restricted to disjunction format | ||
var isGoodRE = /^(?!\|)[\w\|]+(?!\|)$/.test(allowedTypes); | ||
// | ||
if (!isGoodRE) { | ||
//allowedTypes = 'png|jpg|jpeg|gif'; | ||
return false; | ||
} | ||
// | ||
var URL = validImage.attr("href"); | ||
var ext = parseURL(URL).pathname; | ||
var re = new RegExp(allowedTypes,"i"); | ||
// | ||
var isAllowed = re.test(ext); | ||
// function by Cory LaViska | ||
function parseURL(url) { | ||
var parser = document.createElement('a'), | ||
searchObject = {}, | ||
queries, split, i; | ||
// Let the browser do the work | ||
parser.href = url; | ||
// Convert query string to object | ||
queries = parser.search.replace(/^\?/, '').split('&'); | ||
for( i = 0; i < queries.length; i++ ) { | ||
split = queries[i].split('='); | ||
searchObject[split[0]] = split[1]; | ||
} | ||
return { | ||
protocol: parser.protocol, | ||
host: parser.host, | ||
hostname: parser.hostname, | ||
port: parser.port, | ||
pathname: parser.pathname, | ||
search: parser.search, | ||
searchObject: searchObject, | ||
hash: parser.hash | ||
}; | ||
} | ||
return isAllowed; | ||
}, | ||
// TODO make it work again | ||
@@ -339,5 +383,3 @@ // isTargetValid = function (element) { | ||
inProgress = true; | ||
if (options.onLoadStart !== false) { | ||
options.onLoadStart(); | ||
} | ||
_onLoadStart(); | ||
@@ -370,5 +412,3 @@ setTimeout(function () { | ||
inProgress = false; | ||
if (options.onLoadEnd !== false) { | ||
options.onLoadEnd(); | ||
} | ||
_onLoadEnd(); | ||
}); | ||
@@ -384,5 +424,3 @@ if (options.preloadNext) { | ||
.on('error.ilb7', function () { | ||
if (options.onLoadEnd !== false) { | ||
options.onLoadEnd(); | ||
} | ||
_onLoadEnd(); | ||
}); | ||
@@ -405,5 +443,5 @@ | ||
if (imageWidth / 2 > posX) { | ||
_loadPreviousImage(); | ||
_previousTarget(); | ||
} else { | ||
_loadNextImage(); | ||
_nextTarget(); | ||
} | ||
@@ -439,5 +477,5 @@ }) | ||
if (swipeDiff < 0) { | ||
_loadPreviousImage(); | ||
_previousTarget(); | ||
} else { | ||
_loadNextImage(); | ||
_nextTarget(); | ||
} | ||
@@ -455,15 +493,2 @@ } else { | ||
}, | ||
_loadPreviousImage = function () { | ||
if (options.previousTarget() !== false) { | ||
_loadImage('left'); | ||
} | ||
}, | ||
_loadNextImage = function () { | ||
if (options.nextTarget() !== false) { | ||
_loadImage('right'); | ||
} | ||
}, | ||
_removeImage = function () { | ||
@@ -482,6 +507,5 @@ if (!image.length) { | ||
inProgress = false; | ||
if (options.onStart !== false) { | ||
options.onStart(); | ||
} | ||
_onStart(); | ||
$('body').append($wrapper); | ||
$wrapper.trigger("start.ilb2"); | ||
target = $target; | ||
@@ -492,2 +516,3 @@ _loadImage(); | ||
_quitImageLightbox = function () { | ||
$wrapper.trigger("quit.ilb2"); | ||
if (!image.length) { | ||
@@ -499,5 +524,3 @@ return false; | ||
inProgress = false; | ||
if (options.onEnd !== false) { | ||
options.onEnd(); | ||
} | ||
_onEnd(); | ||
}); | ||
@@ -507,18 +530,22 @@ }, | ||
_addTargets = function( newTargets ) { | ||
newTargets.each(function () { | ||
targets = targets.add($(this)); | ||
}); | ||
newTargets.on('click.ilb7', function (e) { | ||
newTargets.on('click.ilb7', {set: targetSet}, function (e) { | ||
e.preventDefault(); | ||
targetSet = $(e.currentTarget).data("imagelightbox"); | ||
filterTargets(); | ||
_openImageLightbox($(this)); | ||
}); | ||
function filterTargets () { | ||
newTargets | ||
.filter(function () { | ||
return $(this).data("imagelightbox") === targetSet; | ||
}) | ||
.filter(function () { | ||
return isTargetValid($(this)); | ||
}) | ||
.each(function () { | ||
targets = targets.add($(this)); | ||
}); | ||
} | ||
}; | ||
this.startImageLightbox = function () { | ||
if (this.length > 0) { | ||
_openImageLightbox($(this[0])); | ||
} | ||
}; | ||
$(window).on('resize.ilb7', _setImage); | ||
@@ -536,2 +563,14 @@ | ||
if (options.lockBody) { | ||
$(document).on('keydown.ilb7', function (e) { | ||
if (!image.length) { | ||
return true; | ||
} | ||
if([9,32,38,40].indexOf(e.which) > -1) { | ||
e.preventDefault(); | ||
return false; | ||
} | ||
}); | ||
} | ||
if (options.enableKeyboard) { | ||
@@ -543,9 +582,9 @@ $(document).on('keyup.ilb7', function (e) { | ||
e.preventDefault(); | ||
if (e.keyCode === 27 && options.quitOnEscKey === true) { | ||
if ([27].indexOf(e.which) > -1 && options.quitOnEscKey) { | ||
_quitImageLightbox(); | ||
} | ||
if (e.keyCode === 37) { | ||
_loadPreviousImage(); | ||
} else if (e.keyCode === 39) { | ||
_loadNextImage(); | ||
if ([37].indexOf(e.which) > -1) { | ||
_previousTarget(); | ||
} else if ([39].indexOf(e.which) > -1) { | ||
_nextTarget(); | ||
} | ||
@@ -560,8 +599,12 @@ }); | ||
this.addToImageLightbox = function(elements) { | ||
_addTargets(elements); | ||
}; | ||
this.loadPreviousImage = function () { | ||
_loadPreviousImage(); | ||
_previousTarget(); | ||
}; | ||
this.loadNextImage = function () { | ||
_loadNextImage(); | ||
_nextTarget(); | ||
}; | ||
@@ -574,4 +617,4 @@ | ||
this.addToImageLightbox = function(elements) { | ||
_addTargets(elements); | ||
this.startImageLightbox = function () { | ||
$(this).trigger('click.ilb7'); | ||
}; | ||
@@ -578,0 +621,0 @@ |
@@ -39,13 +39,17 @@ $(document).ready(function() { | ||
var gallery = $('a[data-imagelightbox="h"]').imageLightbox(); | ||
$('.trigger-button').on('click', function () { | ||
var gallery = $('a[data-imagelightbox="h"]').imageLightbox({ | ||
arrows: true | ||
}); | ||
$('.trigger-lightbox').on('click', function () { | ||
gallery.startImageLightbox(); | ||
}); | ||
var instanceI = $('a[data-imagelightbox="i"]').imageLightbox(); | ||
$("#addimage").on('click', function(){ | ||
var instanceI = $('a[data-imagelightbox="i"]').imageLightbox({ | ||
arrows: true | ||
}); | ||
$(".add-image").on('click', function(){ | ||
var adding_ul = $("#dynamically_adding"); | ||
var li = $('<li></li>').appendTo( adding_ul ); | ||
var a = $("<a></a>") | ||
.attr('data-imagelightbox',"add") | ||
.attr('data-imagelightbox',"i") | ||
.attr('href', "images/demo4.jpg") | ||
@@ -57,3 +61,3 @@ .appendTo( li ); | ||
// dynamically adding | ||
instanceI.addToImageLightbox( $("a[data-imagelightbox='add']") ); | ||
instanceI.addToImageLightbox( $("a[data-imagelightbox='i']") ); | ||
}); | ||
@@ -64,2 +68,17 @@ | ||
}); | ||
$('a[data-imagelightbox="k"]').imageLightbox(); | ||
$(document) | ||
.on("start.ilb2", function () { | ||
console.log("start.ilb2"); | ||
}) | ||
.on("quit.ilb2", function () { | ||
console.log("quit.ilb2"); | ||
}) | ||
.on("previous.ilb2", function () { | ||
console.log("previous.ilb2"); | ||
}) | ||
.on("next.ilb2", function () { | ||
console.log("next.ilb2"); | ||
}); | ||
}); |
@@ -6,2 +6,3 @@ var gulp = require('gulp'), | ||
lintspaces = require("gulp-lintspaces"), | ||
nightwatch = require('gulp-nightwatch'), | ||
rename = require('gulp-rename'), | ||
@@ -72,2 +73,17 @@ uglify = require('gulp-uglify'), | ||
gulp.task('night:js', ['serve'], function () { | ||
return gulp.src('') | ||
.pipe(nightwatch({ | ||
configFile: './nightwatch.json' | ||
})) | ||
.on('error', function(){ | ||
connect.serverClose(); | ||
process.exit(); | ||
}) | ||
.on('end', function(){ | ||
connect.serverClose(); | ||
process.exit(); | ||
}); | ||
}); | ||
gulp.task('build', ['minify:css', 'minify:js']); | ||
@@ -77,1 +93,2 @@ | ||
gulp.task('test', ['night:js']); |
{ | ||
"name": "imagelightbox", | ||
"version": "0.5.4", | ||
"version": "0.6.0", | ||
"description": "Image Lightbox, Responsive and Touch‑friendly", | ||
@@ -11,12 +11,13 @@ "repository": "https://github.com/rejas/imagelightbox.git", | ||
"gulp-autoprefixer": "^3.1.1", | ||
"gulp-clean-css": "^2.0.13", | ||
"gulp-clean-css": "^2.2.1", | ||
"gulp-connect": "^5.0.0", | ||
"gulp-csslint": "^1.0.0", | ||
"gulp-jshint": "^2.0.1", | ||
"gulp-jshint": "^2.0.4", | ||
"gulp-lintspaces": "^0.5.0", | ||
"gulp-nightwatch": "^0.3.2", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-uglify": "^2.0.0", | ||
"jshint": "^2.9.3", | ||
"jshint": "^2.9.4", | ||
"jshint-stylish": "^2.2.1" | ||
} | ||
} |
@@ -54,7 +54,3 @@ imagelightbox | ||
quitOnDocClick: true, // bool; quit when anything but the viewed image is clicked | ||
quitOnEscKey: true, // bool; quit when Esc key is pressed | ||
onStart: false, // function/bool; calls function when the lightbox starts | ||
onEnd: false, // function/bool; calls function when the lightbox quits | ||
onLoadStart: false, // function/bool; calls function when the image load begins | ||
onLoadEnd: false // function/bool; calls function when the image finishes loading | ||
quitOnEscKey: true // bool; quit when Esc key is pressed | ||
}); | ||
@@ -90,3 +86,55 @@ ```` | ||
```` | ||
## Hooks | ||
Image Lightbox now triggers unique events upon start, finish, and when either the next or previous image is requested. | ||
These events are, respectively, "start.ilb2", "quit.ilb2", "next.ilb2", and "previous.ilb2". | ||
Usage example: | ||
````javascript | ||
$(document) | ||
.on("start.ilb2", function () { | ||
console.log("Image Lightbox has started."); | ||
}) | ||
.on("next.ilb2", function () { | ||
console.log("Next image"); | ||
}) | ||
.on("previous.ilb2", function () { | ||
console.log("Previous image"); | ||
}) | ||
.on("quit.ilb2", function () { | ||
console.log("Image Lightbox has quit."); | ||
}); | ||
```` | ||
## Using multiple sets | ||
As of commit bf2b4db, imageLightbox supports "sets." | ||
A set is defined by the links with a common value for the "data-imagelightbox" attribute. | ||
For example: | ||
````html | ||
<a data-imagelightbox="a" | ||
href="image_1.jpg"> | ||
<img src="thumbnail_1.jpg" alt="caption"/> | ||
</a> | ||
<a data-imagelightbox="a" | ||
href="image_2.jpg"> | ||
<img src="thumbnail_2.jpg" alt="caption"/> | ||
</a> | ||
<a data-imagelightbox="b" | ||
href="image_3.jpg"> | ||
<img src="thumbnail_3.jpg" alt="caption"/> | ||
</a> | ||
<a data-imagelightbox="b" | ||
href="image_4.jpg"> | ||
<img src="thumbnail_4.jpg" alt="caption"/> | ||
</a> | ||
```` | ||
When the user clicks any of the thumbnails with a data-imagelightbox value of "a", only those images will appear in the lightbox. The same is true when clicking an image with data-imagelightbox value of "b" and any other. | ||
In order to "capture" all possible sets on a give webpage, it is necessary to apply imageLightbox to "a[data-imagelightbox]"; that is, without specifying a particular data-imagelightbox attribute value. | ||
## Adding images dynamically to lightbox | ||
@@ -113,2 +161,3 @@ | ||
* 0.6.0 Replaced onStart/onEnd/onLoadStart/onLoadEnd with event hooks (@Paxperscientiam), added ui-tests | ||
* 0.5.4 Add ilb2-caption option (@Paxperscientiam) | ||
@@ -115,0 +164,0 @@ * 0.5.3 Add lockBody option (@Paxperscientiam) |
@@ -27,2 +27,5 @@ // | ||
}), | ||
$navItem = $('<a/>', { | ||
href:'#',class:"imagelightbox-navitem" | ||
}), | ||
$navObject = $('<div/>', { | ||
@@ -89,3 +92,3 @@ id: 'imagelightbox-nav' | ||
id: 'imagelightbox', | ||
allowedTypes: 'png|jpg|jpeg||gif', // TODO make it work again | ||
allowedTypes: 'png|jpg|jpeg|gif', // TODO make it work again | ||
animationSpeed: 250, | ||
@@ -104,81 +107,80 @@ activity: false, | ||
quitOnDocClick: true, | ||
quitOnEscKey: true, | ||
onStart: function () { | ||
if (options.arrows) { | ||
arrowsOn(this); | ||
quitOnEscKey: true | ||
}, opts), | ||
_onStart = function () { | ||
if (options.arrows) { | ||
arrowsOn(this); | ||
} | ||
if (options.navigation) { | ||
navigationOn(this, options.selector); | ||
} | ||
if (options.overlay) { | ||
overlayOn(); | ||
} | ||
if (options.button) { | ||
closeButtonOn(); | ||
} | ||
if (options.lockBody) { | ||
lockBody(true); | ||
} | ||
}, | ||
_onEnd = function () { | ||
targets = $([]); | ||
$wrapper.remove().find("*").remove(); | ||
if (options.lockBody) { | ||
lockBody(false); | ||
} | ||
}, | ||
_onLoadStart = function () { | ||
if (options.activity) { | ||
activityIndicatorOn(); | ||
} | ||
if (options.caption) { | ||
captionOff(); | ||
} | ||
}, | ||
_onLoadEnd = function () { | ||
if (options.activity) { | ||
activityIndicatorOff(); | ||
} | ||
if (options.arrows) { | ||
$arrows.css('display', 'block'); | ||
} | ||
if (options.navigation) { | ||
navigationUpdate(options.selector); | ||
} | ||
if (options.caption) { | ||
captionOn(); | ||
} | ||
}, | ||
_previousTarget = function () { | ||
$wrapper.trigger("previous.ilb2"); | ||
var targetIndex = targets.index(target) - 1; | ||
if (targetIndex < 0) { | ||
if (options.quitOnEnd === true) { | ||
_quitImageLightbox(); | ||
return false; | ||
} | ||
if (options.navigation) { | ||
navigationOn(this, options.selector); | ||
else { | ||
targetIndex = targets.length - 1; | ||
} | ||
if (options.overlay) { | ||
overlayOn(); | ||
} | ||
target = targets.eq(targetIndex); | ||
_loadImage("left"); | ||
}, | ||
_nextTarget = function () { | ||
$wrapper.trigger("next.ilb2"); | ||
var targetIndex = targets.index(target) + 1; | ||
if (targetIndex >= targets.length) { | ||
if (options.quitOnEnd === true) { | ||
_quitImageLightbox(); | ||
return false; | ||
} | ||
if (options.button) { | ||
closeButtonOn(); | ||
else { | ||
targetIndex = 0; | ||
} | ||
if (options.lockBody) { | ||
lockBody(true); | ||
} | ||
}, | ||
onEnd: function () { | ||
$wrapper.remove().find("*").remove(); | ||
if (options.lockBody) { | ||
lockBody(false); | ||
} | ||
}, | ||
onLoadStart: function () { | ||
if (options.activity) { | ||
activityIndicatorOn(); | ||
} | ||
if (options.caption) { | ||
captionOff(); | ||
} | ||
}, | ||
onLoadEnd: function () { | ||
if (options.activity) { | ||
activityIndicatorOff(); | ||
} | ||
if (options.arrows) { | ||
$arrows.css('display', 'block'); | ||
} | ||
if (options.navigation) { | ||
navigationUpdate(options.selector); | ||
} | ||
if (options.caption) { | ||
captionOn(); | ||
} | ||
}, | ||
previousTarget: function () { | ||
return this.previousTargetDefault(); | ||
}, | ||
previousTargetDefault: function () { | ||
var targetIndex = targets.index(target) - 1; | ||
if (targetIndex < 0) { | ||
if (options.quitOnEnd === true) { | ||
_quitImageLightbox(); | ||
return false; | ||
} | ||
else { | ||
targetIndex = targets.length - 1; | ||
} | ||
} | ||
target = targets.eq(targetIndex); | ||
}, | ||
nextTarget: function () { | ||
return this.nextTargetDefault(); | ||
}, | ||
nextTargetDefault: function () { | ||
var targetIndex = targets.index(target) + 1; | ||
if (targetIndex >= targets.length) { | ||
if (options.quitOnEnd === true) { | ||
_quitImageLightbox(); | ||
return false; | ||
} | ||
else { | ||
targetIndex = 0; | ||
} | ||
} | ||
target = targets.eq(targetIndex); | ||
} | ||
}, opts), | ||
target = targets.eq(targetIndex); | ||
_loadImage("right"); | ||
}, | ||
activityIndicatorOn = function () { | ||
@@ -220,7 +222,7 @@ $wrapper.append($activityObject); | ||
}, | ||
navigationOn = function (instance, selector) { | ||
var images = $(selector); | ||
navigationOn = function () { | ||
var images = targets; | ||
if (images.length) { | ||
for (var i = 0; i < images.length; i++) { | ||
$navObject.append($('<a/>',{href:'#'})); | ||
$navObject.append($navItem.clone()); | ||
} | ||
@@ -250,6 +252,6 @@ $wrapper.append($navObject); | ||
}, | ||
navigationUpdate = function (selector) { | ||
navigationUpdate = function () { | ||
var items = $navObject.find('a'); | ||
items.removeClass('active'); | ||
items.eq($(selector).filter('[href="' + $('#imagelightbox').attr('src') + '"]').index(selector)).addClass('active'); | ||
items.eq(targets.index(target)).addClass('active'); | ||
}, | ||
@@ -261,5 +263,5 @@ arrowsOn = function () { | ||
if ($(this).hasClass('imagelightbox-arrow-left')) { | ||
_loadPreviousImage(); | ||
_previousTarget(); | ||
} else { | ||
_loadNextImage(); | ||
_nextTarget(); | ||
} | ||
@@ -269,3 +271,3 @@ return false; | ||
}, | ||
targetSet = "", | ||
targets = $([]), | ||
@@ -279,2 +281,44 @@ target = $(), | ||
isTargetValid = function (validImage) { | ||
var allowedTypes = options.allowedTypes; | ||
//test that RegExp is restricted to disjunction format | ||
var isGoodRE = /^(?!\|)[\w\|]+(?!\|)$/.test(allowedTypes); | ||
// | ||
if (!isGoodRE) { | ||
//allowedTypes = 'png|jpg|jpeg|gif'; | ||
return false; | ||
} | ||
// | ||
var URL = validImage.attr("href"); | ||
var ext = parseURL(URL).pathname; | ||
var re = new RegExp(allowedTypes,"i"); | ||
// | ||
var isAllowed = re.test(ext); | ||
// function by Cory LaViska | ||
function parseURL(url) { | ||
var parser = document.createElement('a'), | ||
searchObject = {}, | ||
queries, split, i; | ||
// Let the browser do the work | ||
parser.href = url; | ||
// Convert query string to object | ||
queries = parser.search.replace(/^\?/, '').split('&'); | ||
for( i = 0; i < queries.length; i++ ) { | ||
split = queries[i].split('='); | ||
searchObject[split[0]] = split[1]; | ||
} | ||
return { | ||
protocol: parser.protocol, | ||
host: parser.host, | ||
hostname: parser.hostname, | ||
port: parser.port, | ||
pathname: parser.pathname, | ||
search: parser.search, | ||
searchObject: searchObject, | ||
hash: parser.hash | ||
}; | ||
} | ||
return isAllowed; | ||
}, | ||
// TODO make it work again | ||
@@ -339,5 +383,3 @@ // isTargetValid = function (element) { | ||
inProgress = true; | ||
if (options.onLoadStart !== false) { | ||
options.onLoadStart(); | ||
} | ||
_onLoadStart(); | ||
@@ -370,5 +412,3 @@ setTimeout(function () { | ||
inProgress = false; | ||
if (options.onLoadEnd !== false) { | ||
options.onLoadEnd(); | ||
} | ||
_onLoadEnd(); | ||
}); | ||
@@ -384,5 +424,3 @@ if (options.preloadNext) { | ||
.on('error.ilb7', function () { | ||
if (options.onLoadEnd !== false) { | ||
options.onLoadEnd(); | ||
} | ||
_onLoadEnd(); | ||
}); | ||
@@ -405,5 +443,5 @@ | ||
if (imageWidth / 2 > posX) { | ||
_loadPreviousImage(); | ||
_previousTarget(); | ||
} else { | ||
_loadNextImage(); | ||
_nextTarget(); | ||
} | ||
@@ -439,5 +477,5 @@ }) | ||
if (swipeDiff < 0) { | ||
_loadPreviousImage(); | ||
_previousTarget(); | ||
} else { | ||
_loadNextImage(); | ||
_nextTarget(); | ||
} | ||
@@ -455,15 +493,2 @@ } else { | ||
}, | ||
_loadPreviousImage = function () { | ||
if (options.previousTarget() !== false) { | ||
_loadImage('left'); | ||
} | ||
}, | ||
_loadNextImage = function () { | ||
if (options.nextTarget() !== false) { | ||
_loadImage('right'); | ||
} | ||
}, | ||
_removeImage = function () { | ||
@@ -482,6 +507,5 @@ if (!image.length) { | ||
inProgress = false; | ||
if (options.onStart !== false) { | ||
options.onStart(); | ||
} | ||
_onStart(); | ||
$('body').append($wrapper); | ||
$wrapper.trigger("start.ilb2"); | ||
target = $target; | ||
@@ -492,2 +516,3 @@ _loadImage(); | ||
_quitImageLightbox = function () { | ||
$wrapper.trigger("quit.ilb2"); | ||
if (!image.length) { | ||
@@ -499,5 +524,3 @@ return false; | ||
inProgress = false; | ||
if (options.onEnd !== false) { | ||
options.onEnd(); | ||
} | ||
_onEnd(); | ||
}); | ||
@@ -507,18 +530,22 @@ }, | ||
_addTargets = function( newTargets ) { | ||
newTargets.each(function () { | ||
targets = targets.add($(this)); | ||
}); | ||
newTargets.on('click.ilb7', function (e) { | ||
newTargets.on('click.ilb7', {set: targetSet}, function (e) { | ||
e.preventDefault(); | ||
targetSet = $(e.currentTarget).data("imagelightbox"); | ||
filterTargets(); | ||
_openImageLightbox($(this)); | ||
}); | ||
function filterTargets () { | ||
newTargets | ||
.filter(function () { | ||
return $(this).data("imagelightbox") === targetSet; | ||
}) | ||
.filter(function () { | ||
return isTargetValid($(this)); | ||
}) | ||
.each(function () { | ||
targets = targets.add($(this)); | ||
}); | ||
} | ||
}; | ||
this.startImageLightbox = function () { | ||
if (this.length > 0) { | ||
_openImageLightbox($(this[0])); | ||
} | ||
}; | ||
$(window).on('resize.ilb7', _setImage); | ||
@@ -536,2 +563,14 @@ | ||
if (options.lockBody) { | ||
$(document).on('keydown.ilb7', function (e) { | ||
if (!image.length) { | ||
return true; | ||
} | ||
if([9,32,38,40].indexOf(e.which) > -1) { | ||
e.preventDefault(); | ||
return false; | ||
} | ||
}); | ||
} | ||
if (options.enableKeyboard) { | ||
@@ -543,9 +582,9 @@ $(document).on('keyup.ilb7', function (e) { | ||
e.preventDefault(); | ||
if (e.keyCode === 27 && options.quitOnEscKey === true) { | ||
if ([27].indexOf(e.which) > -1 && options.quitOnEscKey) { | ||
_quitImageLightbox(); | ||
} | ||
if (e.keyCode === 37) { | ||
_loadPreviousImage(); | ||
} else if (e.keyCode === 39) { | ||
_loadNextImage(); | ||
if ([37].indexOf(e.which) > -1) { | ||
_previousTarget(); | ||
} else if ([39].indexOf(e.which) > -1) { | ||
_nextTarget(); | ||
} | ||
@@ -560,8 +599,12 @@ }); | ||
this.addToImageLightbox = function(elements) { | ||
_addTargets(elements); | ||
}; | ||
this.loadPreviousImage = function () { | ||
_loadPreviousImage(); | ||
_previousTarget(); | ||
}; | ||
this.loadNextImage = function () { | ||
_loadNextImage(); | ||
_nextTarget(); | ||
}; | ||
@@ -574,4 +617,4 @@ | ||
this.addToImageLightbox = function(elements) { | ||
_addTargets(elements); | ||
this.startImageLightbox = function () { | ||
$(this).trigger('click.ilb7'); | ||
}; | ||
@@ -578,0 +621,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
36386623
166
27973
165
12
2