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