vendor: 4,620 bytes, lines 1-113
1/*! 2 * Lightbox v2.8.2 3 * by Lokesh Dhakar 4 * 5 * More info: 6 * http://lokeshdhakar.com/projects/lightbox2/ 7 * 8 * Copyright 2007, 2015 Lokesh Dhakar 9 * Released under the MIT license 10 * https://github.com/lokesh/lightbox2/blob/master/LICENSE 11 */ 12 13// Uses Node, AMD or browser globals to create a module. 14(function (root, factory) { 15 if (typeof define === 'function' && define.amd) { 16 // AMD. Register as an anonymous module. 17 define(['jquery'], factory); 18 } else if (typeof exports === 'object') { 19 // Node. Does not work with strict CommonJS, but 20 // only CommonJS-like environments that support module.exports, 21 // like Node. 22 module.exports = factory(require('jquery')); 23 } else { 24 // Browser globals (root is window) 25 root.lightbox = factory(root.jQuery); 26 } 27}(this, function ($) { 28 29 function Lightbox(options) { 30 this.album = []; 31 this.currentImageIndex = void 0; 32 this.init(); 33 34 // options 35 this.options = $.extend({}, this.constructor.defaults); 36 this.option(options); 37 } 38 39 // Descriptions of all options available on the demo site: 40 // http://lokeshdhakar.com/projects/lightbox2/index.html#options 41 Lightbox.defaults = { 42 albumLabel: '%1 / %2', 43 alwaysShowNavOnTouchDevices: false, 44 fadeDuration: 500, 45 fitImagesInViewport: true, 46 // maxWidth: 800, 47 // maxHeight: 600, 48 positionFromTop: 50, 49 resizeDuration: 700, 50 showImageNumberLabel: true, 51 wrapAround: false, 52 disableScrolling: false 53 }; 54 55 Lightbox.prototype.option = function(options) { 56 $.extend(this.options, options); 57 }; 58 59 Lightbox.prototype.imageCountLabel = function(currentImageNum, totalImages) { 60 return this.options.albumLabel.replace(/%1/g, currentImageNum).replace(/%2/g, totalImages); 61 }; 62 63 Lightbox.prototype.init = function() { 64 this.enable(); 65 this.build(); 66 }; 67 68 // Loop through anchors and areamaps looking for either data-lightbox attributes or rel attributes 69 // that contain 'lightbox'. When these are clicked, start lightbox. 70 Lightbox.prototype.enable = function() { 71 var self = this; 72 $('body').on('click', 'a[rel^=lightbox], area[rel^=lightbox], a[data-lightbox], area[data-lightbox]', function(event) { 73 self.start($(event.currentTarget)); 74 return false; 75 }); 76 }; 77 78 // Build html for the lightbox and the overlay. 79 // Attach event handlers to the new DOM elements. click click click 80 Lightbox.prototype.build = function() { 81 var self = this; 82 $('<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($('body')); 83 84 // Cache jQuery objects 85 this.$lightbox = $('#lightbox'); 86 this.$overlay = $('#lightboxOverlay'); 87 this.$outerContainer = this.$lightbox.find('.lb-outerContainer'); 88 this.$container = this.$lightbox.find('.lb-container'); 89 90 // Store css values for future lookup 91 this.containerTopPadding = parseInt(this.$container.css('padding-top'), 10); 92 this.containerRightPadding = parseInt(this.$container.css('padding-right'), 10); 93 this.containerBottomPadding = parseInt(this.$container.css('padding-bottom'), 10); 94 this.containerLeftPadding = parseInt(this.$container.css('padding-left'), 10); 95 96 // Attach event handlers to the newly minted DOM elements 97 this.$overlay.hide().on('click', function() { 98 self.end(); 99 return false; 100 }); 101 102 this.$lightbox.hide().on('click', function(event) { 103 if ($(event.target).attr('id') === 'lightbox') { 104 self.end(); 105 } 106 /* SWP intercept the click on download button [[[ */ 107 else if ($(event.target).attr('id') === 'swp_lightbox_downbutton') { 108 $(event.target).attr('href', $(event.target).closest('#lightbox').find('.lb-image').attr('src')); 109 $(event.target).dispatchEvent('onclick'); 110 } 111 /* SWP intercept the click on download button ]]] */ 112 return false; 113 });
114 115 this.$outerContainer.on('click', function(event) { 116 if ($(event.target).attr('id') === 'lightbox') { 117 self.end(); 118 } 119 return false; 120 }); 121 122 this.$lightbox.find('.lb-prev').on('click', function() { 123 if (self.currentImageIndex === 0) { 124 self.changeImage(self.album.length - 1); 125 } else { 126 self.changeImage(self.currentImageIndex - 1); 127 } 128 return false; 129 }); 130 131 this.$lightbox.find('.lb-next').on('click', function() { 132 if (self.currentImageIndex === self.album.length - 1) { 133 self.changeImage(0); 134 } else { 135 self.changeImage(self.currentImageIndex + 1); 136 } 137 return false; 138 }); 139 140 this.$lightbox.find('.lb-loader, .lb-close').on('click', function() { 141 self.end(); 142 return false; 143 }); 144 }; 145 146 // Show overlay and lightbox. If the image is part of a set, add siblings to album array. 147 Lightbox.prototype.start = function($link) { 148 var self = this; 149 var $window = $(window); 150 151 $window.on('resize', $.proxy(this.sizeOverlay, this)); 152 153 $('select, object, embed').css({ 154 visibility: 'hidden' 155 }); 156 157 this.sizeOverlay(); 158 159 this.album = []; 160 var imageNumber = 0; 161 162 function addToAlbum($link) { 163 self.album.push({ 164 link: $link.attr('href'), 165 title: $link.attr('data-title') || $link.attr('title') 166 }); 167 } 168 169 // Support both data-lightbox attribute and rel attribute implementations 170 var dataLightboxValue = $link.attr('data-lightbox'); 171 var $links; 172 173 if (dataLightboxValue) { 174 $links = $($link.prop('tagName') + '[data-lightbox="' + dataLightboxValue + '"]'); 175 for (var i = 0; i < $links.length; i = ++i) { 176 addToAlbum($($links[i])); 177 if ($links[i] === $link[0]) { 178 imageNumber = i; 179 } 180 } 181 } else { 182 if ($link.attr('rel') === 'lightbox') { 183 // If image is not part of a set 184 addToAlbum($link); 185 } else { 186 // If image is part of a set 187 $links = $($link.prop('tagName') + '[rel="' + $link.attr('rel') + '"]'); 188 for (var j = 0; j < $links.length; j = ++j) { 189 addToAlbum($($links[j])); 190 if ($links[j] === $link[0]) { 191 imageNumber = j; 192 } 193 } 194 } 195 } 196 197 // Position Lightbox 198 var top = $window.scrollTop() + this.options.positionFromTop; 199 var left = $window.scrollLeft(); 200 this.$lightbox.css({ 201 top: top + 'px', 202 left: left + 'px' 203 }).fadeIn(this.options.fadeDuration); 204 205 /* SWP add download button [[[*/ 206 if(IsDownloadButtonEnabled($link)) 207 { 208 $('.lb-details').find('.swp_lightbox_downbutton').remove(); 209 $('.lb-number').before('<div class="swp_lightbox_downbutton"><a id="swp_lightbox_downbutton" href="" download>Download</a></div>'); 210 } 211 /* SWP add download button ]]]*/ 212 213 // Disable scrolling of the page while open 214 if (this.options.disableScrolling) { 215 $('body').addClass('lb-disable-scrolling'); 216 } 217 218 this.changeImage(imageNumber); 219 }; 220 221 // Hide most UI elements in preparation for the animated resizing of the lightbox. 222 Lightbox.prototype.changeImage = function(imageNumber) { 223 var self = this; 224 225 this.disableKeyboardNav(); 226 var $image = this.$lightbox.find('.lb-image'); 227 228 this.$overlay.fadeIn(this.options.fadeDuration); 229 230 $('.lb-loader').fadeIn('slow'); 231 this.$lightbox.find('.lb-image, .lb-nav, .lb-prev, .lb-next, .lb-dataContainer, .lb-numbers, .lb-caption').hide(); 232 233 this.$outerContainer.addClass('animating'); 234 235 // When image to show is preloaded, we send the width and height to sizeContainer() 236 var preloader = new Image(); 237 preloader.onload = function() { 238 var $preloader; 239 var imageHeight; 240 var imageWidth; 241 var maxImageHeight; 242 var maxImageWidth; 243 var windowHeight; 244 var windowWidth; 245 246 $image.attr('src', self.album[imageNumber].link); 247 248 $preloader = $(preloader); 249 250 $image.width(preloader.width); 251 $image.height(preloader.height); 252 253 if (self.options.fitImagesInViewport) { 254 // Fit image inside the viewport. 255 // Take into account the border around the image and an additional 10px gutter on each side. 256 257 windowWidth = $(window).width(); 258 windowHeight = $(window).height(); 259 maxImageWidth = windowWidth - self.containerLeftPadding - self.containerRightPadding - 20; 260 maxImageHeight = windowHeight - self.containerTopPadding - self.containerBottomPadding - 120; 261 262 // Check if image size is larger then maxWidth|maxHeight in settings 263 if (self.options.maxWidth && self.options.maxWidth < maxImageWidth) { 264 maxImageWidth = self.options.maxWidth; 265 } 266 if (self.options.maxHeight && self.options.maxHeight < maxImageWidth) { 267 maxImageHeight = self.options.maxHeight; 268 } 269 270 // Is there a fitting issue? 271 if ((preloader.width > maxImageWidth) || (preloader.height > maxImageHeight)) { 272 if ((preloader.width / maxImageWidth) > (preloader.height / maxImageHeight)) { 273 imageWidth = maxImageWidth; 274 imageHeight = parseInt(preloader.height / (preloader.width / imageWidth), 10); 275 $image.width(imageWidth);
276 $image.height(imageHeight); 277 } else { 278 imageHeight = maxImageHeight; 279 imageWidth = parseInt(preloader.width / (preloader.height / imageHeight), 10); 280 $image.width(imageWidth); 281 $image.height(imageHeight); 282 } 283 } 284 } 285 self.sizeContainer($image.width(), $image.height()); 286 }; 287 288 preloader.src = this.album[imageNumber].link; 289 this.currentImageIndex = imageNumber; 290 }; 291 292 // Stretch overlay to fit the viewport 293 Lightbox.prototype.sizeOverlay = function() { 294 this.$overlay 295 .width($(document).width()) 296 .height($(document).height()); 297 }; 298 299 // Animate the size of the lightbox to fit the image we are showing 300 Lightbox.prototype.sizeContainer = function(imageWidth, imageHeight) { 301 var self = this; 302 303 var oldWidth = this.$outerContainer.outerWidth(); 304 var oldHeight = this.$outerContainer.outerHeight(); 305 var newWidth = imageWidth + this.containerLeftPadding + this.containerRightPadding; 306 var newHeight = imageHeight + this.containerTopPadding + this.containerBottomPadding; 307 308 function postResize() { 309 self.$lightbox.find('.lb-dataContainer').width(newWidth); 310 self.$lightbox.find('.lb-prevLink').height(newHeight); 311 self.$lightbox.find('.lb-nextLink').height(newHeight); 312 self.showImage(); 313 } 314 315 if (oldWidth !== newWidth || oldHeight !== newHeight) { 316 this.$outerContainer.animate({ 317 width: newWidth, 318 height: newHeight 319 }, this.options.resizeDuration, 'swing', function() { 320 postResize(); 321 }); 322 } else { 323 postResize(); 324 } 325 }; 326 327 // Display the image and its details and begin preload neighboring images. 328 Lightbox.prototype.showImage = function() { 329 this.$lightbox.find('.lb-loader').stop(true).hide(); 330 this.$lightbox.find('.lb-image').fadeIn('slow'); 331 332 this.updateNav(); 333 this.updateDetails(); 334 this.preloadNeighboringImages(); 335 this.enableKeyboardNav(); 336 }; 337 338 // Display previous and next navigation if appropriate. 339 Lightbox.prototype.updateNav = function() { 340 // Check to see if the browser supports touch events. If so, we take the conservative approach 341 // and assume that mouse hover events are not supported and always show prev/next navigation 342 // arrows in image sets. 343 var alwaysShowNav = false; 344 try { 345 document.createEvent('TouchEvent'); 346 alwaysShowNav = (this.options.alwaysShowNavOnTouchDevices) ? true : false; 347 } catch (e) {} 348 349 this.$lightbox.find('.lb-nav').show(); 350 351 if (this.album.length > 1) { 352 if (this.options.wrapAround) { 353 if (alwaysShowNav) { 354 this.$lightbox.find('.lb-prev, .lb-next').css('opacity', '1'); 355 } 356 this.$lightbox.find('.lb-prev, .lb-next').show(); 357 } else { 358 if (this.currentImageIndex > 0) { 359 this.$lightbox.find('.lb-prev').show(); 360 if (alwaysShowNav) { 361 this.$lightbox.find('.lb-prev').css('opacity', '1'); 362 } 363 } 364 if (this.currentImageIndex < this.album.length - 1) { 365 this.$lightbox.find('.lb-next').show(); 366 if (alwaysShowNav) { 367 this.$lightbox.find('.lb-next').css('opacity', '1'); 368 } 369 } 370 } 371 } 372 }; 373 374 // Display caption, image number, and closing button. 375 Lightbox.prototype.updateDetails = function() { 376 var self = this; 377 378 // Enable anchor clicks in the injected caption html. 379 // Thanks Nate Wright for the fix. @https://github.com/NateWr 380 if (typeof this.album[this.currentImageIndex].title !== 'undefined' && 381 this.album[this.currentImageIndex].title !== '') { 382 this.$lightbox.find('.lb-caption') 383 .html(this.album[this.currentImageIndex].title) 384 .fadeIn('fast') 385 .find('a').on('click', function(event) { 386 if ($(this).attr('target') !== undefined) { 387 window.open($(this).attr('href'), $(this).attr('target')); 388 } else { 389 location.href = $(this).attr('href'); 390 } 391 }); 392 } 393 394 if (this.album.length > 1 && this.options.showImageNumberLabel) { 395 var labelText = this.imageCountLabel(this.currentImageIndex + 1, this.album.length); 396 this.$lightbox.find('.lb-number').text(labelText).fadeIn('fast'); 397 } else { 398 this.$lightbox.find('.lb-number').hide(); 399 } 400 401 this.$outerContainer.removeClass('animating'); 402 403 this.$lightbox.find('.lb-dataContainer').fadeIn(this.options.resizeDuration, function() { 404 return self.sizeOverlay(); 405 });
406 }; 407 408 // Preload previous and next images in set. 409 Lightbox.prototype.preloadNeighboringImages = function() { 410 if (this.album.length > this.currentImageIndex + 1) { 411 var preloadNext = new Image(); 412 preloadNext.src = this.album[this.currentImageIndex + 1].link; 413 } 414 if (this.currentImageIndex > 0) { 415 var preloadPrev = new Image(); 416 preloadPrev.src = this.album[this.currentImageIndex - 1].link; 417 } 418 }; 419 420 Lightbox.prototype.enableKeyboardNav = function() { 421 $(document).on('keyup.keyboard', $.proxy(this.keyboardAction, this)); 422 }; 423 424 Lightbox.prototype.disableKeyboardNav = function() { 425 $(document).off('.keyboard'); 426 }; 427 428 Lightbox.prototype.keyboardAction = function(event) { 429 var KEYCODE_ESC = 27; 430 var KEYCODE_LEFTARROW = 37; 431 var KEYCODE_RIGHTARROW = 39; 432 433 var keycode = event.keyCode; 434 var key = String.fromCharCode(keycode).toLowerCase(); 435 if (keycode === KEYCODE_ESC || key.match(/x|o|c/)) { 436 this.end(); 437 } else if (key === 'p' || keycode === KEYCODE_LEFTARROW) { 438 if (this.currentImageIndex !== 0) { 439 this.changeImage(this.currentImageIndex - 1); 440 } else if (this.options.wrapAround && this.album.length > 1) { 441 this.changeImage(this.album.length - 1); 442 } 443 } else if (key === 'n' || keycode === KEYCODE_RIGHTARROW) { 444 if (this.currentImageIndex !== this.album.length - 1) { 445 this.changeImage(this.currentImageIndex + 1); 446 } else if (this.options.wrapAround && this.album.length > 1) { 447 this.changeImage(0); 448 } 449 } 450 }; 451 452 // Closing time. :-( 453 Lightbox.prototype.end = function() { 454 this.disableKeyboardNav(); 455 $(window).off('resize', this.sizeOverlay); 456 this.$lightbox.fadeOut(this.options.fadeDuration); 457 this.$overlay.fadeOut(this.options.fadeDuration); 458 $('select, object, embed').css({ 459 visibility: 'visible' 460 }); 461 if (this.options.disableScrolling) { 462 $('body').removeClass('lb-disable-scrolling'); 463 } 464 }; 465 466 /* SWP check if we should show download button [[[ */ 467 function IsDownloadButtonEnabled($link) { 468 var dataShowDownButton = $link.attr('data-download-button'); 469 return (dataShowDownButton && dataShowDownButton==='true') ; 470 } 471 /* SWP check if we should show download button ]]] */ 472 473 return new Lightbox(); 474}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.