Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simplelightbox

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simplelightbox - npm Package Compare versions

Comparing version 1.7.2 to 1.8.0

2

bower.json
{
"name": "simplelightbox",
"version": "1.7.2",
"version": "1.8.0",
"homepage": "http://andreknieriem.de/simple-lightbox",

@@ -5,0 +5,0 @@ "authors": [

@@ -41,3 +41,4 @@

disableScroll: true,
alertError: true
alertError: true,
alertErrorMessage: 'Image not found, next image will be loaded'
}, options );

@@ -140,16 +141,25 @@

//no image was found
objects.eq(index).trigger($.Event('error.simplelightbox'))
animating = false;
opened = true;
spinner.hide();
if(options.alertError){
alert('Image not found, next image will be loaded');
alert(options.alertErrorMessage);
if(dir == 1 || dir == -1){
loadImage(dir);
} else {
loadImage(1);
}
return;
}
if(dir == 1 || dir == -1){
loadImage(dir);
} else {
loadImage(1);
}
return;
})
tmpImage.onload = function() {
if (typeof dir !== 'undefined') {
objects.eq(index)
.trigger($.Event('changed.simplelightbox'))
.trigger($.Event( (dir===1?'nextDone':'prevDone')+'.simplelightbox'));
}
var imageWidth = tmpImage.width,

@@ -230,7 +240,15 @@ imageHeight = tmpImage.height;

prev = (index-1 < 0) ? objects.length -1: (index-1 >= objects.length -1) ? 0 : index-1;
$( '<img />' ).attr( 'src', objects.eq(next).attr( 'href' ) ).load();
$( '<img />' ).attr( 'src', objects.eq(prev).attr( 'href' ) ).load();
$( '<img />' ).attr( 'src', objects.eq(next).attr( 'href' ) ).load(function(){
objects.eq(index).trigger($.Event('nextImageLoaded.simplelightbox'));
});
$( '<img />' ).attr( 'src', objects.eq(prev).attr( 'href' ) ).load(function(){
objects.eq(index).trigger($.Event('prevImageLoaded.simplelightbox'));
});
},
loadImage = function(dir){
objects.eq(index)
.trigger($.Event('change.simplelightbox'))
.trigger($.Event( (dir===1?'next':'prev')+'.simplelightbox'));
spinner.show();

@@ -402,2 +420,3 @@ var newIndex = index + dir;

this.open = function(elem){
elem = elem || $(this[0]);
openImage(elem);

@@ -404,0 +423,0 @@ }

@@ -5,2 +5,2 @@ /*

*/
!function(e,t,n,i){"use strict";e.fn.simpleLightbox=function(i){var i=e.extend({overlay:!0,spinner:!0,nav:!0,navText:["&lsaquo;","&rsaquo;"],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("<div>").addClass("sl-overlay"),h=e("<button>").addClass("sl-close").html(i.closeText),f=e("<div>").addClass("sl-spinner").html("<div></div>"),g=e("<div>").addClass("sl-navigation").html('<button class="sl-prev">'+i.navText[0]+'</button><button class="sl-next">'+i.navText[1]+"</button>"),u=e("<div>").addClass("sl-counter").html('<span class="sl-current"></span>/<span class="sl-total"></span>'),m=!1,v=0,b=e(),x=e("<div>").addClass("sl-caption pos-"+i.captionPosition),y=e("<div>").addClass("sl-wrapper").addClass(i.className).html('<div class="sl-image"></div>'),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("<img/>").hide().attr("src",t.attr("href")),e(".sl-image").html("").attr("style",""),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==n||-1==n?n: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&&v<r.length-1&&e(".sl-prev, .sl-next").show()),1==r.length&&e(".sl-prev, .sl-next").hide(),1==n||-1==n){var x={opacity:1};i.animationSlide&&(d?(k(0,100*n+"px"),setTimeout(function(){k(i.animationSpeed/1e3,"0px"),50})):x.left=parseInt(e(".sl-image").css("left"))+100*n+"px"),e(".sl-image").animate(x,i.animationSpeed,function(){m=!1,E(b)})}else m=!1,E(b)}}},E=function(t){""!=t&&"undefined"!=typeof t&&i.captions&&x.html(t).hide().appendTo(e(".sl-image")).delay(i.captionDelay).fadeIn("fast")},k=function(t,n){var i={};i[s+"transform"]="translateX("+n+")",i[s+"transition"]=s+"transform "+t+"s linear",e(".sl-image").css(i)},I=function(){var t=0>v+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("<img />").attr("src",r.eq(t).attr("href")).load(),e("<img />").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.clientWidth<a){var s=n.createElement("div"),l=parseInt(e("body").css("padding-right"),10);s.className="sl-scrollbar-measure",e("body").append(s);var r=s.offsetWidth-s.clientWidth;e(n.body)[0].removeChild(s),e("body").data("padding",l),r>0&&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);
!function(e,t,n,i){"use strict";e.fn.simpleLightbox=function(i){var i=e.extend({overlay:!0,spinner:!0,nav:!0,navText:["&lsaquo;","&rsaquo;"],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,alertErrorMessage:"Image not found, next image will be loaded"},i),a=(t.navigator.pointerEnabled||t.navigator.msPointerEnabled,0),o=e(),l=function(){var e=n.body||n.documentElement,e=e.style;return""==e.WebkitTransition?"-webkit-":""==e.MozTransition?"-moz-":""==e.OTransition?"-o-":""==e.transition?"":!1},s=!1,r=e(this.selector,this.context),l=l(),d=l!==!1?!0:!1,p="simplelb",c=e("<div>").addClass("sl-overlay"),g=e("<button>").addClass("sl-close").html(i.closeText),h=e("<div>").addClass("sl-spinner").html("<div></div>"),f=e("<div>").addClass("sl-navigation").html('<button class="sl-prev">'+i.navText[0]+'</button><button class="sl-next">'+i.navText[1]+"</button>"),u=e("<div>").addClass("sl-counter").html('<span class="sl-current"></span>/<span class="sl-total"></span>'),m=!1,v=0,x=e(),b=e("<div>").addClass("sl-caption pos-"+i.captionPosition),y=e("<div>").addClass("sl-wrapper").addClass(i.className).html('<div class="sl-image"></div>'),w=function(t){return i.fileExt?"a"==e(t).prop("tagName").toLowerCase()&&new RegExp(".("+i.fileExt+")$","i").test(e(t).attr("href")):!0},E=function(){x=e(".sl-image"),i.close&&g.appendTo(y),i.showCounter&&r.length>1&&(u.appendTo(y),u.find(".sl-total").text(r.length)),i.nav&&f.appendTo(y),i.spinner&&h.appendTo(y)},T=function(t){t.trigger(e.Event("show.simplelightbox")),i.disableScroll&&M("hide"),y.appendTo("body"),i.overlay&&c.appendTo(e("body")),m=!0,v=r.index(t),o=e("<img/>").hide().attr("src",t.attr("href")),e(".sl-image").html("").attr("style",""),o.appendTo(e(".sl-image")),c.fadeIn("fast"),e(".sl-close").fadeIn("fast"),h.show(),f.fadeIn("fast"),e(".sl-wrapper .sl-counter .sl-current").text(v+1),u.fadeIn("fast"),S(),i.preloading&&I(),setTimeout(function(){t.trigger(e.Event("shown.simplelightbox"))},i.animationSpeed)},S=function(n){if(o.length){var a=new Image,l=e(t).width()*i.widthRatio,p=e(t).height()*i.heightRatio;a.src=o.attr("src"),e(a).bind("error",function(t){return r.eq(v).trigger(e.Event("error.simplelightbox")),m=!1,s=!0,h.hide(),i.alertError?(alert(i.alertErrorMessage),void q(1==n||-1==n?n:1)):void 0}),a.onload=function(){"undefined"!=typeof n&&r.eq(v).trigger(e.Event("changed.simplelightbox")).trigger(e.Event((1===n?"nextDone":"prevDone")+".simplelightbox"));var c=a.width,g=a.height;if(c>l||g>p){var f=c/g>l/p?c/l:g/p;c/=f,g/=f}e(".sl-image").css({top:(e(t).height()-g)/2+"px",left:(e(t).width()-c)/2+"px"}),h.hide(),o.css({width:c+"px",height:g+"px"}).fadeIn("fast"),s=!0;var u="self"==i.captionSelector?r.eq(v):r.eq(v).find(i.captionSelector);if("data"==i.captionType)var x=u.data(i.captionsData);else if("text"==i.captionType)var x=u.html();else var x=u.prop(i.captionsData);if(i.loop||(0==v&&e(".sl-prev").hide(),v>=r.length-1&&e(".sl-next").hide(),v>0&&v<r.length-1&&e(".sl-prev, .sl-next").show()),1==r.length&&e(".sl-prev, .sl-next").hide(),1==n||-1==n){var b={opacity:1};i.animationSlide&&(d?(k(0,100*n+"px"),setTimeout(function(){k(i.animationSpeed/1e3,"0px"),50})):b.left=parseInt(e(".sl-image").css("left"))+100*n+"px"),e(".sl-image").animate(b,i.animationSpeed,function(){m=!1,C(x)})}else m=!1,C(x)}}},C=function(t){""!=t&&"undefined"!=typeof t&&i.captions&&b.html(t).hide().appendTo(e(".sl-image")).delay(i.captionDelay).fadeIn("fast")},k=function(t,n){var i={};i[l+"transform"]="translateX("+n+")",i[l+"transition"]=l+"transform "+t+"s linear",e(".sl-image").css(i)},I=function(){var t=0>v+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("<img />").attr("src",r.eq(t).attr("href")).load(function(){r.eq(v).trigger(e.Event("nextImageLoaded.simplelightbox"))}),e("<img />").attr("src",r.eq(n).attr("href")).load(function(){r.eq(v).trigger(e.Event("prevImageLoaded.simplelightbox"))})},q=function(t){r.eq(v).trigger(e.Event("change.simplelightbox")).trigger(e.Event((1===t?"next":"prev")+".simplelightbox")),h.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 l={opacity:0};i.animationSlide&&(d?k(i.animationSpeed/1e3,-100*t-a+"px"):l.left=parseInt(e(".sl-image").css("left"))+-100*t+"px"),e(".sl-image").animate(l,i.animationSpeed,function(){setTimeout(function(){var n=r.eq(v);o.attr("src",n.attr("href")),e(".sl-caption").remove(),S(t),i.preloading&&I()},100)})}},D=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(),s=!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.clientWidth<a){var l=n.createElement("div"),s=parseInt(e("body").css("padding-right"),10);l.className="sl-scrollbar-measure",e("body").append(l);var r=l.offsetWidth-l.clientWidth;e(n.body)[0].removeChild(l),e("body").data("padding",s),r>0&&e("body").css({"padding-right":s+r,overflow:"hidden"})}}else e("body").css({"padding-right":e("body").data("padding"),overflow:"auto"})};E(),e(t).on("resize",S),r.on("click."+p,function(t){if(w(this)){if(t.preventDefault(),m)return!1;T(e(this))}}),e(n).on("click",".sl-close",function(e){e.preventDefault(),s&&D()}),e(n).click(function(t){s&&i.docClose&&0==e(t.target).closest(".sl-image").length&&0==e(t.target).closest(".sl-navigation").length&&D()}),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,q(e(this).hasClass("sl-next")?1:-1)}),i.enableKeyboard&&e(n).on("keyup."+p,function(e){if(e.preventDefault(),a=0,s){var t=e.keyCode;27==t&&D(),(37==t||39==e.keyCode)&&q(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(x.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"):x.css("left",X-a+"px")))):!0}).on("touchend mouseup touchcancel pointerup pointercancel MSPointerUp MSPointerCancel",function(e){W&&(W=!1,Math.abs(a)>i.swipeTolerance?q(a>0?1:-1):i.animationSlide&&(d?k(i.animationSpeed/1e3,"0px"):x.animate({left:X+"px"},i.animationSpeed/2)))}),this.open=function(t){t=t||e(this[0]),T(t)},this.next=function(){q(1)},this.prev=function(){q(-1)},this.close=function(){D()},this.destroy=function(){e(n).unbind("click."+p).unbind("keyup."+p),D(),e(".sl-overlay, .sl-wrapper").remove()},this}}(jQuery,window,document);
{
"name": "simplelightbox",
"version": "1.7.2",
"version": "1.8.0",
"description": "Touch-friendly image lightbox for mobile and desktop with jQuery",

@@ -5,0 +5,0 @@ "main": "dist/simple-lightbox.js",

@@ -19,3 +19,3 @@ # simplelightbox

###Options
### Options
| Property | Default | Type | Description |

@@ -49,5 +49,6 @@ | -------- | ------- | ---- | ----------- |

| disableScroll | true | bool | stop scrolling page if lightbox is opened |
| alertError | true | bool | show an alert, if image was not found |
| alertError | true | bool | show an alert, if image was not found. If false error will be ignored |
| alertErrorMessage | 'Image not found, next image will be loaded' | string | the message displayed if image was not found |
###Events
### Events
| Name | Description |

@@ -59,4 +60,13 @@ | ---- | ----------- |

| closed.simplelightbox | this event fires after the lightbox was closed |
| change.simplelightbox | this event fires before image changes |
| changed.simplelightbox | this event fires after image was changed |
| next.simplelightbox | this event fires before next image arrives |
| nextDone.simplelightbox | this event fires after next image was arrived |
| prev.simplelightbox | this event fires before previous image arrives |
| prevDone.simplelightbox | this event fires after previous image was arrived |
| nextImageLoaded.simplelightbox | this event fires after next image was loaded (if preload activated) |
| prevImageLoaded.simplelightbox | this event fires after previous image was loaded (if preload activated) |
| error.simplelightbox | this event fires on image load error |
**Example**
**Example**
```javascript

@@ -66,5 +76,9 @@ $('.gallery a').on('open.simplelightbox', function () {

});
$('.gallery a').on('error.simplelightbox', function (e) {
console.log(e); // some usefull information
});
```
###Public Methods
### Public Methods
| Name | Description |

@@ -78,3 +92,3 @@ | ---- | ----------- |

**Example**
**Example**
```javascript

@@ -86,3 +100,3 @@ var gallery = $('.gallery a').simpleLightbox();

###Multiple Lightboxes on one page
### Multiple Lightboxes on one page
You can have multiple lightboxes on one page, if you give them different selectors. Here is a small example:

@@ -95,2 +109,3 @@ ```javascript

### Changelog
**1.8.0 - New API Events (changed open to show) and little fix in function open() brought by Geoffrey Crofte and some other small bugfixes**
**1.7.2 - Bugfix von #25 and #27**

@@ -115,2 +130,11 @@ **1.7.1 - Bugfix von #22 with new option alertError and merged pull request #23**

**1.1.0 - Added classname for lightbox wrapper and width/height ratio**
**1.0.0 - Initial Release**
**1.0.0 - Initial Release**
### Author
[Andre Rinas](http://andreknieriem.de/) - [Github](https://github.com/andreknieriem/)
### Contributors
[nicekiwi](https://github.com/nicekiwi)
[helloilya](https://github.com/helloilya)
[bitstarr](https://github.com/bitstarr)
[Geoffrey Crofte](http://geoffrey.crofte.fr/) - [Github](https://github.com/creativejuiz/)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc