1// ----------------------------------------------------------------------------------- 2// 3// Lightbox v2.05 4// by Lokesh Dhakar - http://www.lokeshdhakar.com 5// Last Modification: 3/18/11 6// 7// For more information, visit: 8// http://lokeshdhakar.com/projects/lightbox2/ 9// 10// Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/ 11// - Free for use in both personal and commercial projects 12// - Attribution requires leaving author name, author link, and the license info intact. 13// 14// Thanks: 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 ver of proto-aculous. 16// 17// ----------------------------------------------------------------------------------- 18/* 19 20 Table of Contents 21 ----------------- 22 Configuration 23 24 Lightbox Class Declaration 25 - initialize() 26 - updateImageList() 27 - start() 28 - changeImage() 29 - resizeImageContainer() 30 - showImage() 31 - updateDetails() 32 - updateNav() 33 - enableKeyboardNav() 34 - disableKeyboardNav() 35 - keyboardAction() 36 - preloadNeighborImages() 37 - end() 38 39 Function Calls 40 - document.observe() 41 42*/ 43// ----------------------------------------------------------------------------------- 44 45// 46// Configurationl 47// 48LightboxOptions = Object.extend({ 49 fileLoadingImage: 'https://uni-plovdiv.bg/templates/default/js/lightbox/images/loading.gif', 50 fileBottomNavCloseImage: 'https://uni-plovdiv.bg/templates/default/js/lightbox/images/closelabel.gif', 51 52 overlayOpacity: 0.8, // controls transparency of shadow overlay 53 54 animate: true, // toggles resizing animations 55 resizeSpeed: 7, // controls the speed of the image resizing animations (1=slowest and 10=fastest) 56 57 borderSize: 10, //if you adjust the padding in the CSS, you will need to update this variable 58 59 // When grouping images this is used to write: Image # of #. 60 // Change it for non-english localization 61 labelImage: "Image", 62 labelOf: "of" 63}, window.LightboxOptions || {}); 64 65// ----------------------------------------------------------------------------------- 66 67var Lightbox = Class.create(); 68 69Lightbox.prototype = { 70 imageArray: [], 71 activeImage: undefined, 72 73 // initialize() 74 // Constructor runs on completion of the DOM loading. Calls updateImageList and then 75 // the function inserts html at the bottom of the page which is used to display the shadow 76 // overlay and the image container. 77 // 78 initialize: function() { 79
80 this.updateImageList(); 81 82 this.keyboardAction = this.keyboardAction.bindAsEventListener(this); 83 84 if (LightboxOptions.resizeSpeed > 10) LightboxOptions.resizeSpeed = 10; 85 if (LightboxOptions.resizeSpeed < 1) LightboxOptions.resizeSpeed = 1; 86 87 this.resizeDuration = LightboxOptions.animate ? ((11 - LightboxOptions.resizeSpeed) * 0.15) : 0; 88 this.overlayDuration = LightboxOptions.animate ? 0.2 : 0; // shadow fade in/out duration 89 90 // When Lightbox starts it will resize itself from 250 by 250 to the current image dimension. 91 // If animations are turned off, it will be hidden as to prevent a flicker of a 92 // white 250 by 250 box. 93 var size = (LightboxOptions.animate ? 250 : 1) + 'px'; 94 95 96 // Code inserts html at the bottom of the page that looks similar to this: 97 // 98 // <div id="overlay"></div> 99 // <div id="lightbox"> 100 // <div id="outerImageContainer"> 101 // <div id="imageContainer"> 102 // <img id="lightboxImage"> 103 // <div style="" id="hoverNav"> 104 // <a href="#" id="prevLink"></a> 105 // <a href="#" id="nextLink"></a> 106 // </div> 107 // <div id="loading"> 108 // <a href="#" id="loadingLink"> 109 // <img src="images/loading.gif"> 110 // </a> 111 // </div> 112 // </div> 113 // </div> 114 // <div id="imageDataContainer"> 115 // <div id="imageData"> 116 // <div id="imageDetails"> 117 // <span id="caption"></span> 118 // <span id="numberDisplay"></span> 119 // </div> 120 // <div id="bottomNav"> 121 // <a href="#" id="bottomNavClose"> 122 // <img src="images/close.gif"> 123 // </a> 124 // </div> 125 // </div> 126 // </div> 127 // </div> 128 129 130 var objBody = $$('body')[0]; 131 132 objBody.appendChild(Builder.node('div',{id:'overlay'})); 133 134 objBody.appendChild(Builder.node('div',{id:'lightbox'}, [ 135 Builder.node('div',{id:'outerImageContainer'}, 136 Builder.node('div',{id:'imageContainer'}, [ 137 Builder.node('img',{id:'lightboxImage'}), 138 Builder.node('div',{id:'hoverNav'}, [ 139 Builder.node('a',{id:'prevLink', href: '#' }), 140 Builder.node('a',{id:'nextLink', href: '#' }) 141 ]), 142 Builder.node('div',{id:'loading'}, 143 Builder.node('a',{id:'loadingLink', href: '#' }, 144 Builder.node('img', {src: LightboxOptions.fileLoadingImage}) 145 ) 146 ) 147 ]) 148 ), 149 Builder.node('div', {id:'imageDataContainer'}, 150 Builder.node('div',{id:'imageData'}, [ 151 Builder.node('div',{id:'imageDetails'}, [ 152 Builder.node('span',{id:'caption'}), 153 Builder.node('span',{id:'numberDisplay'}) 154 ]), 155 Builder.node('div',{id:'bottomNav'}, 156 Builder.node('a',{id:'bottomNavClose', href: '#' }, 157 Builder.node('img', { src: LightboxOptions.fileBottomNavCloseImage }) 158 ) 159 ) 160 ]) 161 ) 162 ])); 163 164 165 $('overlay').hide().observe('click', (function() { this.end(); }).bind(this)); 166 $('lightbox').hide().observe('click', (function(event) { if (event.element().id == 'lightbox') this.end(); }).bind(this)); 167 $('outerImageContainer').setStyle({ width: size, height: size }); 168 $('prevLink').observe('click', (function(event) { event.stop(); this.changeImage(this.activeImage - 1); }).bindAsEventListener(this)); 169 $('nextLink').observe('click', (function(event) { event.stop(); this.changeImage(this.activeImage + 1); }).bindAsEventListener(this)); 170 $('loadingLink').observe('click', (function(event) { event.stop(); this.end(); }).bind(this)); 171 $('bottomNavClose').observe('click', (function(event) { event.stop(); this.end(); }).bind(this)); 172 173 var th = this; 174 (function(){ 175 var ids = 176 'overlay lightbox outerImageContainer imageContainer lightboxImage hoverNav prevLink nextLink loading loadingLink ' + 177 'imageDataContainer imageData imageDetails caption numberDis
177play bottomNav bottomNavClose'; 178 $w(ids).each(function(id){ th[id] = $(id); }); 179 }).defer(); 180 }, 181 182 // 183 // updateImageList() 184 // Loops through anchor tags looking for 'lightbox' references and applies onclick 185 // events to appropriate links. You can rerun after dynamically adding images w/ajax. 186 // 187 updateImageList: function() { 188 this.updateImageList = Prototype.emptyFunction; 189 190 document.observe('click', (function(event){ 191 var target = event.findElement('a[rel^=lightbox]') || event.findElement('area[rel^=lightbox]'); 192 if (target) { 193 event.stop(); 194 this.start(target); 195 } 196 }).bind(this)); 197 }, 198 199 // 200 // start() 201 // Display overlay and lightbox. If image is part of a set, add siblings to imageArray. 202 // 203 start: function(imageLink) { 204 205 $$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' }); 206 207 // stretch overlay to fill page and fade in 208 var arrayPageSize = this.getPageSize(); 209 $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' }); 210 211 new Effect.Appear(this.overlay, { duration: this.overlayDuration, from: 0.0, to: LightboxOptions.overlayOpacity }); 212 213 this.imageArray = []; 214 var imageNum = 0; 215 216 if ((imageLink.getAttribute("rel") == 'lightbox')){ 217 // if image is NOT part of a set, add single image to imageArray 218 this.imageArray.push([imageLink.href, imageLink.title]); 219 } else { 220 // if image is part of a set.. 221 this.imageArray = 222 $$(imageLink.tagName + '[href][rel="' + imageLink.rel + '"]'). 223 collect(function(anchor){ return [anchor.href, anchor.title]; }). 224 uniq(); 225 226 while (this.imageArray[imageNum][0] != imageLink.href) { imageNum++; } 227 } 228 229 // calculate top and left offset for the lightbox 230 var arrayPageScroll = document.viewport.getScrollOffsets(); 231 var lightboxTop = arrayPageScroll[1] + (document.viewport.getHeight() / 10); 232 var lightboxLeft = arrayPageScroll[0]; 233 this.lightbox.setStyle({ top: lightboxTop + 'px', left: lightboxLeft + 'px' }).show(); 234 235 this.changeImage(imageNum); 236 }, 237 238 // 239 // changeImage() 240 // Hide most elements and preload image in preparation for resizing image container. 241 // 242 changeImage: function(imageNum) { 243 244 this.activeImage = imageNum; // update global var 245 246 // hide elements during transition 247 if (LightboxOptions.animate) this.loading.show(); 248 this.lightboxImage.hide(); 249 this.hoverNav.hide(); 250 this.prevLink.hide(); 251 this.nextLink.hide(); 252 // HACK: Opera9 does not currently support scriptaculous opacity and appear fx 253 this.imageDataContainer.setStyle({opacity: .0001}); 254 this.numberDisplay.hide(); 255 256 var imgPreloader = new Image(); 257 258 // once image is preloaded, resize image container 259 imgPreloader.onload = (function(){ 260 this.lightboxImage.src = this.imageArray[this.activeImage][0]; 261 /*Bug Fixed by Andy Scott*/ 262 this.lightboxImage.width = imgPreloader.width; 263 this.lightboxImage.height = imgPreloader.height; 264 /*End of Bug Fix*/ 265 this.resizeImageContainer(imgPreloader.width, imgPreloader.height); 266 }).bind(this); 267 imgPreloader.src = this.imageArray[this.activeImage][0]; 268 }, 269 270 // 271 // resizeImageContainer() 272 // 273 resizeImageContainer: function(imgWidth, imgHeight) { 274 275 // get current width and height 276 var widthCurrent = this.outerImageContainer.getWidth(); 277 var heightCurrent = this.outerImageContainer.getHeight(); 278 279 // get new width and height 280 var widthNew = (imgWidth + LightboxOptions.borderSize * 2); 281 var heightNew = (imgHeight + LightboxOptions.borderSize * 2); 282 283 // scalars based on change from old to new 284 var xScale = (widthNew / widthCurrent) * 100; 285 var yScale = (heightNew / heightCurrent) * 100; 286 287 // calculate size difference between new and old image, and resize if necessary 288 var wDiff = widthCurrent - widthNew;
289 var hDiff = heightCurrent - heightNew; 290 291 if (hDiff != 0) new Effect.Scale(this.outerImageContainer, yScale, {scaleX: false, duration: this.resizeDuration, queue: 'front'}); 292 if (wDiff != 0) new Effect.Scale(this.outerImageContainer, xScale, {scaleY: false, duration: this.resizeDuration, delay: this.resizeDuration}); 293 294 // if new and old image are same size and no scaling transition is necessary, 295 // do a quick pause to prevent image flicker. 296 var timeout = 0; 297 if ((hDiff == 0) && (wDiff == 0)){ 298 timeout = 100; 299 if (Prototype.Browser.IE) timeout = 250; 300 } 301 302 (function(){ 303 this.prevLink.setStyle({ height: imgHeight + 'px' }); 304 this.nextLink.setStyle({ height: imgHeight + 'px' }); 305 this.imageDataContainer.setStyle({ width: widthNew + 'px' }); 306 307 this.showImage(); 308 }).bind(this).delay(timeout / 1000); 309 }, 310 311 // 312 // showImage() 313 // Display image and begin preloading neighbors. 314 // 315 showImage: function(){ 316 this.loading.hide(); 317 new Effect.Appear(this.lightboxImage, { 318 duration: this.resizeDuration, 319 queue: 'end', 320 afterFinish: (function(){ this.updateDetails(); }).bind(this) 321 }); 322 this.preloadNeighborImages(); 323 }, 324 325 // 326 // updateDetails() 327 // Display caption, image number, and bottom nav. 328 // 329 updateDetails: function() { 330 331 this.caption.update(this.imageArray[this.activeImage][1]).show(); 332 333 // if image is part of set display 'Image x of x' 334 if (this.imageArray.length > 1){ 335 this.numberDisplay.update( LightboxOptions.labelImage + ' ' + (this.activeImage + 1) + ' ' + LightboxOptions.labelOf + ' ' + this.imageArray.length).show(); 336 } 337 338 new Effect.Parallel( 339 [ 340 new Effect.SlideDown(this.imageDataContainer, { sync: true, duration: this.resizeDuration, from: 0.0, to: 1.0 }), 341 new Effect.Appear(this.imageDataContainer, { sync: true, duration: this.resizeDuration }) 342 ], 343 { 344 duration: this.resizeDuration, 345 afterFinish: (function() { 346 // update overlay size and update nav 347 var arrayPageSize = this.getPageSize(); 348 this.overlay.setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' }); 349 this.updateNav(); 350 }).bind(this) 351 } 352 ); 353 }, 354 355 // 356 // updateNav() 357 // Display appropriate previous and next hover navigation. 358 // 359 updateNav: function() { 360 361 this.hoverNav.show(); 362 363 // if not first image in set, display prev image button 364 if (this.activeImage > 0) this.prevLink.show(); 365 366 // if not last image in set, display next image button 367 if (this.activeImage < (this.imageArray.length - 1)) this.nextLink.show(); 368 369 this.enableKeyboardNav(); 370 }, 371 372 // 373 // enableKeyboardNav() 374 // 375 enableKeyboardNav: function() { 376 document.observe('keydown', this.keyboardAction); 377 }, 378 379 // 380 // disableKeyboardNav() 381 // 382 disableKeyboardNav: function() { 383 document.stopObserving('keydown', this.keyboardAction); 384 }, 385 386 // 387 // keyboardAction() 388 // 389 keyboardAction: function(event) { 390 var keycode = event.keyCode; 391 392 var escapeKey; 393 if (event.DOM_VK_ESCAPE) { // mozilla 394 escapeKey = event.DOM_VK_ESCAPE; 395 } else { // ie 396 escapeKey = 27; 397 } 398 399 var key = String.fromCharCode(keycode).toLowerCase(); 400 401 if (key.match(/x|o|c/) || (keycode == escapeKey)){ // close lightbox 402 this.end(); 403 } else if ((key == 'p') || (keycode == 37)){ // display previous image 404 if (this.activeImage != 0){ 405 this.disableKeyboardNav(); 406 this.changeImage(this.activeImage - 1); 407 } 408 } else if ((key == 'n') || (keycode == 39)){ // display next image 409 if (this.activeImage != (this.imageArray.length - 1)){ 410 this.disableKeyboardNav(); 411 this.changeImage(this.activeImage + 1); 412 } 413 } 414 }, 415 416 // 417 // preloadNeighborImages() 418 // Preload previous and next images. 419 // 420 preloadNeighborImages: function(){ 421 var preloadNextImage, preloadPrevImage; 422 if (this.imageArray.length > this.activeImage + 1){ 423 preloadNextImage = new Image(); 424 preloadNextImage.src = this.imageArray[this.activeImage + 1][0]; 425 } 426 if (this.activeImage > 0){ 427 preloadPrevImage = new Image(); 428 preloadPrevImage.src = this.imageArray[this.activeImage - 1][0]; 429 } 430 431 }, 432 433 // 434 // end() 435 // 436 end: function() { 437 this.disableKeyboardNav(); 438 this.lightbox.hide(); 439 new Effect.Fade(this.overlay, { duration: this.overlayDuration }); 440 $$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' }); 441 }, 442 443 // 444 // getPageSize() 445 // 446 getPageSize: function() { 447 448 var xScroll, yScroll; 449 450 if (window.innerHeight && window.scrollMaxY) { 451 xScroll = window.innerWidth + window.scrollMaxX; 452 yScroll = window.innerHeight + window.scrollMaxY; 453 } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac 454 xScroll = document.body.scrollWidth; 455 yScroll = document.body.scrollHeight; 456 } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 457 xScroll = document.body.offsetWidth; 458 yScroll = document.body.offsetHeight; 459 } 460 461 var windowWidth, windowHeight; 462
463 if (self.innerHeight) { // all except Explorer 464 if(document.documentElement.clientWidth){ 465 windowWidth = document.documentElement.clientWidth; 466 } else { 467 windowWidth = self.innerWidth; 468 } 469 windowHeight = self.innerHeight; 470 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 471 windowWidth = document.documentElement.clientWidth; 472 windowHeight = document.documentElement.clientHeight; 473 } else if (document.body) { // other Explorers 474 windowWidth = document.body.clientWidth; 475 windowHeight = document.body.clientHeight; 476 } 477 478 // for small pages with total height less then height of the viewport 479 if(yScroll < windowHeight){ 480 pageHeight = windowHeight; 481 } else { 482 pageHeight = yScroll; 483 } 484 485 // for small pages with total width less then width of the viewport 486 if(xScroll < windowWidth){ 487 pageWidth = xScroll; 488 } else { 489 pageWidth = windowWidth; 490 } 491 492 return [pageWidth,pageHeight]; 493 } 494} 495 496document.observe('dom:loaded', function () { new Lightbox(); });
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.