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