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