Comparing version 2.8.2 to 2.9.0
/*! | ||
* Lightbox v2.8.1 | ||
* Lightbox v2.9.0 | ||
* by Lokesh Dhakar | ||
@@ -44,4 +44,5 @@ * | ||
alwaysShowNavOnTouchDevices: false, | ||
fadeDuration: 500, | ||
fadeDuration: 600, | ||
fitImagesInViewport: true, | ||
imageFadeDuration: 600, | ||
// maxWidth: 800, | ||
@@ -52,3 +53,13 @@ // maxHeight: 600, | ||
showImageNumberLabel: true, | ||
wrapAround: false | ||
wrapAround: false, | ||
disableScrolling: false, | ||
/* | ||
Sanitize Title | ||
If the caption data is trusted, for example you are hardcoding it in, then leave this to false. | ||
This will free you to add html tags, such as links, in the caption. | ||
If the caption data is user submitted or from some other untrusted source, then set this to true | ||
to prevent xss and other injection attacks. | ||
*/ | ||
sanitizeTitle: false | ||
}; | ||
@@ -65,4 +76,8 @@ | ||
Lightbox.prototype.init = function() { | ||
this.enable(); | ||
this.build(); | ||
var self = this; | ||
// Both enable and build methods require the body tag to be in the DOM. | ||
$(document).ready(function() { | ||
self.enable(); | ||
self.build(); | ||
}); | ||
}; | ||
@@ -91,9 +106,20 @@ | ||
this.$container = this.$lightbox.find('.lb-container'); | ||
this.$image = this.$lightbox.find('.lb-image'); | ||
this.$nav = this.$lightbox.find('.lb-nav'); | ||
// Store css values for future lookup | ||
this.containerTopPadding = parseInt(this.$container.css('padding-top'), 10); | ||
this.containerRightPadding = parseInt(this.$container.css('padding-right'), 10); | ||
this.containerBottomPadding = parseInt(this.$container.css('padding-bottom'), 10); | ||
this.containerLeftPadding = parseInt(this.$container.css('padding-left'), 10); | ||
this.containerPadding = { | ||
top: parseInt(this.$container.css('padding-top'), 10), | ||
right: parseInt(this.$container.css('padding-right'), 10), | ||
bottom: parseInt(this.$container.css('padding-bottom'), 10), | ||
left: parseInt(this.$container.css('padding-left'), 10) | ||
}; | ||
this.imageBorderWidth = { | ||
top: parseInt(this.$image.css('border-top-width'), 10), | ||
right: parseInt(this.$image.css('border-right-width'), 10), | ||
bottom: parseInt(this.$image.css('border-bottom-width'), 10), | ||
left: parseInt(this.$image.css('border-left-width'), 10) | ||
}; | ||
// Attach event handlers to the newly minted DOM elements | ||
@@ -137,2 +163,28 @@ this.$overlay.hide().on('click', function() { | ||
/* | ||
Show context menu for image on right-click | ||
There is a div containing the navigation that spans the entire image and lives above of it. If | ||
you right-click, you are right clicking this div and not the image. This prevents users from | ||
saving the image or using other context menu actions with the image. | ||
To fix this, when we detect the right mouse button is pressed down, but not yet clicked, we | ||
set pointer-events to none on the nav div. This is so that the upcoming right-click event on | ||
the next mouseup will bubble down to the image. Once the right-click/contextmenu event occurs | ||
we set the pointer events back to auto for the nav div so it can capture hover and left-click | ||
events as usual. | ||
*/ | ||
this.$nav.on('mousedown', function(event) { | ||
if (event.which === 3) { | ||
self.$nav.css('pointer-events', 'none'); | ||
self.$lightbox.one('contextmenu', function() { | ||
setTimeout(function() { | ||
this.$nav.css('pointer-events', 'auto'); | ||
}.bind(self), 0); | ||
}); | ||
} | ||
}); | ||
this.$lightbox.find('.lb-loader, .lb-close').on('click', function() { | ||
@@ -203,2 +255,7 @@ self.end(); | ||
// Disable scrolling of the page while open | ||
if (this.options.disableScrolling) { | ||
$('body').addClass('lb-disable-scrolling'); | ||
} | ||
this.changeImage(imageNumber); | ||
@@ -245,4 +302,4 @@ }; | ||
windowHeight = $(window).height(); | ||
maxImageWidth = windowWidth - self.containerLeftPadding - self.containerRightPadding - 20; | ||
maxImageHeight = windowHeight - self.containerTopPadding - self.containerBottomPadding - 120; | ||
maxImageWidth = windowWidth - self.containerPadding.left - self.containerPadding.right - self.imageBorderWidth.left - self.imageBorderWidth.right - 20; | ||
maxImageHeight = windowHeight - self.containerPadding.top - self.containerPadding.bottom - self.imageBorderWidth.top - self.imageBorderWidth.bottom - 120; | ||
@@ -282,3 +339,3 @@ // Check if image size is larger then maxWidth|maxHeight in settings | ||
this.$overlay | ||
.width($(window).width()) | ||
.width($(document).width()) | ||
.height($(document).height()); | ||
@@ -293,4 +350,4 @@ }; | ||
var oldHeight = this.$outerContainer.outerHeight(); | ||
var newWidth = imageWidth + this.containerLeftPadding + this.containerRightPadding; | ||
var newHeight = imageHeight + this.containerTopPadding + this.containerBottomPadding; | ||
var newWidth = imageWidth + this.containerPadding.left + this.containerPadding.right + this.imageBorderWidth.left + this.imageBorderWidth.right; | ||
var newHeight = imageHeight + this.containerPadding.top + this.containerPadding.bottom + this.imageBorderWidth.top + this.imageBorderWidth.bottom; | ||
@@ -319,3 +376,3 @@ function postResize() { | ||
this.$lightbox.find('.lb-loader').stop(true).hide(); | ||
this.$lightbox.find('.lb-image').fadeIn('slow'); | ||
this.$lightbox.find('.lb-image').fadeIn(this.options.imageFadeDuration); | ||
@@ -372,5 +429,9 @@ this.updateNav(); | ||
this.album[this.currentImageIndex].title !== '') { | ||
this.$lightbox.find('.lb-caption') | ||
.html(this.album[this.currentImageIndex].title) | ||
.fadeIn('fast') | ||
var $caption = this.$lightbox.find('.lb-caption'); | ||
if (this.options.sanitizeTitle) { | ||
$caption.text(this.album[this.currentImageIndex].title); | ||
} else { | ||
$caption.html(this.album[this.currentImageIndex].title); | ||
} | ||
$caption.fadeIn('fast') | ||
.find('a').on('click', function(event) { | ||
@@ -452,2 +513,5 @@ if ($(this).attr('target') !== undefined) { | ||
}); | ||
if (this.options.disableScrolling) { | ||
$('body').removeClass('lb-disable-scrolling'); | ||
} | ||
}; | ||
@@ -454,0 +518,0 @@ |
/*! | ||
* Lightbox v2.8.1 | ||
* Lightbox v2.9.0 | ||
* by Lokesh Dhakar | ||
@@ -12,3 +12,3 @@ * | ||
*/ | ||
!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],b):"object"==typeof exports?module.exports=b(require("jquery")):a.lightbox=b(a.jQuery)}(this,function(a){function b(b){this.album=[],this.currentImageIndex=void 0,this.init(),this.options=a.extend({},this.constructor.defaults),this.option(b)}return b.defaults={albumLabel:"Image %1 of %2",alwaysShowNavOnTouchDevices:!1,fadeDuration:500,fitImagesInViewport:!0,positionFromTop:50,resizeDuration:700,showImageNumberLabel:!0,wrapAround:!1},b.prototype.option=function(b){a.extend(this.options,b)},b.prototype.imageCountLabel=function(a,b){return this.options.albumLabel.replace(/%1/g,a).replace(/%2/g,b)},b.prototype.init=function(){this.enable(),this.build()},b.prototype.enable=function(){var b=this;a("body").on("click","a[rel^=lightbox], area[rel^=lightbox], a[data-lightbox], area[data-lightbox]",function(c){return b.start(a(c.currentTarget)),!1})},b.prototype.build=function(){var b=this;a('<div id="lightboxOverlay" class="lightboxOverlay"></div><div id="lightbox" class="lightbox"><div class="lb-outerContainer"><div class="lb-container"><img class="lb-image" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" /><div class="lb-nav"><a class="lb-prev" href="" ></a><a class="lb-next" href="" ></a></div><div class="lb-loader"><a class="lb-cancel"></a></div></div></div><div class="lb-dataContainer"><div class="lb-data"><div class="lb-details"><span class="lb-caption"></span><span class="lb-number"></span></div><div class="lb-closeContainer"><a class="lb-close"></a></div></div></div></div>').appendTo(a("body")),this.$lightbox=a("#lightbox"),this.$overlay=a("#lightboxOverlay"),this.$outerContainer=this.$lightbox.find(".lb-outerContainer"),this.$container=this.$lightbox.find(".lb-container"),this.containerTopPadding=parseInt(this.$container.css("padding-top"),10),this.containerRightPadding=parseInt(this.$container.css("padding-right"),10),this.containerBottomPadding=parseInt(this.$container.css("padding-bottom"),10),this.containerLeftPadding=parseInt(this.$container.css("padding-left"),10),this.$overlay.hide().on("click",function(){return b.end(),!1}),this.$lightbox.hide().on("click",function(c){return"lightbox"===a(c.target).attr("id")&&b.end(),!1}),this.$outerContainer.on("click",function(c){return"lightbox"===a(c.target).attr("id")&&b.end(),!1}),this.$lightbox.find(".lb-prev").on("click",function(){return 0===b.currentImageIndex?b.changeImage(b.album.length-1):b.changeImage(b.currentImageIndex-1),!1}),this.$lightbox.find(".lb-next").on("click",function(){return b.currentImageIndex===b.album.length-1?b.changeImage(0):b.changeImage(b.currentImageIndex+1),!1}),this.$lightbox.find(".lb-loader, .lb-close").on("click",function(){return b.end(),!1})},b.prototype.start=function(b){function c(a){d.album.push({link:a.attr("href"),title:a.attr("data-title")||a.attr("title")})}var d=this,e=a(window);e.on("resize",a.proxy(this.sizeOverlay,this)),a("select, object, embed").css({visibility:"hidden"}),this.sizeOverlay(),this.album=[];var f,g=0,h=b.attr("data-lightbox");if(h){f=a(b.prop("tagName")+'[data-lightbox="'+h+'"]');for(var i=0;i<f.length;i=++i)c(a(f[i])),f[i]===b[0]&&(g=i)}else if("lightbox"===b.attr("rel"))c(b);else{f=a(b.prop("tagName")+'[rel="'+b.attr("rel")+'"]');for(var j=0;j<f.length;j=++j)c(a(f[j])),f[j]===b[0]&&(g=j)}var k=e.scrollTop()+this.options.positionFromTop,l=e.scrollLeft();this.$lightbox.css({top:k+"px",left:l+"px"}).fadeIn(this.options.fadeDuration),this.changeImage(g)},b.prototype.changeImage=function(b){var c=this;this.disableKeyboardNav();var d=this.$lightbox.find(".lb-image");this.$overlay.fadeIn(this.options.fadeDuration),a(".lb-loader").fadeIn("slow"),this.$lightbox.find(".lb-image, .lb-nav, .lb-prev, .lb-next, .lb-dataContainer, .lb-numbers, .lb-caption").hide(),this.$outerContainer.addClass("animating");var e=new Image;e.onload=function(){var f,g,h,i,j,k,l;d.attr("src",c.album[b].link),f=a(e),d.width(e.width),d.height(e.height),c.options.fitImagesInViewport&&(l=a(window).width(),k=a(window).height(),j=l-c.containerLeftPadding-c.containerRightPadding-20,i=k-c.containerTopPadding-c.containerBottomPadding-120,c.options.maxWidth&&c.options.maxWidth<j&&(j=c.options.maxWidth),c.options.maxHeight&&c.options.maxHeight<j&&(i=c.options.maxHeight),(e.width>j||e.height>i)&&(e.width/j>e.height/i?(h=j,g=parseInt(e.height/(e.width/h),10),d.width(h),d.height(g)):(g=i,h=parseInt(e.width/(e.height/g),10),d.width(h),d.height(g)))),c.sizeContainer(d.width(),d.height())},e.src=this.album[b].link,this.currentImageIndex=b},b.prototype.sizeOverlay=function(){this.$overlay.width(a(window).width()).height(a(document).height())},b.prototype.sizeContainer=function(a,b){function c(){d.$lightbox.find(".lb-dataContainer").width(g),d.$lightbox.find(".lb-prevLink").height(h),d.$lightbox.find(".lb-nextLink").height(h),d.showImage()}var d=this,e=this.$outerContainer.outerWidth(),f=this.$outerContainer.outerHeight(),g=a+this.containerLeftPadding+this.containerRightPadding,h=b+this.containerTopPadding+this.containerBottomPadding;e!==g||f!==h?this.$outerContainer.animate({width:g,height:h},this.options.resizeDuration,"swing",function(){c()}):c()},b.prototype.showImage=function(){this.$lightbox.find(".lb-loader").stop(!0).hide(),this.$lightbox.find(".lb-image").fadeIn("slow"),this.updateNav(),this.updateDetails(),this.preloadNeighboringImages(),this.enableKeyboardNav()},b.prototype.updateNav=function(){var a=!1;try{document.createEvent("TouchEvent"),a=this.options.alwaysShowNavOnTouchDevices?!0:!1}catch(b){}this.$lightbox.find(".lb-nav").show(),this.album.length>1&&(this.options.wrapAround?(a&&this.$lightbox.find(".lb-prev, .lb-next").css("opacity","1"),this.$lightbox.find(".lb-prev, .lb-next").show()):(this.currentImageIndex>0&&(this.$lightbox.find(".lb-prev").show(),a&&this.$lightbox.find(".lb-prev").css("opacity","1")),this.currentImageIndex<this.album.length-1&&(this.$lightbox.find(".lb-next").show(),a&&this.$lightbox.find(".lb-next").css("opacity","1"))))},b.prototype.updateDetails=function(){var b=this;if("undefined"!=typeof this.album[this.currentImageIndex].title&&""!==this.album[this.currentImageIndex].title&&this.$lightbox.find(".lb-caption").html(this.album[this.currentImageIndex].title).fadeIn("fast").find("a").on("click",function(b){void 0!==a(this).attr("target")?window.open(a(this).attr("href"),a(this).attr("target")):location.href=a(this).attr("href")}),this.album.length>1&&this.options.showImageNumberLabel){var c=this.imageCountLabel(this.currentImageIndex+1,this.album.length);this.$lightbox.find(".lb-number").text(c).fadeIn("fast")}else this.$lightbox.find(".lb-number").hide();this.$outerContainer.removeClass("animating"),this.$lightbox.find(".lb-dataContainer").fadeIn(this.options.resizeDuration,function(){return b.sizeOverlay()})},b.prototype.preloadNeighboringImages=function(){if(this.album.length>this.currentImageIndex+1){var a=new Image;a.src=this.album[this.currentImageIndex+1].link}if(this.currentImageIndex>0){var b=new Image;b.src=this.album[this.currentImageIndex-1].link}},b.prototype.enableKeyboardNav=function(){a(document).on("keyup.keyboard",a.proxy(this.keyboardAction,this))},b.prototype.disableKeyboardNav=function(){a(document).off(".keyboard")},b.prototype.keyboardAction=function(a){var b=27,c=37,d=39,e=a.keyCode,f=String.fromCharCode(e).toLowerCase();e===b||f.match(/x|o|c/)?this.end():"p"===f||e===c?0!==this.currentImageIndex?this.changeImage(this.currentImageIndex-1):this.options.wrapAround&&this.album.length>1&&this.changeImage(this.album.length-1):("n"===f||e===d)&&(this.currentImageIndex!==this.album.length-1?this.changeImage(this.currentImageIndex+1):this.options.wrapAround&&this.album.length>1&&this.changeImage(0))},b.prototype.end=function(){this.disableKeyboardNav(),a(window).off("resize",this.sizeOverlay),this.$lightbox.fadeOut(this.options.fadeDuration),this.$overlay.fadeOut(this.options.fadeDuration),a("select, object, embed").css({visibility:"visible"})},new b}); | ||
!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],b):"object"==typeof exports?module.exports=b(require("jquery")):a.lightbox=b(a.jQuery)}(this,function(a){function b(b){this.album=[],this.currentImageIndex=void 0,this.init(),this.options=a.extend({},this.constructor.defaults),this.option(b)}return b.defaults={albumLabel:"Image %1 of %2",alwaysShowNavOnTouchDevices:!1,fadeDuration:600,fitImagesInViewport:!0,imageFadeDuration:600,positionFromTop:50,resizeDuration:700,showImageNumberLabel:!0,wrapAround:!1,disableScrolling:!1,sanitizeTitle:!1},b.prototype.option=function(b){a.extend(this.options,b)},b.prototype.imageCountLabel=function(a,b){return this.options.albumLabel.replace(/%1/g,a).replace(/%2/g,b)},b.prototype.init=function(){var b=this;a(document).ready(function(){b.enable(),b.build()})},b.prototype.enable=function(){var b=this;a("body").on("click","a[rel^=lightbox], area[rel^=lightbox], a[data-lightbox], area[data-lightbox]",function(c){return b.start(a(c.currentTarget)),!1})},b.prototype.build=function(){var b=this;a('<div id="lightboxOverlay" class="lightboxOverlay"></div><div id="lightbox" class="lightbox"><div class="lb-outerContainer"><div class="lb-container"><img class="lb-image" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" /><div class="lb-nav"><a class="lb-prev" href="" ></a><a class="lb-next" href="" ></a></div><div class="lb-loader"><a class="lb-cancel"></a></div></div></div><div class="lb-dataContainer"><div class="lb-data"><div class="lb-details"><span class="lb-caption"></span><span class="lb-number"></span></div><div class="lb-closeContainer"><a class="lb-close"></a></div></div></div></div>').appendTo(a("body")),this.$lightbox=a("#lightbox"),this.$overlay=a("#lightboxOverlay"),this.$outerContainer=this.$lightbox.find(".lb-outerContainer"),this.$container=this.$lightbox.find(".lb-container"),this.$image=this.$lightbox.find(".lb-image"),this.$nav=this.$lightbox.find(".lb-nav"),this.containerPadding={top:parseInt(this.$container.css("padding-top"),10),right:parseInt(this.$container.css("padding-right"),10),bottom:parseInt(this.$container.css("padding-bottom"),10),left:parseInt(this.$container.css("padding-left"),10)},this.imageBorderWidth={top:parseInt(this.$image.css("border-top-width"),10),right:parseInt(this.$image.css("border-right-width"),10),bottom:parseInt(this.$image.css("border-bottom-width"),10),left:parseInt(this.$image.css("border-left-width"),10)},this.$overlay.hide().on("click",function(){return b.end(),!1}),this.$lightbox.hide().on("click",function(c){return"lightbox"===a(c.target).attr("id")&&b.end(),!1}),this.$outerContainer.on("click",function(c){return"lightbox"===a(c.target).attr("id")&&b.end(),!1}),this.$lightbox.find(".lb-prev").on("click",function(){return 0===b.currentImageIndex?b.changeImage(b.album.length-1):b.changeImage(b.currentImageIndex-1),!1}),this.$lightbox.find(".lb-next").on("click",function(){return b.currentImageIndex===b.album.length-1?b.changeImage(0):b.changeImage(b.currentImageIndex+1),!1}),this.$nav.on("mousedown",function(a){3===a.which&&(b.$nav.css("pointer-events","none"),b.$lightbox.one("contextmenu",function(){setTimeout(function(){this.$nav.css("pointer-events","auto")}.bind(b),0)}))}),this.$lightbox.find(".lb-loader, .lb-close").on("click",function(){return b.end(),!1})},b.prototype.start=function(b){function c(a){d.album.push({link:a.attr("href"),title:a.attr("data-title")||a.attr("title")})}var d=this,e=a(window);e.on("resize",a.proxy(this.sizeOverlay,this)),a("select, object, embed").css({visibility:"hidden"}),this.sizeOverlay(),this.album=[];var f,g=0,h=b.attr("data-lightbox");if(h){f=a(b.prop("tagName")+'[data-lightbox="'+h+'"]');for(var i=0;i<f.length;i=++i)c(a(f[i])),f[i]===b[0]&&(g=i)}else if("lightbox"===b.attr("rel"))c(b);else{f=a(b.prop("tagName")+'[rel="'+b.attr("rel")+'"]');for(var j=0;j<f.length;j=++j)c(a(f[j])),f[j]===b[0]&&(g=j)}var k=e.scrollTop()+this.options.positionFromTop,l=e.scrollLeft();this.$lightbox.css({top:k+"px",left:l+"px"}).fadeIn(this.options.fadeDuration),this.options.disableScrolling&&a("body").addClass("lb-disable-scrolling"),this.changeImage(g)},b.prototype.changeImage=function(b){var c=this;this.disableKeyboardNav();var d=this.$lightbox.find(".lb-image");this.$overlay.fadeIn(this.options.fadeDuration),a(".lb-loader").fadeIn("slow"),this.$lightbox.find(".lb-image, .lb-nav, .lb-prev, .lb-next, .lb-dataContainer, .lb-numbers, .lb-caption").hide(),this.$outerContainer.addClass("animating");var e=new Image;e.onload=function(){var f,g,h,i,j,k,l;d.attr("src",c.album[b].link),f=a(e),d.width(e.width),d.height(e.height),c.options.fitImagesInViewport&&(l=a(window).width(),k=a(window).height(),j=l-c.containerPadding.left-c.containerPadding.right-c.imageBorderWidth.left-c.imageBorderWidth.right-20,i=k-c.containerPadding.top-c.containerPadding.bottom-c.imageBorderWidth.top-c.imageBorderWidth.bottom-120,c.options.maxWidth&&c.options.maxWidth<j&&(j=c.options.maxWidth),c.options.maxHeight&&c.options.maxHeight<j&&(i=c.options.maxHeight),(e.width>j||e.height>i)&&(e.width/j>e.height/i?(h=j,g=parseInt(e.height/(e.width/h),10),d.width(h),d.height(g)):(g=i,h=parseInt(e.width/(e.height/g),10),d.width(h),d.height(g)))),c.sizeContainer(d.width(),d.height())},e.src=this.album[b].link,this.currentImageIndex=b},b.prototype.sizeOverlay=function(){this.$overlay.width(a(document).width()).height(a(document).height())},b.prototype.sizeContainer=function(a,b){function c(){d.$lightbox.find(".lb-dataContainer").width(g),d.$lightbox.find(".lb-prevLink").height(h),d.$lightbox.find(".lb-nextLink").height(h),d.showImage()}var d=this,e=this.$outerContainer.outerWidth(),f=this.$outerContainer.outerHeight(),g=a+this.containerPadding.left+this.containerPadding.right+this.imageBorderWidth.left+this.imageBorderWidth.right,h=b+this.containerPadding.top+this.containerPadding.bottom+this.imageBorderWidth.top+this.imageBorderWidth.bottom;e!==g||f!==h?this.$outerContainer.animate({width:g,height:h},this.options.resizeDuration,"swing",function(){c()}):c()},b.prototype.showImage=function(){this.$lightbox.find(".lb-loader").stop(!0).hide(),this.$lightbox.find(".lb-image").fadeIn(this.options.imageFadeDuration),this.updateNav(),this.updateDetails(),this.preloadNeighboringImages(),this.enableKeyboardNav()},b.prototype.updateNav=function(){var a=!1;try{document.createEvent("TouchEvent"),a=this.options.alwaysShowNavOnTouchDevices?!0:!1}catch(b){}this.$lightbox.find(".lb-nav").show(),this.album.length>1&&(this.options.wrapAround?(a&&this.$lightbox.find(".lb-prev, .lb-next").css("opacity","1"),this.$lightbox.find(".lb-prev, .lb-next").show()):(this.currentImageIndex>0&&(this.$lightbox.find(".lb-prev").show(),a&&this.$lightbox.find(".lb-prev").css("opacity","1")),this.currentImageIndex<this.album.length-1&&(this.$lightbox.find(".lb-next").show(),a&&this.$lightbox.find(".lb-next").css("opacity","1"))))},b.prototype.updateDetails=function(){var b=this;if("undefined"!=typeof this.album[this.currentImageIndex].title&&""!==this.album[this.currentImageIndex].title){var c=this.$lightbox.find(".lb-caption");this.options.sanitizeTitle?c.text(this.album[this.currentImageIndex].title):c.html(this.album[this.currentImageIndex].title),c.fadeIn("fast").find("a").on("click",function(b){void 0!==a(this).attr("target")?window.open(a(this).attr("href"),a(this).attr("target")):location.href=a(this).attr("href")})}if(this.album.length>1&&this.options.showImageNumberLabel){var d=this.imageCountLabel(this.currentImageIndex+1,this.album.length);this.$lightbox.find(".lb-number").text(d).fadeIn("fast")}else this.$lightbox.find(".lb-number").hide();this.$outerContainer.removeClass("animating"),this.$lightbox.find(".lb-dataContainer").fadeIn(this.options.resizeDuration,function(){return b.sizeOverlay()})},b.prototype.preloadNeighboringImages=function(){if(this.album.length>this.currentImageIndex+1){var a=new Image;a.src=this.album[this.currentImageIndex+1].link}if(this.currentImageIndex>0){var b=new Image;b.src=this.album[this.currentImageIndex-1].link}},b.prototype.enableKeyboardNav=function(){a(document).on("keyup.keyboard",a.proxy(this.keyboardAction,this))},b.prototype.disableKeyboardNav=function(){a(document).off(".keyboard")},b.prototype.keyboardAction=function(a){var b=27,c=37,d=39,e=a.keyCode,f=String.fromCharCode(e).toLowerCase();e===b||f.match(/x|o|c/)?this.end():"p"===f||e===c?0!==this.currentImageIndex?this.changeImage(this.currentImageIndex-1):this.options.wrapAround&&this.album.length>1&&this.changeImage(this.album.length-1):("n"===f||e===d)&&(this.currentImageIndex!==this.album.length-1?this.changeImage(this.currentImageIndex+1):this.options.wrapAround&&this.album.length>1&&this.changeImage(0))},b.prototype.end=function(){this.disableKeyboardNav(),a(window).off("resize",this.sizeOverlay),this.$lightbox.fadeOut(this.options.fadeDuration),this.$overlay.fadeOut(this.options.fadeDuration),a("select, object, embed").css({visibility:"visible"}),this.options.disableScrolling&&a("body").removeClass("lb-disable-scrolling")},new b}); | ||
//# sourceMappingURL=lightbox.min.map |
{ | ||
"name": "lightbox2", | ||
"version": "2.8.2", | ||
"version": "2.9.0", | ||
"author": "Lokesh Dhakar <lokesh.dhakar@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "The original Lightbox script. Uses jQuery.", |
111
README.md
@@ -7,110 +7,7 @@ # Lightbox2 | ||
For demos and usage instructions, visit [lokeshdhakar.com/projects/lightbox2/](http://lokeshdhakar.com/projects/lightbox2/). | ||
- **Demos and usage instructions.** Visit the [Lightbox homepage](http://lokeshdhakar.com/projects/lightbox2/) to see examples, info on getting started, script options, how to get help, and more. | ||
- **Releases and Changelog**. Viewable on the [Github Releases page](https://github.com/lokesh/lightbox2/releases) | ||
- **Roadmap.** View the [Roadmap](https://github.com/lokesh/lightbox2/blob/master/ROADMAP.md) for a peek at what is being planned for future releases. | ||
- **License.** Lightbox is licensed under the MIT License. [Learn more about the license.](http://lokeshdhakar.com/projects/lightbox2/#license) | ||
by [Lokesh Dhakar](http://www.lokeshdhakar.com) | ||
## Roadmap | ||
- **Maintenance.** Get open Issues and PRs number down. | ||
- **Mobile experience.** Redo animations and interactions from scratch and include gesture support. | ||
### v3.0 - In Brainstorming Phase | ||
- Add touch gesture support. | ||
- Optimize layout for mobile. | ||
- Optimize layout for screens of varying densities. | ||
- Use inline SVG for UI elements. | ||
- Do not initialize automatically and allow multiple instances. | ||
- Add event handlers. | ||
- Allow the setting of options from HTML. | ||
- Allow instantiation with jQuery plugin syntax. | ||
- If one of the two options, maxWidth or maxHeight, is set, maintain aspect ratio. | ||
- Evaluate start, end, and transition animations. | ||
- Evaluate preloading and caching. | ||
- Evaluate droppping jQuery requirement. | ||
- If user attempts to go forward when at end of image set, animation (shake?) indicating the end or option to close Lightbox. | ||
- Add Lightbox to NPM Registry. | ||
## Changelog | ||
### v2.8.2 - UNRELEASED | ||
- [Add] Add option to disable vertical scrolling [#487](https://github.com/lokesh/lightbox2/pull/487) Thanks [blacksunshineCoding](https://github.com/blacksunshineCoding) | ||
- [Fix] When horizontal scrolling is on page the overlay is not covering entire page [#485](https://github.com/lokesh/lightbox2/pull/485) Thanks [@manuel-io](https://github.com/manuel-io) | ||
- [Change] Add css minify task to Gruntfile.js and removedlegacy css vendor prefixes for border-radius. [#470](https://github.com/lokesh/lightbox2/pull/470) Thanks [ajerez](https://github.com/ajerez) | ||
### v2.8.1 - 2015-07-09 | ||
- [Fix] Change AMD jQuery require statement to use all lowercase. [#464](https://github.com/lokesh/lightbox2/pull/464) Thanks [@vtforester](https://github.com/vtforester) | ||
### v2.8.0 - 2015-06-29 | ||
- [Add] UMD support (AMD, CommonJS, fallback to global export).[#461](https://github.com/lokesh/lightbox2/pull/461) | ||
- [Add] option method for setting options. [#461](https://github.com/lokesh/lightbox2/commit/d708fbd716aaa90e01ba4198944c8955e7283d87) | ||
- [Add] CONTRIBUTING.md | ||
### v2.7.4 - 2015-06-23 | ||
- [Change] Revert jquery dep version to 2.x from 1.x. Added note to Lightbox page about using jQuery 1.x to get IE6, 7, and 8 support. | ||
- [Fix] Preserve author and license comments from lightbox.js in minified files. | ||
### v2.7.3 - 2015-06-22 | ||
- [Add] Barebone HTML file with examples /examples/index.html. | ||
- [Add] jquery.lightbox.js which concatenates jQuery and Lightbox. This is for those who are Bower averse or want an extra easy install. | ||
### v2.7.2 - 2015-06-16 | ||
- [Add] maxWidth and maxHeight options added [#197](https://github.com/lokesh/lightbox2/pull/197) | ||
- [Add] Enable target attribute in caption links [#299](https://github.com/lokesh/lightbox2/pull/299) | ||
- [Change] Switched to The MIT License from Creative Commons Attribution 4.0 International License. | ||
- [Change] Add CSS and images to bower.json main property. | ||
- [Change] Dropped version property from bower.json. [#453](https://github.com/lokesh/lightbox2/pull/453) | ||
- [Change] Use src -> dist folder structure for build. | ||
- [Fix] Remove empty src attribute from img tag [#287](https://github.com/lokesh/lightbox2/pull/287) | ||
- [Fix] Correct grammatical error in comment [#224](https://github.com/lokesh/lightbox2/pull/224) | ||
- [Fix] Clear the jquery animation queue before hiding the .lb-loader [#309](https://github.com/lokesh/lightbox2/pull/309) | ||
- [Remove] Remove releases's zips from repo. | ||
### v2.7.1 - 2014-03-30 | ||
- [Fix] Enable links in captions | ||
### v2.7.0 - 2014-03-29 | ||
- [Add] Support for data-title attribute for the caption. - Thanks [@copycut](https://github.com/copycut) | ||
- [Add] New option to enable always visible prev and next arrows | ||
- [Change] Rewrite Coffeescript code into plain ole Javascript | ||
- [Change] Updated jQuery to v1.10.2 | ||
- [Fix] prev/next arrows not appearing in IE9 and IE 10 - Thanks [@rebizu](https://github.com/rebizu) | ||
- [Fix] Support wrap around option w/keyboard actions. Thanks [@vovayatsyuk](https://github.com/vovayatsyuk) | ||
### v2.6.0 - 2013-07-06 | ||
- [Add] Added wraparound option | ||
- [Add] Added fitImagesInViewport option - now mobile friendly | ||
- [Add] Added showImageNumber label | ||
- [Add] Compatibility with html5shiv | ||
- [Add] Html5 valid using new data-lightbox attribute | ||
- [Add] Compatibility with hmtl5shiv and modernizr | ||
- [Add] Support jquery 1.9+ | ||
- [Change] Move reference to loading and close images into css | ||
- [Change] Cache jquery objects | ||
### v2.5.0 - 2012-04-11 | ||
- [Change] Switch to jQuery from Prototype and Scriptaculous | ||
- [Change] Switch from Javacript to Coffeescript | ||
- [Change] Switch from CSS to SASS | ||
- [Add] Repo created on Github | ||
## How to deploy | ||
- Update version number in ```src/lightbox.js``` | ||
- Update README.md Changelog with release date | ||
- grunt build | ||
- Push to Github repo | ||
- Create a new Github release along with tag. Naming convention for both ```v2.8.1``` |
/*! | ||
* Lightbox v2.8.1 | ||
* Lightbox v2.9.0 | ||
* by Lokesh Dhakar | ||
@@ -11,2 +11,4 @@ * | ||
* https://github.com/lokesh/lightbox2/blob/master/LICENSE | ||
* | ||
* @preserve | ||
*/ | ||
@@ -45,4 +47,5 @@ | ||
alwaysShowNavOnTouchDevices: false, | ||
fadeDuration: 500, | ||
fadeDuration: 600, | ||
fitImagesInViewport: true, | ||
imageFadeDuration: 600, | ||
// maxWidth: 800, | ||
@@ -54,3 +57,12 @@ // maxHeight: 600, | ||
wrapAround: false, | ||
disableScrolling: false | ||
disableScrolling: false, | ||
/* | ||
Sanitize Title | ||
If the caption data is trusted, for example you are hardcoding it in, then leave this to false. | ||
This will free you to add html tags, such as links, in the caption. | ||
If the caption data is user submitted or from some other untrusted source, then set this to true | ||
to prevent xss and other injection attacks. | ||
*/ | ||
sanitizeTitle: false | ||
}; | ||
@@ -67,5 +79,8 @@ | ||
Lightbox.prototype.init = function() { | ||
console.log('init'); | ||
this.enable(); | ||
this.build(); | ||
var self = this; | ||
// Both enable and build methods require the body tag to be in the DOM. | ||
$(document).ready(function() { | ||
self.enable(); | ||
self.build(); | ||
}); | ||
}; | ||
@@ -94,9 +109,20 @@ | ||
this.$container = this.$lightbox.find('.lb-container'); | ||
this.$image = this.$lightbox.find('.lb-image'); | ||
this.$nav = this.$lightbox.find('.lb-nav'); | ||
// Store css values for future lookup | ||
this.containerTopPadding = parseInt(this.$container.css('padding-top'), 10); | ||
this.containerRightPadding = parseInt(this.$container.css('padding-right'), 10); | ||
this.containerBottomPadding = parseInt(this.$container.css('padding-bottom'), 10); | ||
this.containerLeftPadding = parseInt(this.$container.css('padding-left'), 10); | ||
this.containerPadding = { | ||
top: parseInt(this.$container.css('padding-top'), 10), | ||
right: parseInt(this.$container.css('padding-right'), 10), | ||
bottom: parseInt(this.$container.css('padding-bottom'), 10), | ||
left: parseInt(this.$container.css('padding-left'), 10) | ||
}; | ||
this.imageBorderWidth = { | ||
top: parseInt(this.$image.css('border-top-width'), 10), | ||
right: parseInt(this.$image.css('border-right-width'), 10), | ||
bottom: parseInt(this.$image.css('border-bottom-width'), 10), | ||
left: parseInt(this.$image.css('border-left-width'), 10) | ||
}; | ||
// Attach event handlers to the newly minted DOM elements | ||
@@ -140,2 +166,28 @@ this.$overlay.hide().on('click', function() { | ||
/* | ||
Show context menu for image on right-click | ||
There is a div containing the navigation that spans the entire image and lives above of it. If | ||
you right-click, you are right clicking this div and not the image. This prevents users from | ||
saving the image or using other context menu actions with the image. | ||
To fix this, when we detect the right mouse button is pressed down, but not yet clicked, we | ||
set pointer-events to none on the nav div. This is so that the upcoming right-click event on | ||
the next mouseup will bubble down to the image. Once the right-click/contextmenu event occurs | ||
we set the pointer events back to auto for the nav div so it can capture hover and left-click | ||
events as usual. | ||
*/ | ||
this.$nav.on('mousedown', function(event) { | ||
if (event.which === 3) { | ||
self.$nav.css('pointer-events', 'none'); | ||
self.$lightbox.one('contextmenu', function() { | ||
setTimeout(function() { | ||
this.$nav.css('pointer-events', 'auto'); | ||
}.bind(self), 0); | ||
}); | ||
} | ||
}); | ||
this.$lightbox.find('.lb-loader, .lb-close').on('click', function() { | ||
@@ -252,4 +304,4 @@ self.end(); | ||
windowHeight = $(window).height(); | ||
maxImageWidth = windowWidth - self.containerLeftPadding - self.containerRightPadding - 20; | ||
maxImageHeight = windowHeight - self.containerTopPadding - self.containerBottomPadding - 120; | ||
maxImageWidth = windowWidth - self.containerPadding.left - self.containerPadding.right - self.imageBorderWidth.left - self.imageBorderWidth.right - 20; | ||
maxImageHeight = windowHeight - self.containerPadding.top - self.containerPadding.bottom - self.imageBorderWidth.top - self.imageBorderWidth.bottom - 120; | ||
@@ -264,3 +316,4 @@ // Check if image size is larger then maxWidth|maxHeight in settings | ||
// Is there a fitting issue? | ||
// Is the current image's width or height is greater than the maxImageWidth or maxImageHeight | ||
// option than we need to size down while maintaining the aspect ratio. | ||
if ((preloader.width > maxImageWidth) || (preloader.height > maxImageHeight)) { | ||
@@ -300,4 +353,4 @@ if ((preloader.width / maxImageWidth) > (preloader.height / maxImageHeight)) { | ||
var oldHeight = this.$outerContainer.outerHeight(); | ||
var newWidth = imageWidth + this.containerLeftPadding + this.containerRightPadding; | ||
var newHeight = imageHeight + this.containerTopPadding + this.containerBottomPadding; | ||
var newWidth = imageWidth + this.containerPadding.left + this.containerPadding.right + this.imageBorderWidth.left + this.imageBorderWidth.right; | ||
var newHeight = imageHeight + this.containerPadding.top + this.containerPadding.bottom + this.imageBorderWidth.top + this.imageBorderWidth.bottom; | ||
@@ -326,3 +379,3 @@ function postResize() { | ||
this.$lightbox.find('.lb-loader').stop(true).hide(); | ||
this.$lightbox.find('.lb-image').fadeIn('slow'); | ||
this.$lightbox.find('.lb-image').fadeIn(this.options.imageFadeDuration); | ||
@@ -379,5 +432,9 @@ this.updateNav(); | ||
this.album[this.currentImageIndex].title !== '') { | ||
this.$lightbox.find('.lb-caption') | ||
.html(this.album[this.currentImageIndex].title) | ||
.fadeIn('fast') | ||
var $caption = this.$lightbox.find('.lb-caption'); | ||
if (this.options.sanitizeTitle) { | ||
$caption.text(this.album[this.currentImageIndex].title); | ||
} else { | ||
$caption.html(this.album[this.currentImageIndex].title); | ||
} | ||
$caption.fadeIn('fast') | ||
.find('a').on('click', function(event) { | ||
@@ -384,0 +441,0 @@ if ($(this).attr('target') !== undefined) { |
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 too big to display
Sorry, the diff of this file is too big to display
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
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
599689
31
9906
13