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