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