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