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