|
21 | 21 | this.alwaysShowNavOnTouchDevices = false; |
22 | 22 | this.wrapAround = false; |
23 | 23 | } |
24 | | - |
| 24 | + |
25 | 25 | // Change to localize to non-english language |
26 | 26 | LightboxOptions.prototype.albumLabel = function(curImageNum, albumSize) { |
27 | 27 | return "Image " + curImageNum + " of " + albumSize; |
|
58 | 58 | // Attach event handlers to the new DOM elements. click click click |
59 | 59 | Lightbox.prototype.build = function() { |
60 | 60 | var self = this; |
61 | | - $("<div id='lightboxOverlay' class='lightboxOverlay'></div><div id='lightbox' class='lightbox'><div class='lb-outerContainer'><div class='lb-container'><img class='lb-image' src='' /><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($('body')); |
62 | | - |
| 61 | + $("<div id='lightboxOverlay' class='lightboxOverlay'></div><div id='lightbox' class='lightbox'><div class='lb-outerContainer'><div class='lb-container'><img class='lb-image' src='' /><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><a class='lb-download' href='' target='_blank'></a></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($('body')); |
| 62 | + |
63 | 63 | // Cache jQuery objects |
64 | 64 | this.$lightbox = $('#lightbox'); |
65 | 65 | this.$overlay = $('#lightboxOverlay'); |
|
71 | 71 | this.containerRightPadding = parseInt(this.$container.css('padding-right'), 10); |
72 | 72 | this.containerBottomPadding = parseInt(this.$container.css('padding-bottom'), 10); |
73 | 73 | this.containerLeftPadding = parseInt(this.$container.css('padding-left'), 10); |
74 | | - |
| 74 | + |
75 | 75 | // Attach event handlers to the newly minted DOM elements |
76 | 76 | this.$overlay.hide().on('click', function() { |
77 | 77 | self.end(); |
|
114 | 114 | self.end(); |
115 | 115 | return false; |
116 | 116 | }); |
| 117 | + |
| 118 | + this.$lightbox.find('.lb-download').on('click', function (e) { |
| 119 | + window.open(e.target.href) |
| 120 | + }); |
117 | 121 | }; |
118 | 122 |
|
119 | 123 | // Show overlay and lightbox. If the image is part of a set, add siblings to album array. |
|
166 | 170 | } |
167 | 171 | } |
168 | 172 | } |
169 | | - |
| 173 | + |
170 | 174 | // Position Lightbox |
171 | 175 | var top = $window.scrollTop() + this.options.positionFromTop; |
172 | 176 | var left = $window.scrollLeft(); |
|
184 | 188 |
|
185 | 189 | this.disableKeyboardNav(); |
186 | 190 | var $image = this.$lightbox.find('.lb-image'); |
| 191 | + var $downloadLink = this.$lightbox.find('.lb-download'); |
187 | 192 |
|
188 | 193 | this.$overlay.fadeIn(this.options.fadeDuration); |
189 | 194 |
|
|
197 | 202 | preloader.onload = function() { |
198 | 203 | var $preloader, imageHeight, imageWidth, maxImageHeight, maxImageWidth, windowHeight, windowWidth; |
199 | 204 | $image.attr('src', self.album[imageNumber].link); |
| 205 | + $downloadLink.attr('href', self.album[imageNumber].link); |
200 | 206 |
|
201 | 207 | $preloader = $(preloader); |
202 | 208 |
|
203 | 209 | $image.width(preloader.width); |
204 | 210 | $image.height(preloader.height); |
205 | | - |
| 211 | + |
206 | 212 | if (self.options.fitImagesInViewport) { |
207 | 213 | // Fit image inside the viewport. |
208 | 214 | // Take into account the border around the image and an additional 10px gutter on each side. |
|
244 | 250 | // Animate the size of the lightbox to fit the image we are showing |
245 | 251 | Lightbox.prototype.sizeContainer = function(imageWidth, imageHeight) { |
246 | 252 | var self = this; |
247 | | - |
| 253 | + |
248 | 254 | var oldWidth = this.$outerContainer.outerWidth(); |
249 | 255 | var oldHeight = this.$outerContainer.outerHeight(); |
250 | 256 | var newWidth = imageWidth + this.containerLeftPadding + this.containerRightPadding; |
251 | 257 | var newHeight = imageHeight + this.containerTopPadding + this.containerBottomPadding; |
252 | | - |
| 258 | + |
253 | 259 | function postResize() { |
254 | 260 | self.$lightbox.find('.lb-dataContainer').width(newWidth); |
255 | 261 | self.$lightbox.find('.lb-prevLink').height(newHeight); |
|
273 | 279 | Lightbox.prototype.showImage = function() { |
274 | 280 | this.$lightbox.find('.lb-loader').hide(); |
275 | 281 | this.$lightbox.find('.lb-image').fadeIn('slow'); |
276 | | - |
| 282 | + |
277 | 283 | this.updateNav(); |
278 | 284 | this.updateDetails(); |
279 | 285 | this.preloadNeighboringImages(); |
|
330 | 336 | location.href = $(this).attr('href'); |
331 | 337 | }); |
332 | 338 | } |
333 | | - |
| 339 | + |
334 | 340 | if (this.album.length > 1 && this.options.showImageNumberLabel) { |
335 | 341 | this.$lightbox.find('.lb-number').text(this.options.albumLabel(this.currentImageIndex + 1, this.album.length)).fadeIn('fast'); |
336 | 342 | } else { |
337 | 343 | this.$lightbox.find('.lb-number').hide(); |
338 | 344 | } |
339 | | - |
| 345 | + |
340 | 346 | this.$outerContainer.removeClass('animating'); |
341 | | - |
| 347 | + |
342 | 348 | this.$lightbox.find('.lb-dataContainer').fadeIn(this.options.resizeDuration, function() { |
343 | 349 | return self.sizeOverlay(); |
344 | 350 | }); |
|
0 commit comments