vendor: 4,616 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).fireEvent('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-number').before('<div class="swp_lightbox_downbutton"><a id="swp_lightbox_downbutton" href="" download >Download</a></div>'); 209 } 210 /* SWP add download button ]]]*/ 211 212 // Disable scrolling of the page while open 213 if (this.options.disableScrolling) { 214 $('body').addClass('lb-disable-scrolling'); 215 } 216 217 this.changeImage(imageNumber); 218 }; 219 220 // Hide most UI elements in preparation for the animated resizing of the lightbox. 221 Lightbox.prototype.changeImage = function(imageNumber) { 222 var self = this; 223 224 this.disableKeyboardNav(); 225 var $image = this.$lightbox.find('.lb-image'); 226 227 this.$overlay.fadeIn(this.options.fadeDuration); 228 229 $('.lb-loader').fadeIn('slow'); 230 this.$lightbox.find('.lb-image, .lb-nav, .lb-prev, .lb-next, .lb-dataContainer, .lb-numbers, .lb-caption').hide(); 231 232 this.$outerContainer.addClass('animating'); 233 234 // When image to show is preloaded, we send the width and height to sizeContainer() 235 var preloader = new Image(); 236 preloader.onload = function() { 237 var $preloader; 238 var imageHeight; 239 var imageWidth; 240 var maxImageHeight; 241 var maxImageWidth; 242 var windowHeight; 243 var windowWidth; 244 245 $image.attr('src', self.album[imageNumber].link); 246 247 $preloader = $(preloader); 248 249 $image.width(preloader.width); 250 $image.height(preloader.height); 251 252 if (self.options.fitImagesInViewport) { 253 // Fit image inside the viewport. 254 // Take into account the border around the image and an additional 10px gutter on each side. 255 256 windowWidth = $(window).width(); 257 windowHeight = $(window).height(); 258 maxImageWidth = windowWidth - self.containerLeftPadding - self.containerRightPadding - 20; 259 maxImageHeight = windowHeight - self.containerTopPadding - self.containerBottomPadding - 120; 260 261 // Check if image size is larger then maxWidth|maxHeight in settings 262 if (self.options.maxWidth && self.options.maxWidth < maxImageWidth) { 263 maxImageWidth = self.options.maxWidth; 264 } 265 if (self.options.maxHeight && self.options.maxHeight < maxImageWidth) { 266 maxImageHeight = self.options.maxHeight; 267 } 268 269 // Is there a fitting issue? 270 if ((preloader.width > maxImageWidth) || (preloader.height > maxImageHeight)) { 271 if ((preloader.width / maxImageWidth) > (preloader.height / maxImageHeight)) { 272 imageWidth = maxImageWidth; 273 imageHeight = parseInt(preloader.height / (preloader.width / imageWidth), 10); 274 $image.width(imageWidth);
275 $image.height(imageHeight); 276 } else { 277 imageHeight = maxImageHeight; 278 imageWidth = parseInt(preloader.width / (preloader.height / imageHeight), 10); 279 $image.width(imageWidth); 280 $image.height(imageHeight); 281 } 282 } 283 } 284 self.sizeContainer($image.width(), $image.height()); 285 }; 286 287 preloader.src = this.album[imageNumber].link; 288 this.currentImageIndex = imageNumber; 289 }; 290 291 // Stretch overlay to fit the viewport 292 Lightbox.prototype.sizeOverlay = function() { 293 this.$overlay 294 .width($(document).width()) 295 .height($(document).height()); 296 }; 297 298 // Animate the size of the lightbox to fit the image we are showing 299 Lightbox.prototype.sizeContainer = function(imageWidth, imageHeight) { 300 var self = this; 301 302 var oldWidth = this.$outerContainer.outerWidth(); 303 var oldHeight = this.$outerContainer.outerHeight(); 304 var newWidth = imageWidth + this.containerLeftPadding + this.containerRightPadding; 305 var newHeight = imageHeight + this.containerTopPadding + this.containerBottomPadding; 306 307 function postResize() { 308 self.$lightbox.find('.lb-dataContainer').width(newWidth); 309 self.$lightbox.find('.lb-prevLink').height(newHeight); 310 self.$lightbox.find('.lb-nextLink').height(newHeight); 311 self.showImage(); 312 } 313 314 if (oldWidth !== newWidth || oldHeight !== newHeight) { 315 this.$outerContainer.animate({ 316 width: newWidth, 317 height: newHeight 318 }, this.options.resizeDuration, 'swing', function() { 319 postResize(); 320 }); 321 } else { 322 postResize(); 323 } 324 }; 325 326 // Display the image and its details and begin preload neighboring images. 327 Lightbox.prototype.showImage = function() { 328 this.$lightbox.find('.lb-loader').stop(true).hide(); 329 this.$lightbox.find('.lb-image').fadeIn('slow'); 330 331 this.updateNav(); 332 this.updateDetails(); 333 this.preloadNeighboringImages(); 334 this.enableKeyboardNav(); 335 }; 336 337 // Display previous and next navigation if appropriate. 338 Lightbox.prototype.updateNav = function() { 339 // Check to see if the browser supports touch events. If so, we take the conservative approach 340 // and assume that mouse hover events are not supported and always show prev/next navigation 341 // arrows in image sets. 342 var alwaysShowNav = false; 343 try { 344 document.createEvent('TouchEvent'); 345 alwaysShowNav = (this.options.alwaysShowNavOnTouchDevices) ? true : false; 346 } catch (e) {} 347 348 this.$lightbox.find('.lb-nav').show(); 349 350 if (this.album.length > 1) { 351 if (this.options.wrapAround) { 352 if (alwaysShowNav) { 353 this.$lightbox.find('.lb-prev, .lb-next').css('opacity', '1'); 354 } 355 this.$lightbox.find('.lb-prev, .lb-next').show(); 356 } else { 357 if (this.currentImageIndex > 0) { 358 this.$lightbox.find('.lb-prev').show(); 359 if (alwaysShowNav) { 360 this.$lightbox.find('.lb-prev').css('opacity', '1'); 361 } 362 } 363 if (this.currentImageIndex < this.album.length - 1) { 364 this.$lightbox.find('.lb-next').show(); 365 if (alwaysShowNav) { 366 this.$lightbox.find('.lb-next').css('opacity', '1'); 367 } 368 } 369 } 370 } 371 }; 372 373 // Display caption, image number, and closing button. 374 Lightbox.prototype.updateDetails = function() { 375 var self = this; 376 377 // Enable anchor clicks in the injected caption html. 378 // Thanks Nate Wright for the fix. @https://github.com/NateWr 379 if (typeof this.album[this.currentImageIndex].title !== 'undefined' && 380 this.album[this.currentImageIndex].title !== '') { 381 this.$lightbox.find('.lb-caption') 382 .html(this.album[this.currentImageIndex].title) 383 .fadeIn('fast') 384 .find('a').on('click', function(event) { 385 if ($(this).attr('target') !== undefined) { 386 window.open($(this).attr('href'), $(this).attr('target')); 387 } else { 388 location.href = $(this).attr('href'); 389 } 390 }); 391 } 392 393 if (this.album.length > 1 && this.options.showImageNumberLabel) { 394 var labelText = this.imageCountLabel(this.currentImageIndex + 1, this.album.length); 395 this.$lightbox.find('.lb-number').text(labelText).fadeIn('fast'); 396 } else { 397 this.$lightbox.find('.lb-number').hide(); 398 } 399 400 this.$outerContainer.removeClass('animating'); 401 402 this.$lightbox.find('.lb-dataContainer').fadeIn(this.options.resizeDuration, function() { 403 return self.sizeOverlay(); 404 });
405 }; 406 407 // Preload previous and next images in set. 408 Lightbox.prototype.preloadNeighboringImages = function() { 409 if (this.album.length > this.currentImageIndex + 1) { 410 var preloadNext = new Image(); 411 preloadNext.src = this.album[this.currentImageIndex + 1].link; 412 } 413 if (this.currentImageIndex > 0) { 414 var preloadPrev = new Image(); 415 preloadPrev.src = this.album[this.currentImageIndex - 1].link; 416 } 417 }; 418 419 Lightbox.prototype.enableKeyboardNav = function() { 420 $(document).on('keyup.keyboard', $.proxy(this.keyboardAction, this)); 421 }; 422 423 Lightbox.prototype.disableKeyboardNav = function() { 424 $(document).off('.keyboard'); 425 }; 426 427 Lightbox.prototype.keyboardAction = function(event) { 428 var KEYCODE_ESC = 27; 429 var KEYCODE_LEFTARROW = 37; 430 var KEYCODE_RIGHTARROW = 39; 431 432 var keycode = event.keyCode; 433 var key = String.fromCharCode(keycode).toLowerCase(); 434 if (keycode === KEYCODE_ESC || key.match(/x|o|c/)) { 435 this.end(); 436 } else if (key === 'p' || keycode === KEYCODE_LEFTARROW) { 437 if (this.currentImageIndex !== 0) { 438 this.changeImage(this.currentImageIndex - 1); 439 } else if (this.options.wrapAround && this.album.length > 1) { 440 this.changeImage(this.album.length - 1); 441 } 442 } else if (key === 'n' || keycode === KEYCODE_RIGHTARROW) { 443 if (this.currentImageIndex !== this.album.length - 1) { 444 this.changeImage(this.currentImageIndex + 1); 445 } else if (this.options.wrapAround && this.album.length > 1) { 446 this.changeImage(0); 447 } 448 } 449 }; 450 451 // Closing time. :-( 452 Lightbox.prototype.end = function() { 453 this.disableKeyboardNav(); 454 $(window).off('resize', this.sizeOverlay); 455 this.$lightbox.fadeOut(this.options.fadeDuration); 456 this.$overlay.fadeOut(this.options.fadeDuration); 457 $('select, object, embed').css({ 458 visibility: 'visible' 459 }); 460 if (this.options.disableScrolling) { 461 $('body').removeClass('lb-disable-scrolling'); 462 } 463 }; 464 465 /* SWP check if we should show download button [[[ */ 466 function IsDownloadButtonEnabled($link) { 467 var dataShowDownButton = $link.attr('data-download-button'); 468 return (dataShowDownButton && dataShowDownButton==='true') ; 469 } 470 /* SWP check if we should show download button ]]] */ 471 472 return new Lightbox(); 473}));
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.