1/* ------------------------------------------------------------------------ 2 Class: prettyPhoto 3 Use: Lightbox clone for jQuery 4 Author: Stephane Caron (http://www.no-margin-for-errors.com) 5 Version: 3.0 6------------------------------------------------------------------------- */ 7 8(function($) { 9 $.prettyPhoto = {version: '3.0'}; 10 11 $.fn.prettyPhoto = function(pp_settings) { 12 pp_settings = jQuery.extend({ 13 animation_speed: 'fast', /* fast/slow/normal */ 14 slideshow: false, /* false OR interval time in ms */ 15 autoplay_slideshow: false, /* true/false */ 16 opacity: 0.80, /* Value between 0 and 1 */ 17 show_title: true, /* true/false */ 18 allow_resize: true, /* Resize the photos bigger than viewport. true/false */ 19 default_width: 500, 20 default_height: 344, 21 counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */ 22 theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square / facebook */ 23 hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */ 24 wmode: 'opaque', /* Set the flash wmode attribute */ 25 autoplay: true, /* Automatically start videos: True/False */ 26 modal: false, /* If set to true, only the close button will close the window */ 27 overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */ 28 keyboard_shortcuts: true, /* Set to false if you open forms inside prettyPhoto */ 29 changepicturecallback: function(){}, /* Called everytime an item is shown/changed */ 30 callback: function(){}, /* Called when prettyPhoto is closed */ 31 markup: '<div class="pp_pic_holder"> \ 32 <div class="ppt"> </div> \ 33 <div class="pp_top"> \ 34 <div class="pp_left"></div> \ 35 <div class="pp_middle"></div> \ 36 <div class="pp_right"></div> \ 37 </div> \ 38 <div class="pp_content_container"> \ 39 <div class="pp_left"> \ 40 <div class="pp_right"> \ 41 <div class="pp_content"> \ 42 <div class="pp_loaderIcon"></div> \ 43 <div class="pp_fade"> \ 44 <a href="#" class="pp_expand" title="Expand the image">Expand</a> \ 45 <div class="pp_hoverContainer"> \ 46 <a class="pp_next" href="#">next</a> \ 47 <a class="pp_previous" href="#">previous</a> \ 48 </div> \ 49 <div id="pp_full_res"></div> \ 50 <div class="pp_details clearfix"> \ 51 <p class="pp_description"></p> \ 52 <a class="pp_close" href="#">Close</a> \ 53 <div class="pp_nav"> \ 54 <a href="#" class="pp_arrow_previous">Previous</a> \ 55 <p class="currentTextHolder">0/0</p> \ 56 <a href="#" class="pp_arrow_next">Next</a> \ 57 </div> \ 58 </div> \ 59 </div> \ 60 </div> \ 61 </div> \ 62 </div> \ 63 </div> \ 64 <div class="pp_bottom"> \ 65 <div class="pp_left"></div> \ 66 <div class="pp_middle"></div> \ 67 <div class="pp_right"></div> \ 68 </div> \ 69 </div> \ 70 <div class="pp_overlay"></div>', 71 gallery_markup: '<div class="pp_gallery"> \ 72 <a href="#" class="pp_arrow_previous">Previous</a> \ 73 <ul> \ 74 {gallery} \ 75 </ul> \ 76 <a href="#" class="pp_arrow_next">Next</a> \ 77 </div>', 78 image_markup: '<img id="fullResImage" src="" />', 79 flash_markup: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>', 80 quicktime_markup: '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>', 81 iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>', 82 inline_markup: '<div class="pp_inline clearfix">{content}</div>', 83 custom_markup: '' 84 }, pp_settings); 85 86 // Global variables accessible only by prettyPhoto 87 var matchedObjects = this, percentBased = false, correctSizes, 88 89 // prettyPhoto container specific 90 pp_contentHeight, pp_contentWidth, pp_containerHeight, pp_containerWidth, 91 92 // Window size 93 windowHeight = $(window).height(), windowWidth = $(window).width(), 94 95 // Global elements 96 pp_slideshow; 97 98 doresize = true, scroll_pos = _get_scroll(); 99 100 // Window/Keyboard events 101 $(window).unbind('resize').resize(function(){ _center_overlay(); _resize_overlay(); }); 102 103 if(pp_settings.keyboard_shortcuts) { 104 $(document).unbind('keydown').keydown(function(e){ 105 if(typeof $pp_pic_holder != 'undefined'){ 106 if($pp_pic_holder.is(':visible')){ 107 switch(e.keyCode){ 108 case 37: 109 $.prettyPhoto.changePage('previous'); 110 break; 111 case 39: 112 $.prettyPhoto.changePage('next'); 113 break; 114 case 27: 115 if(!settings.modal) 116 $.prettyPhoto.close(); 117 break; 118 }; 119 return false;
120 }; 121 }; 122 }); 123 } 124 125 126 /** 127 * Initialize prettyPhoto. 128 */ 129 $.prettyPhoto.initialize = function() { 130 settings = pp_settings; 131 132 if($.browser.msie && parseInt($.browser.version) == 6) settings.theme = "light_square"; // Fallback to a supported theme for IE6 133 134 _buildOverlay(this); // Build the overlay {this} being the caller 135 136 if(settings.allow_resize) 137 $(window).scroll(function(){ _center_overlay(); }); 138 139 _center_overlay(); 140 141 set_position = jQuery.inArray($(this).attr('href'), pp_images); // Define where in the array the clicked item is positionned 142 143 $.prettyPhoto.open(); 144 145 return false; 146 } 147 148 149 /** 150 * Opens the prettyPhoto modal box. 151 * @param image {String,Array} Full path to the image to be open, can also be an array containing full images paths. 152 * @param title {String,Array} The title to be displayed with the picture, can also be an array containing all the titles. 153 * @param description {String,Array} The description to be displayed with the picture, can also be an array containing all the descriptions. 154 */ 155 $.prettyPhoto.open = function() { 156 if(typeof settings == "undefined"){ // Means it's an API call, need to manually get the settings and set the variables 157 settings = pp_settings; 158 _buildOverlay(this); // Build the overlay {this} being the caller 159 pp_images = $.makeArray(arguments[0]); 160 pp_titles = (arguments[1]) ? $.makeArray(arguments[1]) : $.makeArray(""); 161 pp_descriptions = (arguments[2]) ? $.makeArray(arguments[2]) : $.makeArray(""); 162 isSet = (pp_images.length > 1) ? true : false; 163 set_position = 0; 164 } 165 166 if($.browser.msie && $.browser.version == 6) $('select').css('visibility','hidden'); // To fix the bug with IE select boxes 167 168 if(settings.hideflash) $('object,embed').css('visibility','hidden'); // Hide the flash 169 170 _checkPosition($(pp_images).size()); // Hide the next/previous links if on first or last images. 171 172 $('.pp_loaderIcon').show(); 173 174 // Fade the content in 175 if($ppt.is(':hidden')) $ppt.css('opacity',0).show(); 176 $pp_overlay.show().fadeTo(settings.animation_speed,settings.opacity); 177 178 // Display the current position 179 $pp_pic_holder.find('.currentTextHolder').text((set_position+1) + settings.counter_separator_label + $(pp_images).size()); 180 181 // Set the description 182 $pp_pic_holder.find('.pp_description').show().html(unescape(pp_descriptions[set_position])); 183 184 // Set the title 185 (settings.show_title && pp_titles[set_position] != "") ? $ppt.html(unescape(pp_titles[set_position])) : $ppt.html(' '); 186 187 // Get the dimensions 188 movie_width = ( parseFloat(grab_param('width',pp_images[set_position])) ) ? grab_param('width',pp_images[set_position]) : settings.default_width.toString(); 189 movie_height = ( parseFloat(grab_param('height',pp_images[set_position])) ) ? grab_param('height',pp_images[set_position]) : settings.default_height.toString(); 190 191 // If the size is % based, calculate according to window dimensions 192 if(movie_width.indexOf('%') != -1 || movie_height.indexOf('%') != -1){ 193 movie_height = parseFloat(($(window).height() * parseFloat(movie_height) / 100) - 100); 194 movie_width = parseFloat(($(window).width() * parseFloat(movie_width) / 100) - 100); 195 percentBased = true; 196 }else{ 197 percentBased = false; 198 } 199 200 // Fade the holder 201 $pp_pic_holder.fadeIn(function(){ 202 imgPreloader = ""; 203 204 // Inject the proper content 205 switch(_getFileType(pp_images[set_position])){ 206 case 'image': 207 imgPreloader = new Image(); 208 209 // Preload the neighbour images 210 nextImage = new Image(); 211 if(isSet && set_position > $(pp_images).size()) nextImage.src = pp_images[set_position + 1]; 212 prevImage = new Image(); 213 if(isSet && pp_images[set_position - 1]) prevImage.src = pp_images[set_position - 1]; 214 215 $pp_pic_holder.find('#pp_full_res')[0].innerHTML = settings.image_markup; 216 $pp_pic_holder.find('#fullResImage').attr('src',pp_images[set_position]); 217 218 imgPreloader.onload = function(){ 219 // Fit item to viewport 220 correctSizes = _fitToViewport(imgPreloader.width,imgPreloader.height); 221 222 _showContent(); 223 }; 224 225 imgPreloader.onerror = function(){ 226 alert('Image cannot be loaded. Make sure the path is correct and image exist.'); 227 $.prettyPhoto.close(); 228 }; 229 230 imgPreloader.src = pp_images[set_position]; 231 break; 232 233 case 'youtube': 234 correctSizes = _fitToViewport(movie_width,movie_height); // Fit item to viewport 235 236 movie = 'http://www.youtube.com/v/'+grab_param('v',pp_images[set_position]); 237 if(settings.autoplay) movie += "&autoplay=1"; 238 239 toInject = settings.flash_markup.replace(/{width}/g,correctSizes['width']).replace(/{height}/g,correctSizes['height']).replace(/{wmode}/g,settings.wmode).replace(/{path}/g,movie); 240 break; 241 242 case 'vimeo': 243 correctSizes = _fitToViewport(movie_width,movie_height); // Fit item to viewport 244 245 movie_id = pp_images[set_position]; 246 var regExp = /http:\/\/(www\.)?vimeo.com\/(\d+)/; 247 var match = movie_id.match(regExp); 248 249 movie = 'http://player.vimeo.com/video/'+ match[2] +'?title=0&byline=0&portrait=0'; 250 if(settings.autoplay) movie += "&autoplay=1;"; 251 252 vimeo_width = correctSizes['width'] + '/embed/?moog_width='+ correctSizes['width']; 253 254 toInject = settings.iframe_markup.replace(/{width}/g,vimeo_width).replace(/{height}/g,correctSizes['height']).replace(/{path}/g,movie); 255 break; 256 257 case 'quicktime': 258 correctSizes = _fitToViewport(movie_width,movie_height); // Fit item to viewport 259 correctSizes['height']+=15; correctSizes['contentHeight']+=15; correctSizes['containerHeight']+=15; // Add space for the control bar 260 261 toInject = settings.quicktime_markup.replace(/{width}/g,correctSizes['width']).replace(/{height}/g,correctSizes['height']).replace(/{wmode}/g,settings.wmode).replace(/{path}
261/g,pp_images[set_position]).replace(/{autoplay}/g,settings.autoplay); 262 break; 263 264 case 'flash': 265 correctSizes = _fitToViewport(movie_width,movie_height); // Fit item to viewport 266 267 flash_vars = pp_images[set_position]; 268 flash_vars = flash_vars.substring(pp_images[set_position].indexOf('flashvars') + 10,pp_images[set_position].length); 269 270 filename = pp_images[set_position]; 271 filename = filename.substring(0,filename.indexOf('?')); 272 273 toInject = settings.flash_markup.replace(/{width}/g,correctSizes['width']).replace(/{height}/g,correctSizes['height']).replace(/{wmode}/g,settings.wmode).replace(/{path}/g,filename+'?'+flash_vars); 274 break; 275 276 case 'iframe': 277 correctSizes = _fitToViewport(movie_width,movie_height); // Fit item to viewport 278 279 frame_url = pp_images[set_position]; 280 frame_url = frame_url.substr(0,frame_url.indexOf('iframe')-1); 281 282 toInject = settings.iframe_markup.replace(/{width}/g,correctSizes['width']).replace(/{height}/g,correctSizes['height']).replace(/{path}/g,frame_url); 283 break; 284 285 case 'custom': 286 correctSizes = _fitToViewport(movie_width,movie_height); // Fit item to viewport 287 288 toInject = settings.custom_markup; 289 break; 290 291 case 'inline': 292 // to get the item height clone it, apply default width, wrap it in the prettyPhoto containers , then delete 293 myClone = $(pp_images[set_position]).clone().css({'width':settings.default_width}).wrapInner('<div id="pp_full_res"><div class="pp_inline clearfix"></div></div>').appendTo($('body')); 294 correctSizes = _fitToViewport($(myClone).width(),$(myClone).height()); 295 $(myClone).remove(); 296 toInject = settings.inline_markup.replace(/{content}/g,$(pp_images[set_position]).html()); 297 break; 298 }; 299 300 if(!imgPreloader){ 301 $pp_pic_holder.find('#pp_full_res')[0].innerHTML = toInject; 302 303 // Show content 304 _showContent(); 305 }; 306 }); 307 308 return false; 309 }; 310 311 312 /** 313 * Change page in the prettyPhoto modal box 314 * @param direction {String} Direction of the paging, previous or next. 315 */ 316 $.prettyPhoto.changePage = function(direction){ 317 currentGalleryPage = 0; 318 319 if(direction == 'previous') { 320 set_position--; 321 if (set_position < 0){ 322 set_position = 0; 323 return; 324 }; 325 }else if(direction == 'next'){ 326 set_position++; 327 if(set_position > $(pp_images).size()-1) { 328 set_position = 0; 329 } 330 }else{ 331 set_position=direction; 332 }; 333 334 if(!doresize) doresize = true; // Allow the resizing of the images 335 $('.pp_contract').removeClass('pp_contract').addClass('pp_expand'); 336 337 _hideContent(function(){ $.prettyPhoto.open(); }); 338 }; 339 340 341 /** 342 * Change gallery page in the prettyPhoto modal box 343 * @param direction {String} Direction of the paging, previous or next. 344 */ 345 $.prettyPhoto.changeGalleryPage = function(direction){ 346 if(direction=='next'){ 347 currentGalleryPage ++; 348 349 if(currentGalleryPage > totalPage){ 350 currentGalleryPage = 0; 351 }; 352 }else if(direction=='previous'){ 353 currentGalleryPage --; 354 355 if(currentGalleryPage < 0){ 356 currentGalleryPage = totalPage; 357 }; 358 }else{ 359 currentGalleryPage = direction; 360 }; 361 362 // Slide the pages, if we're on the last page, find out how many items we need to slide. To make sure we don't have an empty space. 363 itemsToSlide = (currentGalleryPage == totalPage) ? pp_images.length - ((totalPage) * itemsPerPage) : itemsPerPage; 364 365 $pp_pic_holder.find('.pp_gallery li').each(function(i){ 366 $(this).animate({ 367 'left': (i * itemWidth) - ((itemsToSlide * itemWidth) * currentGalleryPage) 368 }); 369 }); 370 }; 371 372 373 /** 374 * Start the slideshow... 375 */ 376 $.prettyPhoto.startSlideshow = function(){ 377 if(typeof pp_slideshow == 'undefined'){ 378 $pp_pic_holder.find('.pp_play').unbind('click').removeClass('pp_play').addClass('pp_pause').click(function(){ 379 $.prettyPhoto.stopSlideshow(); 380 return false; 381 }); 382 pp_slideshow = setInterval($.prettyPhoto.startSlideshow,settings.slideshow); 383 }else{ 384 $.prettyPhoto.changePage('next'); 385 }; 386 } 387 388 389 /** 390 * Stop the slideshow... 391 */ 392 $.prettyPhoto.stopSlideshow = function(){ 393 $pp_pic_holder.find('.pp_pause').unbind('click').removeClass('pp_pause').addClass('pp_play').click(function(){ 394 $.prettyPhoto.startSlideshow(); 395 return false;
396 }); 397 clearInterval(pp_slideshow); 398 pp_slideshow=undefined; 399 } 400 401 402 /** 403 * Closes the prettyPhoto modal box. 404 */ 405 $.prettyPhoto.close = function(){ 406 407 clearInterval(pp_slideshow); 408 409 $pp_pic_holder.stop().find('object,embed').css('visibility','hidden'); 410 411 $('div.pp_pic_holder,div.ppt,.pp_fade').fadeOut(settings.animation_speed,function(){ $(this).remove(); }); 412 413 $pp_overlay.fadeOut(settings.animation_speed, function(){ 414 if($.browser.msie && $.browser.version == 6) $('select').css('visibility','visible'); // To fix the bug with IE select boxes 415 416 if(settings.hideflash) $('object,embed').css('visibility','visible'); // Show the flash 417 418 $(this).remove(); // No more need for the prettyPhoto markup 419 420 $(window).unbind('scroll'); 421 422 settings.callback(); 423 424 doresize = true; 425 426 delete settings; 427 }); 428 }; 429 430 /** 431 * Set the proper sizes on the containers and animate the content in. 432 */ 433 _showContent = function(){ 434 $('.pp_loaderIcon').hide(); 435 436 $ppt.fadeTo(settings.animation_speed,1); 437 438 // Calculate the opened top position of the pic holder 439 projectedTop = scroll_pos['scrollTop'] + ((windowHeight/2) - (correctSizes['containerHeight']/2)); 440 if(projectedTop < 0) projectedTop = 0; 441 442 // Resize the content holder 443 $pp_pic_holder.find('.pp_content').animate({'height':correctSizes['contentHeight']},settings.animation_speed); 444 445 // Resize picture the holder 446 $pp_pic_holder.animate({ 447 'top': projectedTop, 448 'left': (windowWidth/2) - (correctSizes['containerWidth']/2), 449 'width': correctSizes['containerWidth'] 450 },settings.animation_speed,function(){ 451 $pp_pic_holder.find('.pp_hoverContainer,#fullResImage').height(correctSizes['height']).width(correctSizes['width']); 452 453 $pp_pic_holder.find('.pp_fade').fadeIn(settings.animation_speed); // Fade the new content 454 455 // Show the nav 456 if(isSet && _getFileType(pp_images[set_position])=="image") { $pp_pic_holder.find('.pp_hoverContainer').show(); }else{ $pp_pic_holder.find('.pp_hoverContainer').hide(); } 457 458 if(correctSizes['resized']) $('a.pp_expand,a.pp_contract').fadeIn(settings.animation_speed); // Fade the resizing link if the image is resized 459 460 if(settings.autoplay_slideshow && !pp_slideshow) $.prettyPhoto.startSlideshow(); 461 462 settings.changepicturecallback(); // Callback! 463 }); 464 465 _insert_gallery(); 466 }; 467 468 /** 469 * Hide the content...DUH! 470 */ 471 function _hideContent(callback){ 472 // Fade out the current picture 473 $pp_pic_holder.find('#pp_full_res object,#pp_full_res embed').css('visibility','hidden'); 474 $pp_pic_holder.find('.pp_fade').fadeOut(settings.animation_speed,function(){ 475 $('.pp_loaderIcon').show(); 476 477 callback(); 478 }); 479 }; 480 481 /** 482 * Check the item position in the gallery array, hide or show the navigation links 483 * @param setCount {integer} The total number of items in the set 484 */ 485 function _checkPosition(setCount){ 486 // If at the end, hide the next link 487 if(set_position == setCount-1) { 488 $pp_pic_holder.find('a.pp_next').css('visibility','hidden'); 489 $pp_pic_holder.find('a.pp_next').addClass('disabled').unbind('click'); 490 }else{ 491 $pp_pic_holder.find('a.pp_next').css('visibility','visible'); 492 $pp_pic_holder.find('a.pp_next.disabled').removeClass('disabled').bind('click',function(){ 493 $.prettyPhoto.changePage('next'); 494 return false; 495 }); 496 }; 497 498 // If at the beginning, hide the previous link 499 if(set_position == 0) { 500 $pp_pic_holder 501 .find('a.pp_previous') 502 .css('visibility','hidden') 503 .addClass('disabled') 504 .unbind('click'); 505 }else{ 506 $pp_pic_holder.find('a.pp_previous.disabled') 507 .css('visibility','visible') 508 .removeClass('disabled') 509 .bind('click',function(){ 510 $.prettyPhoto.changePage('previous'); 511 return false; 512 }); 513 }; 514 515 (setCount > 1) ? $('.pp_nav').show() : $('.pp_nav').hide(); // Hide the bottom nav if it's not a set. 516 }; 517 518 /** 519 * Resize the item dimensions if it's bigger than the viewport 520 * @param width {integer} Width of the item to be opened 521 * @param height {integer} Height of the item to be opened 522 * @return An array containin the "fitted" dimensions 523 */ 524 function _fitToViewport(width,height){ 525 resized = false;
526 527 _getDimensions(width,height); 528 529 // Define them in case there's no resize needed 530 imageWidth = width, imageHeight = height; 531 532 if( ((pp_containerWidth > windowWidth) || (pp_containerHeight > windowHeight)) && doresize && settings.allow_resize && !percentBased) { 533 resized = true, fitting = false; 534 535 while (!fitting){ 536 if((pp_containerWidth > windowWidth)){ 537 imageWidth = (windowWidth - 200); 538 imageHeight = (height/width) * imageWidth; 539 }else if((pp_containerHeight > windowHeight)){ 540 imageHeight = (windowHeight - 200); 541 imageWidth = (width/height) * imageHeight; 542 }else{ 543 fitting = true; 544 }; 545 546 pp_containerHeight = imageHeight, pp_containerWidth = imageWidth; 547 }; 548 549 _getDimensions(imageWidth,imageHeight); 550 }; 551 552 return { 553 width:Math.floor(imageWidth), 554 height:Math.floor(imageHeight), 555 containerHeight:Math.floor(pp_containerHeight), 556 containerWidth:Math.floor(pp_containerWidth) + 40, // 40 behind the side padding 557 contentHeight:Math.floor(pp_contentHeight), 558 contentWidth:Math.floor(pp_contentWidth), 559 resized:resized 560 }; 561 }; 562 563 /** 564 * Get the containers dimensions according to the item size 565 * @param width {integer} Width of the item to be opened 566 * @param height {integer} Height of the item to be opened 567 */ 568 function _getDimensions(width,height){ 569 width = parseFloat(width); 570 height = parseFloat(height); 571 572 // Get the details height, to do so, I need to clone it since it's invisible 573 $pp_details = $pp_pic_holder.find('.pp_details'); 574 $pp_details.width(width); 575 detailsHeight = parseFloat($pp_details.css('marginTop')) + parseFloat($pp_details.css('marginBottom')); 576 $pp_details = $pp_details.clone().appendTo($('body')).css({ 577 'position':'absolute', 578 'top':-10000 579 }); 580 detailsHeight += $pp_details.height(); 581 detailsHeight = (detailsHeight <= 34) ? 36 : detailsHeight; // Min-height for the details 582 if($.browser.msie && $.browser.version==7) detailsHeight+=8; 583 $pp_details.remove(); 584 585 // Get the container size, to resize the holder to the right dimensions 586 pp_contentHeight = height + detailsHeight; 587 pp_contentWidth = width; 588 pp_containerHeight = pp_contentHeight + $ppt.height() + $pp_pic_holder.find('.pp_top').height() + $pp_pic_holder.find('.pp_bottom').height(); 589 pp_containerWidth = width; 590 } 591 592 function _getFileType(itemSrc){ 593 if (itemSrc.match(/youtube\.com\/watch/i)) { 594 return 'youtube'; 595 }else if (itemSrc.match(/vimeo\.com/i)) { 596 return 'vimeo'; 597 }else if(itemSrc.indexOf('.mov') != -1){ 598 return 'quicktime'; 599 }else if(itemSrc.indexOf('.swf') != -1){ 600 return 'flash'; 601 }else if(itemSrc.indexOf('iframe') != -1){ 602 return 'iframe'; 603 }else if(itemSrc.indexOf('custom') != -1){ 604 return 'custom'; 605 }else if(itemSrc.substr(0,1) == '#'){ 606 return 'inline'; 607 }else{ 608 return 'image'; 609 }; 610 }; 611 612 function _center_overlay(){ 613 if(doresize && typeof $pp_pic_holder != 'undefined') { 614 scroll_pos = _get_scroll(); 615 616 titleHeight = $ppt.height(), contentHeight = $pp_pic_holder.height(), contentwidth = $pp_pic_holder.width(); 617 618 projectedTop = (windowHeight/2) + scroll_pos['scrollTop'] - (contentHeight/2); 619 620 $pp_pic_holder.css({ 621 'top': projectedTop, 622 'left': (windowWidth/2) + scroll_pos['scrollLeft'] - (contentwidth/2) 623 }); 624 }; 625 }; 626 627 function _get_scroll(){ 628 if (self.pageYOffset) { 629 return {scrollTop:self.pageYOffset,scrollLeft:self.pageXOffset}; 630 } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict 631 return {scrollTop:document.documentElement.scrollTop,scrollLeft:document.documentElement.scrollLeft}; 632 } else if (document.body) {// all other Explorers 633 return {scrollTop:document.body.scrollTop,scrollLeft:document.body.scrollLeft}; 634 }; 635 }; 636 637 function _resize_overlay() { 638 windowHeight = $(window).height(), windowWidth = $(window).width(); 639 640 if(typeof $pp_overlay != "undefined") $pp_overlay.height($(document).height()); 641 }; 642 643 function _insert_gallery(){ 644 if(isSet && settings.overlay_gallery && _getFileType(pp_images[set_position])=="image") { 645 itemWidth = 52+5; // 52 beign the thumb width, 5 being the right margin. 646 navWidth = (settings.theme == "facebook") ? 58 : 38; // Define the arrow width depending on the theme 647 648 itemsPerPage = Math.floor((correctSizes['containerWidth'] - 100 - navWidth) / itemWidth); 649 itemsPerPage = (itemsPerPage < pp_images.length) ? itemsPerPage : pp_images.length;
650 totalPage = Math.ceil(pp_images.length / itemsPerPage) - 1; 651 652 // Hide the nav in the case there's no need for links 653 if(totalPage == 0){ 654 navWidth = 0; // No nav means no width! 655 $pp_pic_holder.find('.pp_gallery .pp_arrow_next,.pp_gallery .pp_arrow_previous').hide(); 656 }else{ 657 $pp_pic_holder.find('.pp_gallery .pp_arrow_next,.pp_gallery .pp_arrow_previous').show(); 658 }; 659 660 galleryWidth = itemsPerPage * itemWidth + navWidth; 661 662 // Set the proper width to the gallery items 663 $pp_pic_holder.find('.pp_gallery') 664 .width(galleryWidth) 665 .css('margin-left',-(galleryWidth/2)); 666 667 $pp_pic_holder 668 .find('.pp_gallery ul') 669 .width(itemsPerPage * itemWidth) 670 .find('li.selected') 671 .removeClass('selected'); 672 673 goToPage = (Math.floor(set_position/itemsPerPage) <= totalPage) ? Math.floor(set_position/itemsPerPage) : totalPage; 674 675 676 if(itemsPerPage) { 677 $pp_pic_holder.find('.pp_gallery').hide().show().removeClass('disabled'); 678 }else{ 679 $pp_pic_holder.find('.pp_gallery').hide().addClass('disabled'); 680 } 681 682 $.prettyPhoto.changeGalleryPage(goToPage); 683 684 $pp_pic_holder 685 .find('.pp_gallery ul li:eq('+set_position+')') 686 .addClass('selected'); 687 }else{ 688 $pp_pic_holder.find('.pp_content').unbind('mouseenter mouseleave'); 689 $pp_pic_holder.find('.pp_gallery').hide(); 690 } 691 } 692 693 function _buildOverlay(caller){ 694 // Find out if the picture is part of a set 695 theRel = $(caller).attr('rel'); 696 galleryRegExp = /\[(?:.*)\]/; 697 isSet = (galleryRegExp.exec(theRel)) ? true : false; 698 699 // Put the SRCs, TITLEs, ALTs into an array. 700 pp_images = (isSet) ? jQuery.map(matchedObjects, function(n, i){ if($(n).attr('rel').indexOf(theRel) != -1) return $(n).attr('href'); }) : $.makeArray($(caller).attr('href')); 701 pp_titles = (isSet) ? jQuery.map(matchedObjects, function(n, i){ if($(n).attr('rel').indexOf(theRel) != -1) return ($(n).find('img').attr('alt')) ? $(n).find('img').attr('alt') : ""; }) : $.makeArray($(caller).find('img').attr('alt')); 702 pp_descriptions = (isSet) ? jQuery.map(matchedObjects, function(n, i){ if($(n).attr('rel').indexOf(theRel) != -1) return ($(n).attr('title')) ? $(n).attr('title') : ""; }) : $.makeArray($(caller).attr('title')); 703 704 $('body').append(settings.markup); // Inject the markup 705 706 $pp_pic_holder = $('.pp_pic_holder') , $ppt = $('.ppt'), $pp_overlay
706= $('div.pp_overlay'); // Set my global selectors 707 708 // Inject the inline gallery! 709 if(isSet && settings.overlay_gallery) { 710 currentGalleryPage = 0; 711 toInject = ""; 712 for (var i=0; i < pp_images.length; i++) { 713 var regex = new RegExp("(.*?)\.(jpg|jpeg|png|gif)$"); 714 var results = regex.exec( pp_images[i] ); 715 if(!results){ 716 classname = 'default'; 717 }else{ 718 classname = ''; 719 } 720 toInject += "<li class='"+classname+"'><a href='#'><img src='" + pp_images[i] + "' width='50' alt='' /></a></li>"; 721 }; 722 723 toInject = settings.gallery_markup.replace(/{gallery}/g,toInject); 724 725 $pp_pic_holder.find('#pp_full_res').after(toInject); 726 727 $pp_pic_holder.find('.pp_gallery .pp_arrow_next').click(function(){ 728 $.prettyPhoto.changeGalleryPage('next'); 729 $.prettyPhoto.stopSlideshow(); 730 return false; 731 }); 732 733 $pp_pic_holder.find('.pp_gallery .pp_arrow_previous').click(function(){ 734 $.prettyPhoto.changeGalleryPage('previous'); 735 $.prettyPhoto.stopSlideshow(); 736 return false; 737 }); 738 739 $pp_pic_holder.find('.pp_content').hover( 740 function(){ 741 $pp_pic_holder.find('.pp_gallery:not(.disabled)').fadeIn(); 742 }, 743 function(){ 744 $pp_pic_holder.find('.pp_gallery:not(.disabled)').fadeOut(); 745 }); 746 747 itemWidth = 52+5; // 52 beign the thumb width, 5 being the right margin. 748 $pp_pic_holder.find('.pp_gallery ul li').each(function(i){ 749 $(this).css({ 750 'position':'absolute', 751 'left': i * itemWidth 752 }); 753 754 $(this).find('a').unbind('click').click(function(){ 755 $.prettyPhoto.changePage(i); 756 $.prettyPhoto.stopSlideshow(); 757 return false; 758 }); 759 }); 760 }; 761 762 763 // Inject the play/pause if it's a slideshow 764 if(settings.slideshow){ 765 $pp_pic_holder.find('.pp_nav').prepend('<a href="#" class="pp_play">Play</a>') 766 $pp_pic_holder.find('.pp_nav .pp_play').click(function(){ 767 $.prettyPhoto.startSlideshow(); 768 return false; 769 }); 770 } 771 772 $pp_pic_holder.attr('class','pp_pic_holder ' + settings.theme); // Set the proper theme 773 774 $pp_overlay 775 .css({ 776 'opacity':0, 777 'height':$(document).height(), 778 'width':$(document).width() 779 }) 780 .bind('click',function(){ 781 if(!settings.modal) $.prettyPhoto.close(); 782 }); 783 784 $('a.pp_close').bind('click',function(){ $.prettyPhoto.close(); return false; }); 785 786 $('a.pp_expand').bind('click',function(e){ 787 // Expand the image 788 if($(this).hasClass('pp_expand')){ 789 $(this).removeClass('pp_expand').addClass('pp_contract'); 790 doresize = false; 791 }else{ 792 $(this).removeClass('pp_contract').addClass('pp_expand'); 793 doresize = true; 794 }; 795 796 _hideContent(function(){ $.prettyPhoto.open(); }); 797 798 return false; 799 }); 800 801 $pp_pic_holder.find('.pp_previous, .pp_nav .pp_arrow_previous').bind('click',function(){ 802 $.prettyPhoto.changePage('previous'); 803 $.prettyPhoto.stopSlideshow(); 804 return false; 805 }); 806 807 $pp_pic_holder.find('.pp_next, .pp_nav .pp_arrow_next').bind('click',function(){ 808 $.prettyPhoto.changePage('next'); 809 $.prettyPhoto.stopSlideshow(); 810 return false; 811 }); 812 813 _center_overlay(); // Center it 814 }; 815 816 return this.unbind('click').click($.prettyPhoto.initialize); // Return the jQuery object for chaining. The unbind method is used to avoid click conflict when the plugin is called more than once 817 }; 818 819 function grab_param(name,url){ 820 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 821 var regexS = "[\\?&]"+name+"=([^&#]*)"; 822 var regex = new RegExp( regexS ); 823 var results = regex.exec( url ); 824 return ( results == null ) ? "" : results[1]; 825 } 826 827})(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.