simplelightbox
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -20,2 +20,3 @@ | ||
captions: true, | ||
captionsData: 'title', | ||
close: true, | ||
@@ -153,3 +154,3 @@ closeText: 'X', | ||
var captionText = $(selector).eq(index).find('img').prop('title'); | ||
var captionText = (options.captionsData == 'data-title') ? $(selector).eq(index).find('img').data('title') : $(selector).eq(index).find('img').prop(options.captionsData); | ||
if(dir == 1 || dir == -1){ | ||
@@ -177,3 +178,3 @@ var css = { 'opacity': 1.0 }; | ||
if(captiontext != '' && options.captions){ | ||
caption.text(captiontext).hide().appendTo($('.sl-image')).fadeIn('fast'); | ||
caption.html(captiontext).hide().appendTo($('.sl-image')).fadeIn('fast'); | ||
} | ||
@@ -180,0 +181,0 @@ }, |
@@ -5,2 +5,2 @@ /* | ||
*/ | ||
!function(e,t,n){"use strict";e.fn.simpleLightbox=function(a){var a=e.extend({overlay:!0,spinner:!0,nav:!0,navText:["←","→"],captions:!0,close:!0,closeText:"X",showCounter:!0,fileExt:"png|jpg|jpeg|gif",animationSpeed:250,preloading:!0,enableKeyboard:!0,loop:!0,docClose:!0,swipeTolerance:50,className:"simple-lightbox",widthRatio:.8,heightRatio:.9},a),i=(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(),p=s!==!1?!0:!1,c="simplelb",d=e("<div>").addClass("sl-overlay"),u=e("<button>").addClass("sl-close").html(a.closeText),g=e("<div>").addClass("sl-spinner").html("<div></div>"),f=e("<div>").addClass("sl-navigation").html('<button class="sl-prev">'+a.navText[0]+'</button><button class="sl-next">'+a.navText[1]+"</button>"),h=e("<div>").addClass("sl-counter").html('<span class="sl-current"></span>/<span class="sl-total"></span>'),m=!1,v=0,x=e(),w=e("<div>").addClass("sl-caption"),b=function(t){return"a"==e(t).prop("tagName").toLowerCase()&&new RegExp(".("+a.fileExt+")$","i").test(e(t).attr("href"))},T=function(){a.overlay&&d.appendTo(e("body")),e("<div>").addClass("sl-wrapper").addClass(a.className).html('<div class="sl-image"></div>').appendTo("body"),x=e(".sl-image"),a.close&&u.appendTo(e(".sl-wrapper")),a.showCounter&&e(r).length>1&&(h.appendTo(e(".sl-wrapper")),e(".sl-wrapper .sl-counter .sl-total").text(e(r).length)),a.nav&&f.appendTo(e(".sl-wrapper")),a.spinner&&g.appendTo(e(".sl-wrapper"))},y=function(t){t.trigger(e.Event("show.simplelightbox")),m=!0,v=e(r).index(t),o=e("<img/>").hide().attr("src",t.attr("href")),e(".sl-image").html(""),o.appendTo(e(".sl-image")),d.fadeIn("fast"),e(".sl-close").fadeIn("fast"),g.show(),f.fadeIn("fast"),e(".sl-wrapper .sl-counter .sl-current").text(v+1),h.fadeIn("fast"),C(),a.preloading&&S(),setTimeout(function(){t.trigger(e.Event("shown.simplelightbox"))},a.animationSpeed)},C=function(n){if(o.length){var i=new Image,s=e(t).width()*a.widthRatio,c=e(t).height()*a.heightRatio;i.src=o.attr("src"),i.onload=function(){var d=i.width,u=i.height;if(d>s||u>c){var f=d/u>s/c?d/s:u/c;d/=f,u/=f}e(".sl-image").css({top:(e(t).height()-u)/2+"px",left:(e(t).width()-d)/2+"px"}),g.hide(),o.css({width:d+"px",height:u+"px"}).fadeIn("fast"),l=!0;var h=e(r).eq(v).find("img").prop("title");if(1==n||-1==n){var x={opacity:1};p?(k(0,100*n+"px"),setTimeout(function(){k(a.animationSpeed/1e3,"0px"),50})):x.left=parseInt(e(".sl-image").css("left"))+100*n+"px",e(".sl-image").animate(x,a.animationSpeed,function(){m=!1,E(h)})}else m=!1,E(h)}}},E=function(t){""!=t&&a.captions&&w.text(t).hide().appendTo(e(".sl-image")).fadeIn("fast")},k=function(t,n){var a={};a[s+"transform"]="translateX("+n+")",a[s+"transition"]=s+"transform "+t+"s linear",e(".sl-image").css(a)},S=function(){var t=0>v+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("<img />").attr("src",e(r).eq(t).attr("href")).load(),e("<img />").attr("src",e(r).eq(n).attr("href")).load()},I=function(t){g.show();var n=v+t;if(!(m||(0>n||n>=e(r).length)&&0==a.loop)){m=!0,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};p?k(a.animationSpeed/1e3,-100*t-i+"px"):s.left=parseInt(e(".sl-image").css("left"))+-100*t+"px",e(".sl-image").animate(s,a.animationSpeed,function(){setTimeout(function(){var n=e(r).eq(v);o.attr("src",n.attr("href")),e(".sl-caption").remove(),C(t),a.preloading&&S()},100)})}},M=function(){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(){n||t.trigger(e.Event("closed.simplelightbox")),n=!0}),o=e(),l=!1};T(),e(t).on("resize",C),e(n).on("click."+c,this.selector,function(t){if(b(this)){if(t.preventDefault(),m)return!1;y(e(this))}}),e(n).on("click",".sl-close",function(e){e.preventDefault(),l&&M()}),e(n).click(function(t){l&&a.docClose&&0==e(t.target).closest(".sl-image").length&&0==e(t.target).closest(".sl-navigation").length&&M()}),e(n).on("click",".sl-navigation button",function(t){t.preventDefault(),i=0,I(e(this).hasClass("sl-next")?1:-1)}),a.enableKeyboard&&e(n).on("keyup."+c,function(e){if(e.preventDefault(),i=0,l){var t=e.keyCode;27==t&&M(),(37==t||39==e.keyCode)&&I(39==e.keyCode?1:-1)}});var D=0,X=0,q=!1,P=0;return e(n).on("touchstart mousedown pointerdown MSPointerDown",".sl-image",function(e){return q?!0:(p&&(P=parseInt(x.css("left"))),q=!0,void(D=e.originalEvent.pageX||e.originalEvent.touches[0].pageX))}).on("touchmove mousemove pointermove MSPointerMove",".sl-image",function(e){return q?(e.preventDefault(),X=e.originalEvent.pageX||e.originalEvent.touches[0].pageX,i=D-X,void(p?k(0,-i+"px"):x.css("left",P-i+"px"))):!0}).on("touchend mouseup touchcancel pointerup pointercancel MSPointerUp MSPointerCancel",".sl-image",function(){q=!1,Math.abs(i)>a.swipeTolerance?I(i>0?1:-1):p?k(a.animationSpeed/1e3,"0px"):x.animate({left:P+"px"},a.animationSpeed/2)}),this.open=function(e){y(e)},this.next=function(){I(1)},this.prev=function(){I(-1)},this.close=function(){M()},this.destroy=function(){e(n).unbind("click."+c).unbind("keyup."+c),M(),e(".sl-overlay, .sl-wrapper").remove()},this}}(jQuery,window,document); | ||
!function(e,t,n){"use strict";e.fn.simpleLightbox=function(a){var a=e.extend({overlay:!0,spinner:!0,nav:!0,navText:["←","→"],captions:!0,captionsData:"title",close:!0,closeText:"X",showCounter:!0,fileExt:"png|jpg|jpeg|gif",animationSpeed:250,preloading:!0,enableKeyboard:!0,loop:!0,docClose:!0,swipeTolerance:50,className:"simple-lightbox",widthRatio:.8,heightRatio:.9},a),i=(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(),p=s!==!1?!0:!1,c="simplelb",d=e("<div>").addClass("sl-overlay"),u=e("<button>").addClass("sl-close").html(a.closeText),g=e("<div>").addClass("sl-spinner").html("<div></div>"),f=e("<div>").addClass("sl-navigation").html('<button class="sl-prev">'+a.navText[0]+'</button><button class="sl-next">'+a.navText[1]+"</button>"),h=e("<div>").addClass("sl-counter").html('<span class="sl-current"></span>/<span class="sl-total"></span>'),m=!1,v=0,x=e(),w=e("<div>").addClass("sl-caption"),b=function(t){return"a"==e(t).prop("tagName").toLowerCase()&&new RegExp(".("+a.fileExt+")$","i").test(e(t).attr("href"))},T=function(){a.overlay&&d.appendTo(e("body")),e("<div>").addClass("sl-wrapper").addClass(a.className).html('<div class="sl-image"></div>').appendTo("body"),x=e(".sl-image"),a.close&&u.appendTo(e(".sl-wrapper")),a.showCounter&&e(r).length>1&&(h.appendTo(e(".sl-wrapper")),e(".sl-wrapper .sl-counter .sl-total").text(e(r).length)),a.nav&&f.appendTo(e(".sl-wrapper")),a.spinner&&g.appendTo(e(".sl-wrapper"))},y=function(t){t.trigger(e.Event("show.simplelightbox")),m=!0,v=e(r).index(t),o=e("<img/>").hide().attr("src",t.attr("href")),e(".sl-image").html(""),o.appendTo(e(".sl-image")),d.fadeIn("fast"),e(".sl-close").fadeIn("fast"),g.show(),f.fadeIn("fast"),e(".sl-wrapper .sl-counter .sl-current").text(v+1),h.fadeIn("fast"),C(),a.preloading&&S(),setTimeout(function(){t.trigger(e.Event("shown.simplelightbox"))},a.animationSpeed)},C=function(n){if(o.length){var i=new Image,s=e(t).width()*a.widthRatio,c=e(t).height()*a.heightRatio;i.src=o.attr("src"),i.onload=function(){var d=i.width,u=i.height;if(d>s||u>c){var f=d/u>s/c?d/s:u/c;d/=f,u/=f}e(".sl-image").css({top:(e(t).height()-u)/2+"px",left:(e(t).width()-d)/2+"px"}),g.hide(),o.css({width:d+"px",height:u+"px"}).fadeIn("fast"),l=!0;var h="data-title"==a.captionsData?e(r).eq(v).find("img").data("title"):e(r).eq(v).find("img").prop(a.captionsData);if(1==n||-1==n){var x={opacity:1};p?(k(0,100*n+"px"),setTimeout(function(){k(a.animationSpeed/1e3,"0px"),50})):x.left=parseInt(e(".sl-image").css("left"))+100*n+"px",e(".sl-image").animate(x,a.animationSpeed,function(){m=!1,E(h)})}else m=!1,E(h)}}},E=function(t){""!=t&&a.captions&&w.html(t).hide().appendTo(e(".sl-image")).fadeIn("fast")},k=function(t,n){var a={};a[s+"transform"]="translateX("+n+")",a[s+"transition"]=s+"transform "+t+"s linear",e(".sl-image").css(a)},S=function(){var t=0>v+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("<img />").attr("src",e(r).eq(t).attr("href")).load(),e("<img />").attr("src",e(r).eq(n).attr("href")).load()},I=function(t){g.show();var n=v+t;if(!(m||(0>n||n>=e(r).length)&&0==a.loop)){m=!0,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};p?k(a.animationSpeed/1e3,-100*t-i+"px"):s.left=parseInt(e(".sl-image").css("left"))+-100*t+"px",e(".sl-image").animate(s,a.animationSpeed,function(){setTimeout(function(){var n=e(r).eq(v);o.attr("src",n.attr("href")),e(".sl-caption").remove(),C(t),a.preloading&&S()},100)})}},D=function(){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(){n||t.trigger(e.Event("closed.simplelightbox")),n=!0}),o=e(),l=!1};T(),e(t).on("resize",C),e(n).on("click."+c,this.selector,function(t){if(b(this)){if(t.preventDefault(),m)return!1;y(e(this))}}),e(n).on("click",".sl-close",function(e){e.preventDefault(),l&&D()}),e(n).click(function(t){l&&a.docClose&&0==e(t.target).closest(".sl-image").length&&0==e(t.target).closest(".sl-navigation").length&&D()}),e(n).on("click",".sl-navigation button",function(t){t.preventDefault(),i=0,I(e(this).hasClass("sl-next")?1:-1)}),a.enableKeyboard&&e(n).on("keyup."+c,function(e){if(e.preventDefault(),i=0,l){var t=e.keyCode;27==t&&D(),(37==t||39==e.keyCode)&&I(39==e.keyCode?1:-1)}});var M=0,q=0,X=!1,P=0;return e(n).on("touchstart mousedown pointerdown MSPointerDown",".sl-image",function(e){return X?!0:(p&&(P=parseInt(x.css("left"))),X=!0,void(M=e.originalEvent.pageX||e.originalEvent.touches[0].pageX))}).on("touchmove mousemove pointermove MSPointerMove",".sl-image",function(e){return X?(e.preventDefault(),q=e.originalEvent.pageX||e.originalEvent.touches[0].pageX,i=M-q,void(p?k(0,-i+"px"):x.css("left",P-i+"px"))):!0}).on("touchend mouseup touchcancel pointerup pointercancel MSPointerUp MSPointerCancel",".sl-image",function(){X=!1,Math.abs(i)>a.swipeTolerance?I(i>0?1:-1):p?k(a.animationSpeed/1e3,"0px"):x.animate({left:P+"px"},a.animationSpeed/2)}),this.open=function(e){y(e)},this.next=function(){I(1)},this.prev=function(){I(-1)},this.close=function(){D()},this.destroy=function(){e(n).unbind("click."+c).unbind("keyup."+c),D(),e(".sl-overlay, .sl-wrapper").remove()},this}}(jQuery,window,document); |
{ | ||
"name": "simplelightbox", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "Touch-friendly image lightbox for mobile and desktop with jQuery", | ||
@@ -5,0 +5,0 @@ "main": "dist/simple-lightbox.js", |
@@ -6,3 +6,7 @@ # simplelightbox | ||
```sh | ||
//Bower | ||
bower install simplelightbox | ||
//NPM | ||
npm install simplelightbox | ||
``` | ||
@@ -24,3 +28,3 @@ | ||
| captions | true | bool | show captions if availabled or not | | ||
| captionsData | title | string | get the caption from title or data-title attribute | | ||
| captionsData | title | string | get the caption from given attribute or data-title | | ||
| close | true | bool | show the close button or not | | ||
@@ -71,2 +75,3 @@ | closeText | 'X' | string | text or html for the close button | | ||
### Changelog | ||
**1.4.0 - Caption Attribute can now be what, you want, or data-title. Fixed some small issues** | ||
**1.3.1 - Bugfix: disable keyboard control if lightbox is closed** | ||
@@ -73,0 +78,0 @@ **1.3.0 - Added current index indicator/counter** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7308262
596
80