From 6012f8fef08c57f27d202037398c8ff2a485b1be Mon Sep 17 00:00:00 2001 From: Duncan McDougall Date: Sun, 22 Sep 2013 22:01:55 +0100 Subject: [PATCH] Added basic caption option --- demo/index_with_captions.html | 70 +++++++++++++++++++++++++++++++++++ jquery.lightbox.css | 23 ++++++++++++ jquery.lightbox.js | 19 ++++++++-- jquery.lightbox.min.css | 2 +- jquery.lightbox.min.js | 2 +- package.json | 2 +- readme.markdown | 9 +++++ 7 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 demo/index_with_captions.html diff --git a/demo/index_with_captions.html b/demo/index_with_captions.html new file mode 100644 index 0000000..16bc3dd --- /dev/null +++ b/demo/index_with_captions.html @@ -0,0 +1,70 @@ + + + + + Demo + + + + + +
+

Responsive Lightbox

+ + + +
+ + + + + + \ No newline at end of file diff --git a/jquery.lightbox.css b/jquery.lightbox.css index 8f1e60a..a50997a 100644 --- a/jquery.lightbox.css +++ b/jquery.lightbox.css @@ -30,6 +30,29 @@ body.blurred > * { top: 48%; left: 50%; } +.lightbox-caption { + display: none; + position: absolute; + left: 0; + bottom: 0; + width: 100%; + text-align: center; + z-index: 1000; + background: #000; + background: rgba(0,0,0,0.7); +} + +.lightbox-caption p { + margin: 0 auto; + max-width: 70%; + display: inline-block; + *display: inline; + *zoom: 1; + padding: 10px; + color: #fff; + font-size: 12px; + line-height: 18px; +} .lightbox-button { position: absolute; diff --git a/jquery.lightbox.js b/jquery.lightbox.js index e05a63a..f4d0897 100644 --- a/jquery.lightbox.js +++ b/jquery.lightbox.js @@ -30,7 +30,7 @@ image: null, current: null, locked: false, - selector: "#lightbox", + caption: null, init: function (items) { plugin.items = items; @@ -38,16 +38,18 @@ if (!plugin.lightbox) { $('body').append( - ''),d.lightbox=a("#lightbox"),d.caption=a(".lightbox-caption",d.lightbox)),d.items.length>1&&c.nav?a(".lightbox-nav",d.lightbox).show():a(".lightbox-nav",d.lightbox).hide(),d.bindEvents()},loadImage:function(){c.blur&&a("body").addClass("blurred"),a("img",d.lightbox).remove(),d.lightbox.fadeIn("fast").append('');var b=a('');a(b).load(function(){a(".lightbox-loading").remove(),d.lightbox.append(b),d.image=a("img",d.lightbox).hide(),d.resizeImage(),d.setCaption()})},setCaption:function(){var b=a(d.current).data("caption");b&&b.length>0?(d.caption.fadeIn(),a("p",d.caption).text(b)):d.caption.hide()},resizeImage:function(){var b,e,f,g,h;e=a(window).height()-c.margin,f=a(window).outerWidth(!0)-c.margin,d.image.width("").height(""),g=d.image.height(),h=d.image.width(),h>f&&(b=f/h,h=f,g=Math.round(g*b)),g>e&&(b=e/g,g=e,h=Math.round(h*b)),d.image.width(h).height(g).css({top:(a(window).height()-d.image.outerHeight())/2+"px",left:(a(window).width()-d.image.outerWidth())/2+"px"}).show(),d.locked=!1},getCurrentIndex:function(){return a.inArray(d.current,d.items)},next:function(){return d.locked?!1:(d.locked=!0,d.getCurrentIndex()>=d.items.length-1?a(d.items[0]).click():a(d.items[d.getCurrentIndex()+1]).click(),void 0)},previous:function(){return d.locked?!1:(d.locked=!0,d.getCurrentIndex()<=0?a(d.items[d.items.length-1]).click():a(d.items[d.getCurrentIndex()-1]).click(),void 0)},bindEvents:function(){a(d.items).click(function(b){if(!a("#lightbox").is(":visible")&&(a(window).width() +``` + Contributing ------