1 2(function($){ 3 var opts; 4 5 $.fn.lightbox = function(options){ 6 // build main options 7 opts = $.extend({}, $.fn.lightbox.defaults, options); 8 9 // initalize the lightbox 10 $.fn.lightbox.initialize(); 11 return this.each(function(){ 12 $(this).click(function(){ 13 $(this).lightbox.start(this); 14 return false; 15 }); 16 }); 17 }; 18 19 // lightbox functions 20 $.fn.lightbox.initialize = function(){ 21 $('#overlay').remove(); 22 $('#lightbox').remove(); 23 opts.inprogress = false; 24 var outerImage = '<div id="outerImageContainer"><div id="imageContainer"><img id="lightboxImage" alt="Lightbox Image"><div id="hoverNav"><a href="javascript://" id="prevLink"><span class="sr-only">Previous image</span></a><a href="javascript://" id="nextLink"><span class="sr-only">Next image</span></a></div><div id="loading"><a href="javascript://" id="loadingLink"><img src="' + opts.fileLoadingImage + '" alt="Loading image"></a></div></div></div>'; 25 var imageData = '<div id="imageDataContainer" class="clearfix"><div id="imageData"><div id="imageDetails"><span id="caption"></span><span id="numberDisplay"></span></div><div id="bottomNav">' 26 27 if (opts.displayHelp) 28 imageData += '<span id="helpDisplay">' + opts.strings.help + '</span>'; 29 30 imageData += '<a href="javascript://" id="bottomNavClose" title="' + opts.strings.closeTitle + '"><img src="'+opts.fileBottomNavCloseImage+'" alt="Close image"></a></div></div></div>'; 31 32 var string; 33 34 if (opts.navbarOnTop) { 35 string = '<div id="overlay"></div><div id="lightbox">' + imageData + outerImage + '</div>'; 36 $("body").append(string); 37 $("#imageDataContainer").addClass('ontop'); 38 } else { 39 string = '<div id="overlay"></div><div id="lightbox">' + outerImage + imageData + '</div>'; 40 $("body").append(string); 41 } 42 43 $("#overlay").click(function(){ $.fn.lightbox.end(); }).hide(); 44 $("#lightbox").click(function(){ $.fn.lightbox.end();}).hide(); 45 $("#loadingLink").click(function(){ $.fn.lightbox.end(); return false;}); 46 $("#bottomNavClose").click(function(){ $.fn.lightbox.end(); return false; }); 47 $('#outerImageContainer').width(opts.widthCurrent).height(opts.heightCurrent); 48 $('#imageDataContainer').width(opts.widthCurrent); 49 }; 50 51 $.fn.lightbox.getPageSize = function(){ 52 var xScroll, yScroll; 53 54 if (window.innerHeight && window.scrollMaxY) { 55 xScroll = window.innerWidth + window.scrollMaxX; 56 yScroll = window.innerHeight + window.scrollMaxY; 57 } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac 58 xScroll = document.body.scrollWidth; 59 yScroll = document.body.scrollHeight; 60 } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 61 xScroll = document.body.offsetWidth; 62 yScroll = document.body.offsetHeight; 63 } 64 65 var windowWidth, windowHeight; 66 67 if (self.innerHeight) { // all except Explorer 68 if(document.documentElement.clientWidth){ 69 windowWidth = document.documentElement.clientWidth; 70 } else { 71 windowWidth = self.innerWidth; 72 } 73 windowHeight = self.innerHeight; 74 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 75 windowWidth = document.documentElement.clientWidth; 76 windowHeight = document.documentElement.clientHeight; 77 } else if (document.body) { // other Explorers 78 windowWidth = document.body.clientWidth; 79 windowHeight = document.body.clientHeight; 80 } 81 82 // for small pages with total height less then height of the viewport 83 if(yScroll < windowHeight){ 84 pageHeight = windowHeight; 85 } else { 86 pageHeight = yScroll; 87 } 88 89 90 // for small pages with total width less then width of the viewport 91 if(xScroll < windowWidth){ 92 pageWidth = xScroll; 93 } else { 94 pageWidth = windowWidth; 95 } 96 97 var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight); 98 return arrayPageSize; 99 }; 100 101 102 $.fn.lightbox.getPageScroll = function(){ 103 var xScroll, yScroll; 104 105 if (self.pageYOffset) { 106 yScroll = self.pageYOffset; 107 xScroll = self.pageXOffset; 108 } else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict 109 yScroll = document.documentElement.scrollTop; 110 xScroll = document.documentElement.scrollLeft; 111 } else if (document.body) {// all other Explorers 112 yScroll = document.body.scrollTop; 113 xScroll = document.body.scrollLeft; 114 } 115 116 var arrayPageScroll = new Array(xScroll,yScroll); 117 return arrayPageScroll; 118 }; 119 120 $.fn.lightbox.pause = function(ms){ 121 var date = new Date(); 122 var curDate = null; 123 do{curDate = new Date();} 124 while( curDate - date < ms); 125 }; 126 127 $.fn.lightbox.start = function(imageLink){ 128 129 $("select, embed, object").hide(); 130 var arrayPageSize = $.fn.lightbox.getPageSize(); 131 $("#overlay").hide().css({width: '100%', height: arrayPageSize[1]+'px', opacity : opts.overlayOpacity}).fadeIn(); 132 opts.imageArray = []; 133 imageNum = 0; 134 135 var anchors = document.getElementsByTagName( imageLink.tagName); 136 137 // if image is NOT part of a set.. 138 if(!imageLink.rel || (imageLink.rel == '')){ 139 // add single image to Lightbox.imageArray 140 opts.imageArray.push(new Array(imageLink.href, opts.displayTitle ? imageLink.title : '')); 141 } else { 142 // if image is part of a set.. 143 $("a").each(function(){ 144 if(this.href && (this.rel == imageLink.rel)){ 145 opts.imageArray.push(new Array(this.href, opts.displayTitle ? this.title : '')); 146 } 147 }) 148 149 150 for(i = 0; i < opts.imageArray.length; i++){ 151 for(j = opts.imageArray.length-1; j>i; j--){ 152 if(opts.imageArray[i][0] == opts.imageArray[j][0]){ 153 opts.imageArray.splice(j,1); 154 } 155 } 156 } 157 while(opts.imageArray[imageNum][0] != imageLink.href) { imageNum++;} 158 } 159 160 // calculate top and left offset for the lightbox 161 var arrayPageScroll = $.fn.lightbox.getPageScroll(); 162 var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10); 163 var lightboxLeft = arrayPageScroll[0]; 164 $('#lightbox').css({top: lightboxTop+'px', left: lightboxLeft+'px'}).show(); 165 166 167 if (!opts.slideNavBar) 168 $('#imageData').hide(); 169 170 $.fn.lightbox.changeImage(imageNum); 171 172 }; 173 174 $.fn.lightbox.changeImage = function(imageNum){ 175 if(opts.inprogress == false){ 176 opts.inprogress = true; 177 opts.activeImage = imageNum; // update global var 178 179 // hide elements during transition 180 $('#loading').show(); 181 $('#lightboxImage').hide(); 182 $('#hoverNav').hide(); 183 $('#prevLink').hide(); 184 $('#nextLink').hide(); 185 186 if (opts.slideNavBar) { // delay preloading image until navbar will slide up 187 // $('#imageDataContainer').slideUp(opts.navBarSlideSpeed, $.fn.doChangeImage); 188 $('#imageDataContainer').hide(); 189 $('#imageData').hide(); 190 $.fn.doChangeImage(); 191 } else { 192 $.fn.doChangeImage(); 193 } 194 } 195 }; 196 197 $.fn.doChangeImage = function(){ 198 199 imgPreloader = new Image(); 200 201 // once image is preloaded, resize image container 202 imgPreloader.onload=function(){ 203 var newWidth = imgPreloader.width; 204 var newHeight = imgPreloader.height; 205 206 207 if (opts.fitToScreen) { 208 var arrayPageSize = $.fn.lightbox.getPageSize(); 209 var ratio; 210 var initialPageWidth = arrayPageSize[2] - 2 * opts.borderSize; 211 var initialPageHeight = arrayPageSize[3] - 200; 212 213 if (imgPreloader.height > initialPageHeight) 214 { 215 newWidth = parseInt((initialPageHeight/imgPreloader.height) * imgPreloader.width); 216 newHeight = initialPageHeight; 217 } 218 else if (imgPreloader.width > initialPageWidth) 219 { 220 newHeight = parseInt((initialPageWidth/imgPreloader.width) * imgPreloader.height); 221 newWidth = initialPageWidth; 222 } 223 } 224 225 $('#lightboxImage').attr('src', opts.imageArray[opts.activeImage][0]) 226 .width(newWidth).height(newHeight);
227 $.fn.lightbox.resizeImageContainer(newWidth, newHeight); 228 } 229 230 imgPreloader.src = opts.imageArray[opts.activeImage][0]; 231 } 232 233 $.fn.lightbox.end = function(){ 234 $.fn.lightbox.disableKeyboardNav(); 235 $('#lightbox').hide(); 236 $('#overlay').fadeOut(); 237 $('select, object, embed').show(); 238 }; 239 240 $.fn.lightbox.preloadNeighborImages = function(){ 241 if((opts.imageArray.length - 1) > opts.activeImage){ 242 preloadNextImage = new Image(); 243 preloadNextImage.src = opts.imageArray[opts.activeImage + 1][0]; 244 } 245 if(opts.activeImage > 0){ 246 preloadPrevImage = new Image(); 247 preloadPrevImage.src = opts.imageArray[opts.activeImage - 1][0]; 248 } 249 }; 250 251 $.fn.lightbox.keyboardAction = function(e){ 252 if (e == null) { // ie 253 var keycode = event.keyCode; 254 var escapeKey = 27; 255 } else { // mozilla 256 var keycode = e.keyCode; 257 var escapeKey = e.DOM_VK_ESCAPE; 258 } 259 260 var key = String.fromCharCode(keycode).toLowerCase(); 261 262 if((key == 'x') || (key == 'o') || (key == 'c') || (keycode == escapeKey)){ // close lightbox 263 $.fn.lightbox.end(); 264 } else if((key == 'p') || (keycode == 37)){ // display previous image 265 if(opts.activeImage != 0){ 266 $.fn.lightbox.disableKeyboardNav(); 267 $.fn.lightbox.changeImage(opts.activeImage - 1); 268 } 269 } else if((key == 'n') || (keycode == 39)){ // display next image 270 if(opts.activeImage != (opts.imageArray.length - 1)){ 271 $.fn.lightbox.disableKeyboardNav(); 272 $.fn.lightbox.changeImage(opts.activeImage + 1); 273 } 274 } 275 }; 276 277 $.fn.lightbox.resizeImageContainer = function(imgWidth, imgHeight){ 278 // get current width and height 279 opts.widthCurrent = document.getElementById('outerImageContainer').offsetWidth; 280 opts.heightCurrent = document.getElementById('outerImageContainer').offsetHeight; 281 282 // get new width and height 283 var widthNew = (imgWidth + (opts.borderSize * 2)); 284 var heightNew = (imgHeight + (opts.borderSize * 2)); 285 286 // scalars based on change from old to new 287 opts.xScale = ( widthNew / opts.widthCurrent) * 100; 288 opts.yScale = ( heightNew / opts.heightCurrent) * 100; 289 290 // calculate size difference between new and old image, and resize if necessary 291 wDiff = opts.widthCurrent - widthNew; 292 hDiff = opts.heightCurrent - heightNew; 293 294 $('#imageDataContainer').animate({width: widthNew},opts.resizeSpeed,'linear'); 295 $('#outerImageContainer').animate({width: widthNew},opts.resizeSpeed,'linear',function(){ 296 $('#outerImageContainer').animate({height: heightNew},opts.resizeSpeed,'linear',function(){ 297 $.fn.lightbox.showImage(); 298 }); 299 }); 300 301 302 // if new and old image are same size and no scaling transition is necessary, 303 // do a quick pause to prevent image flicker. 304 if((hDiff == 0) && (wDiff == 0)){ 305 if (jQuery.browser.msie){ $.fn.lightbox.pause(250); } else { $.fn.lightbox.pause(100);} 306 } 307 308 $('#prevLink').height(imgHeight); 309 $('#nextLink').height(imgHeight); 310 }; 311 312 $.fn.lightbox.showImage = function(){ 313 $('#loading').hide(); 314 $('#lightboxImage').fadeIn("fast"); 315 $.fn.lightbox.updateDetails(); 316 $.fn.lightbox.preloadNeighborImages(); 317 318 opts.inprogress = false; 319 }; 320 321 $.fn.lightbox.updateDetails = function(){ 322 323 if(opts.imageArray[opts.activeImage][1]){ 324 $('#caption').html(opts.imageArray[opts.activeImage][1]).show(); 325 } 326 327 // if image is part of set display 'Image x of x' 328 if(opts.imageArray.length > 1){ 329 var nav_html; 330 331 nav_html = opts.strings.image + (opts.activeImage + 1) + opts.strings.of + opts.imageArray.length; 332 333 // display previous / next text links 334 if ((opts.activeImage) > 0) { 335 nav_html = '<a title="' + opts.strings.prevLinkTitle + '" href="#" id="prevLinkText">' + opts.strings.prevLinkText + "</a>" + nav_html; 336 } 337 338 if ((opts.activeImage + 1) < opts.imageArray.length) { 339 nav_html += '<a title="' + opts.strings.nextLinkTitle + '" href="#" id="nextLinkText">' + opts.strings.nextLinkText + "</a>"; 340 } 341 342 $('#numberDisplay').html(nav_html).show(); 343 } 344 345 if (opts.slideNavBar) { 346 $("#imageData").slideDown(opts.navBarSlideSpeed); 347 } else { 348 $("#imageData").show(); 349 } 350 351 var arrayPageSize = $.fn.lightbox.getPageSize(); 352 $('#overlay').height(arrayPageSize[1]); 353 $.fn.lightbox.updateNav(); 354 }; 355 356 $.fn.lightbox.updateNav = function(){ 357 $('#hoverNav').show(); 358 359 // if not first image in set, display prev image button 360 if(opts.activeImage != 0){ 361 $('#prevLink,#prevLinkText').show().click(function(){ 362 $.fn.lightbox.changeImage(opts.activeImage - 1); return false; 363 }); 364 } 365 366 // if not last image in set, display next image button 367 if(opts.activeImage != (opts.imageArray.length - 1)){ 368 $('#nextLink,#nextLinkText').show().click(function(){ 369 370 $.fn.lightbox.changeImage(opts.activeImage +1); return false; 371 }); 372 } 373 374 $.fn.lightbox.enableKeyboardNav(); 375 }; 376 377 378 $.fn.lightbox.enableKeyboardNav = function(){ 379 document.onkeydown = $.fn.lightbox.keyboardAction; 380 }; 381 382 $.fn.lightbox.disableKeyboardNav = function(){ 383 document.onkeydown = ''; 384 }; 385 386 $.fn.lightbox.defaults = { 387 fileLoadingImage : 'images/loading.gif', 388 fileBottomNavCloseImage : 'images/closelabel.gif', 389 overlayOpacity : 0.8, 390 borderSize : 10, 391 imageArray : new Array, 392 activeImage : null, 393 inprogress : false, 394 resizeSpeed : 350, 395 widthCurrent: 250, 396 heightCurrent: 250, 397 xScale : 1, 398 yScale : 1, 399 displayTitle: true, 400 navbarOnTop: false, 401 slideNavBar: false, // slide nav bar up/down between image resizing transitions 402 navBarSlideSpeed: 350, 403 displayHelp: false, 404 strings : { 405 help: ' \u2190 / P - previous image\u00a0\u00a0\u00a0\u00a0\u2192 / N - next image\u00a0\u00a0\u00a0\u00a0ESC / X - close image gallery', 406 prevLinkTitle: 'previous image', 407 nextLinkTitle: 'next image', 408 prevLinkText: '« Previous', 409 nextLinkText: 'Next »', 410 closeTitle: 'close image gallery', 411 image: 'Image ', 412 of: ' of ' 413 }, 414 fitToScreen: false // resize images if they are bigger than window 415 }; 416})(jQuery);
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.