1 2/* 3Lightbox v2.51 4by Lokesh Dhakar - http://www.lokeshdhakar.com 5 6For more information, visit: 7http://lokeshdhakar.com/projects/lightbox2/ 8 9Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/ 10- free for use in both personal and commercial projects 11- attribution requires leaving author name, author link, and the license info intact 12 13Thanks 14- Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.com), and Thomas Fuchs(mir.aculo.us) for ideas, libs, and snippets. 15- Artemy Tregubenko (arty.name) for cleanup and help in updating to latest proto-aculous in v2.05. 16 17 18Table of Contents 19================= 20LightboxOptions 21 22Lightbox 23- constructor 24- init 25- enable 26- build 27- start 28- changeImage 29- sizeContainer 30- showImage 31- updateNav 32- updateDetails 33- preloadNeigbhoringImages 34- enableKeyboardNav 35- disableKeyboardNav 36- keyboardAction 37- end 38 39options = new LightboxOptions 40lightbox = new Lightbox options 41*/ 42 43(function() { 44 var $, Lightbox, LightboxOptions; 45 46 $ = jQuery; 47 48 LightboxOptions = (function() { 49 50 function LightboxOptions() { 51 this.fileLoadingImage = etheme_wp_url + '/wp-content/themes/idstore/images/loading.gif'; 52 this.fileCloseImage = etheme_wp_url + '/wp-content/themes/idstore/images/close.png'; 53 this.resizeDuration = 700; 54 this.fadeDuration = 500; 55 this.labelImage = "Image"; 56 this.labelOf = "of"; 57 } 58 59 return LightboxOptions; 60 61 })(); 62 63 Lightbox = (function() { 64 65 function Lightbox(options) { 66 this.options = options; 67 this.album = []; 68 this.currentImageIndex = void 0; 69 this.init(); 70 } 71 72 Lightbox.prototype.init = function() { 73 this.enable(); 74 return this.build(); 75 }; 76 77 Lightbox.prototype.enable = function() { 78 var _this = this; 79 return $('body').on('click', ' a[rel^=lightbox], area[rel^=lightbox]', function(e) { 80 _this.start($(e.currentTarget)); 81 return false; 82 }); 83 }; 84 85 Lightbox.prototype.build = function() { 86 var $lightbox, 87 _this = this; 88 $("<div>", { 89 id: 'lightboxOverlay' 90 }).after($('<div/>', { 91 id: 'lightbox' 92 }).append($('<div/>', { 93 "class": 'lb-dataContainer' 94 }).append($('<div/>', { 95 "class": 'lb-data' 96 }).append($('<div/>', { 97 "class": 'lb-details' 98 }).append($('<span/>', { 99 "class": 'lb-caption' 100 }), $('<span/>', { 101 "class": 'lb-number' 102 })), $('<div/>', { 103 "class": 'lb-closeContainer' 104 }).append($('<a/>', { 105 "class": 'lb-close' 106 })))), $('<div/>', { 107 "class": 'lb-outerContainer' 108 }).append($('<div/>', { 109 "class": 'lb-container' 110 }).append($('<img/>', { 111 "class": 'lb-image' 112 }), $('<div/>', { 113 "class": 'lb-nav' 114 }).append($('<a/>', { 115 "class": 'lb-prev' 116 }), $('<a/>', { 117 "class": 'lb-next' 118 })), $('<div/>', { 119 "class": 'lb-loader' 120 }).append($('<a/>', { 121 "class": 'lb-cancel' 122 }).append($('<img/>', { 123 src: this.options.fileLoadingImage 124 }))))))).appendTo($('body')); 125 $('#lightboxOverlay').hide().on('click', function(e) { 126 _this.end(); 127 return false; 128 }); 129 $lightbox = $('#lightbox'); 130 $lightbox.hide().on('click', function(e) { 131 if ($(e.target).attr('id') === 'lightbox') _this.end(); 132 return false; 133 }); 134 $lightbox.find('.lb-outerContainer').on('click', function(e) { 135 if ($(e.target).attr('id') === 'lightbox') _this.end(); 136 return false; 137 }); 138 $lightbox.find('.lb-prev').on('click', function(e) { 139 _this.changeImage(_this.currentImageIndex - 1); 140 return false; 141 }); 142 $lightbox.find('.lb-next').on('click', function(e) { 143 _this.changeImage(_this.currentImageIndex + 1); 144 return false; 145 }); 146 $lightbox.find('.lb-loader, .lb-close').on('click', function(e) { 147 _this.end(); 148 return false; 149 }); 150 }; 151 152 Lightbox.prototype.start = function($link) { 153 var $lightbox, $window, a, i, imageNumber, left, top, _len, _ref; 154 $(window).on("resize", this.sizeOverlay); 155 $('select, object, embed').css({ 156 visibility: "hidden" 157 }); 158 $('#lightboxOverlay').width($(document).width()).height($(document).height()).fadeIn(this.options.fadeDuration); 159 this.album = []; 160 imageNumber = 0; 161 if ($link.attr('rel') === 'lightbox') { 162 this.album.push({ 163 link: $link.attr('href'), 164 title: $link.attr('title') 165 }); 166 } else { 167 _ref = $($link.prop("tagName") + '[rel="' + $link.attr('rel') + '"]'); 168 for (i = 0, _len = _ref.length; i < _len; i++) { 169 a = _ref[i]; 170 this.album.push({ 171 link: $(a).attr('href'), 172 title: $(a).attr('title') 173 }); 174 if ($(a).attr('href') === $link.attr('href')) imageNumber = i; 175 } 176 } 177 $window = $(window); 178 top = $window.scrollTop() + $window.height() / 10; 179 left = $window.scrollLeft(); 180 $lightbox = $('#lightbox'); 181 $lightbox.css({ 182 top: top + 'px', 183 left: left + 'px' 184 }).fadeIn(this.options.fadeDuration); 185 this.changeImage(imageNumber); 186 }; 187 188 Lightbox.prototype.changeImage = function(imageNumber) { 189 var $image, $lightbox, preloader, 190 _this = this; 191 this.disableKeyboardNav(); 192 $lightbox = $('#lightbox'); 193 $image = $lightbox.find('.lb-image'); 194 this.sizeOverlay(); 195 $('#lightboxOverlay').fadeIn(this.options.fadeDuration); 196 $('.loader').fadeIn('slow'); 197 $lightbox.find('.lb-image, .lb-nav, .lb-prev, .lb-next, .lb-dataContainer, .lb-numbers, .lb-caption').hide(); 198 $lightbox.find('.lb-outerContainer').addClass('animating'); 199 preloader = new Image; 200 preloader.onload = function() { 201 $image.attr('src', _this.album[imageNumber].link); 202 $image.width = preloader.width; 203 $image.height = preloader.height; 204 return _this.sizeContainer(preloader.width, preloader.height); 205 }; 206 preloader.src = this.album[imageNumber].link; 207 this.currentImageIndex = imageNumber; 208 }; 209 210 Lightbox.prototype.sizeOverlay = function() { 211 return $('#lightboxOverlay').width($(document).width()).height($(document).height()); 212 }; 213 214 Lightbox.prototype.sizeContainer = function(imageWidth, imageHeight) { 215 var $container, $lightbox, $outerContainer, containerBottomPadding, containerLeftPadding, containerRightPadding, containerTopPadding, newHeight, newWidth, oldHeight, oldWidth, 216 _this = this; 217 $lightbox = $('#lightbox'); 218 $outerContainer = $lightbox.find('.lb-outerContainer'); 219 oldWidth = $outerContainer.outerWidth(); 220 oldHeight = $outerContainer.outerHeight(); 221 $container = $lightbox.find('.lb-container'); 222 containerTopPadding = parseInt($container.css('padding-top'), 10); 223 containerRightPadding = parseInt($container.css('padding-right'), 10); 224 containerBottomPadding = parseInt($container.css('padding-bottom'), 10); 225 containerLeftPadding = parseInt($container.css('padding-left'), 10); 226 newWidth = imageWidth + containerLeftPadding + containerRightPadding; 227 newHeight = imageHeight + containerTopPadding + containerBottomPadding; 228 if (newWidth !== oldWidth && newHeight !== oldHeight) { 229 $outerContainer.animate({ 230 width: newWidth, 231 height: newHeight 232 }, this.options.resizeDuration, 'swing'); 233 } else if (newWidth !== oldWidth) { 234 $outerContainer.animate({ 235 width: newWidth 236 }, this.options.resizeDuration, 'swing'); 237 } else if (newHeight !== oldHeight) { 238 $outerContainer.animate({ 239 height: newHeight 240 }, this.options.resizeDuration, 'swing'); 241 } 242 setTimeout(function() { 243 $lightbox.find('.lb-dataContainer').width(newWidth); 244 $lightbox.find('.lb-prevLink').height(newHeight); 245 $lightbox.find('.lb-nextLink').height(newHeight); 246 _this.showImage(); 247 }, this.options.resizeDuration); 248 }; 249 250 Lightbox.prototype.showImage = function() { 251 var $lightbox; 252 $lightbox = $('#lightbox'); 253 $lightbox.find('.lb-loader').hide(); 254 $lightbox.find('.lb-image').fadeIn('slow'); 255 this.updateNav(); 256 this.updateDetails(); 257 this.preloadNeighboringImages(); 258 this.enableKeyboardNav(); 259 }; 260 261 Lightbox.prototype.updateNav = function() { 262 var $lightbox; 263 $lightbox = $('#lightbox'); 264 $lightbox.find('.lb-nav').show(); 265 if (this.currentImageIndex > 0) $lightbox.find('.lb-prev').show(); 266 if (this.currentImageIndex < this.album.length - 1) { 267 $lightbox.find('.lb-next').show(); 268 } 269 }; 270 271 Lightbox.prototype.updateDetails = function() { 272 var $lightbox, 273 _this = this; 274 $lightbox = $('#lightbox'); 275 if (typeof this.album[this.currentImageIndex].title !== 'undefined' && this.album[this.currentImageIndex].title !== "") { 276 $lightbox.find('.lb-caption').html(this.album[this.currentImageIndex].title).fadeIn('fast'); 277 } 278 if (this.album.length > 1) { 279 $lightbox.find('.lb-number').html(this.options.labelImage + ' ' + (this.currentImageIndex + 1) + ' ' + this.options.labelOf + ' ' + this.album.length).fadeIn('fast'); 280 } else { 281 $lightbox.find('.lb-number').hide(); 282 } 283 $lightbox.find('.lb-outerContainer').removeClass('animating'); 284 $lightbox.find('.lb-dataContainer').fadeIn(this.resizeDuration, function() { 285 return _this.sizeOverlay(); 286 }); 287 }; 288 289 Lightbox.prototype.preloadNeighboringImages = function() { 290 var preloadNext, preloadPrev; 291 if (this.album.length > this.currentImageIndex + 1) { 292 preloadNext = new Image; 293 preloadNext.src = this.album[this.currentImageIndex + 1].link; 294 } 295 if (this.currentImageIndex > 0) { 296 preloadPrev = new Image; 297 preloadPrev.src = this.album[this.currentImageIndex - 1].link; 298 } 299 }; 300 301 Lightbox.prototype.enableKeyboardNav = function() { 302 $(document).on('keyup.keyboard', $.proxy(this.keyboardAction, this)); 303 }; 304 305 Lightbox.prototype.disableKeyboardNav = function() { 306 $(document).off('.keyboard'); 307 }; 308 309 Lightbox.prototype.keyboardAction = function(event) { 310 var KEYCODE_ESC, KEYCODE_LEFTARROW, KEYCODE_RIGHTARROW, key, keycode; 311 KEYCODE_ESC = 27; 312 KEYCODE_LEFTARROW = 37; 313 KEYCODE_RIGHTARROW = 39; 314 keycode = event.keyCode; 315 key = String.fromCharCode(keycode).toLowerCase(); 316 if (keycode === KEYCODE_ESC || key.match(/x|o|c/)) { 317 this.end(); 318 } else if (key === 'p' || keycode === KEYCODE_LEFTARROW) { 319 if (this.currentImageIndex !== 0) { 320 this.changeImage(this.currentImageIndex - 1); 321 } 322 } else if (key === 'n' || keycode === KEYCODE_RIGHTARROW) { 323 if (this.currentImageIndex !== this.album.length - 1) { 324 this.changeImage(this.currentImageIndex + 1); 325 } 326 } 327 }; 328 329 Lightbox.prototype.end = function() { 330 this.disableKeyboardNav(); 331 $(window).off("resize", this.sizeOverlay); 332 $('#lightbox').fadeOut(this.options.fadeDuration); 333 $('#lightboxOverlay').fadeOut(this.options.fadeDuration); 334 return $('select, object, embed').css({ 335 visibility: "visible" 336 }); 337 }; 338 339 return Lightbox; 340 341 })(); 342 343 $(function() { 344 var lightbox, options; 345 options = new LightboxOptions; 346 return lightbox = new Lightbox(options); 347 }); 348 349}).call(this);
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.