2013-01-30 16:18:36 +00:00
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Class : prettyPhoto
Use : Lightbox clone for jQuery
Author : Stephane Caron ( http : //www.no-margin-for-errors.com)
Version : 3.1 . 5
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * /
( function ( $ ) {
$ . prettyPhoto = { version : '3.1.5' } ;
$ . fn . prettyPhoto = function ( pp _settings ) {
pp _settings = jQuery . extend ( {
hook : 'rel' , /* the attribute tag to use for prettyPhoto hooks. default: 'rel'. For HTML5, use "data-rel" or similar. */
animation _speed : 'fast' , /* fast/slow/normal */
ajaxcallback : function ( ) { } ,
slideshow : 5000 , /* false OR interval time in ms */
autoplay _slideshow : false , /* true/false */
opacity : 0.80 , /* Value between 0 and 1 */
show _title : true , /* true/false */
allow _resize : true , /* Resize the photos bigger than viewport. true/false */
allow _expand : true , /* Allow the user to expand a resized image. true/false */
default _width : 500 ,
default _height : 344 ,
counter _separator _label : '/' , /* The separator for the gallery counter 1 "of" 2 */
theme : 'pp_default' , /* light_rounded / dark_rounded / light_square / dark_square / facebook */
horizontal _padding : 20 , /* The padding on each side of the picture */
hideflash : false , /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
wmode : 'opaque' , /* Set the flash wmode attribute */
autoplay : true , /* Automatically start videos: True/False */
modal : false , /* If set to true, only the close button will close the window */
deeplinking : true , /* Allow prettyPhoto to update the url to enable deeplinking. */
overlay _gallery : true , /* If set to true, a gallery will overlay the fullscreen image on mouse over */
overlay _gallery _max : 30 , /* Maximum number of pictures in the overlay gallery */
2014-03-11 11:14:25 +00:00
keyboard _shortcuts : true , /* Set to false if you open forms inside prettyPhoto */
2013-01-30 16:18:36 +00:00
changepicturecallback : function ( ) { } , /* Called everytime an item is shown/changed */
callback : function ( ) { } , /* Called when prettyPhoto is closed */
ie6 _fallback : true ,
markup : ' < div class = "pp_pic_holder" > \
< div class = "ppt" > & nbsp ; < / d i v > \
< div class = "pp_top" > \
< div class = "pp_left" > < / d i v > \
< div class = "pp_middle" > < / d i v > \
< div class = "pp_right" > < / d i v > \
< / d i v > \
< div class = "pp_content_container" > \
< div class = "pp_left" > \
< div class = "pp_right" > \
< div class = "pp_content" > \
< div class = "pp_loaderIcon" > < / d i v > \
< div class = "pp_fade" > \
< a href = "#" class = "pp_expand" title = "Expand the image" > Expand < / a > \
< div class = "pp_hoverContainer" > \
< a class = "pp_next" href = "#" > next < / a > \
< a class = "pp_previous" href = "#" > previous < / a > \
< / d i v > \
< div id = "pp_full_res" > < / d i v > \
< div class = "pp_details" > \
< div class = "pp_nav" > \
< a href = "#" class = "pp_arrow_previous" > Previous < / a > \
< p class = "currentTextHolder" > 0 / 0 < / p > \
< a href = "#" class = "pp_arrow_next" > Next < / a > \
< / d i v > \
< p class = "pp_description" > < / p > \
< div class = "pp_social" > { pp _social } < / d i v > \
< a class = "pp_close" href = "#" > Close < / a > \
< / d i v > \
< / d i v > \
< / d i v > \
< / d i v > \
< / d i v > \
< / d i v > \
< div class = "pp_bottom" > \
< div class = "pp_left" > < / d i v > \
< div class = "pp_middle" > < / d i v > \
< div class = "pp_right" > < / d i v > \
< / d i v > \
< / d i v > \
< div class = "pp_overlay" > < / d i v > ' ,
gallery _markup : ' < div class = "pp_gallery" > \
< a href = "#" class = "pp_arrow_previous" > Previous < / a > \
< div > \
< ul > \
{ gallery } \
< / u l > \
< / d i v > \
< a href = "#" class = "pp_arrow_next" > Next < / a > \
< / d i v > ' ,
image _markup : '<img id="fullResImage" src="{path}" />' ,
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>' ,
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>' ,
iframe _markup : '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>' ,
inline _markup : '<div class="pp_inline">{content}</div>' ,
custom _markup : '' ,
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 */
} , pp _settings ) ;
// Global variables accessible only by prettyPhoto
var matchedObjects = this , percentBased = false , pp _dimensions , pp _open ,
// prettyPhoto container specific
pp _contentHeight , pp _contentWidth , pp _containerHeight , pp _containerWidth ,
// Window size
windowHeight = $ ( window ) . height ( ) , windowWidth = $ ( window ) . width ( ) ,
// Global elements
pp _slideshow ;
doresize = true , scroll _pos = _get _scroll ( ) ;
// Window/Keyboard events
$ ( window ) . unbind ( 'resize.prettyphoto' ) . bind ( 'resize.prettyphoto' , function ( ) { _center _overlay ( ) ; _resize _overlay ( ) ; } ) ;
if ( pp _settings . keyboard _shortcuts ) {
$ ( document ) . unbind ( 'keydown.prettyphoto' ) . bind ( 'keydown.prettyphoto' , function ( e ) {
if ( typeof $pp _pic _holder != 'undefined' ) {
if ( $pp _pic _holder . is ( ':visible' ) ) {
switch ( e . keyCode ) {
case 37 :
$ . prettyPhoto . changePage ( 'previous' ) ;
e . preventDefault ( ) ;
break ;
case 39 :
$ . prettyPhoto . changePage ( 'next' ) ;
e . preventDefault ( ) ;
break ;
case 27 :
if ( ! settings . modal )
$ . prettyPhoto . close ( ) ;
e . preventDefault ( ) ;
break ;
} ;
// return false;
} ;
} ;
} ) ;
} ;
/ * *
* Initialize prettyPhoto .
* /
$ . prettyPhoto . initialize = function ( ) {
settings = pp _settings ;
if ( settings . theme == 'pp_default' ) settings . horizontal _padding = 16 ;
// Find out if the picture is part of a set
theRel = $ ( this ) . attr ( settings . hook ) ;
galleryRegExp = /\[(?:.*)\]/ ;
isSet = ( galleryRegExp . exec ( theRel ) ) ? true : false ;
// Put the SRCs, TITLEs, ALTs into an array.
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' ) ) ;
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' ) ) ;
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' ) ) ;
if ( pp _images . length > settings . overlay _gallery _max ) settings . overlay _gallery = false ;
set _position = jQuery . inArray ( $ ( this ) . attr ( 'href' ) , pp _images ) ; // Define where in the array the clicked item is positionned
rel _index = ( isSet ) ? set _position : $ ( "a[" + settings . hook + "^='" + theRel + "']" ) . index ( $ ( this ) ) ;
_build _overlay ( this ) ; // Build the overlay {this} being the caller
if ( settings . allow _resize )
$ ( window ) . bind ( 'scroll.prettyphoto' , function ( ) { _center _overlay ( ) ; } ) ;
$ . prettyPhoto . open ( ) ;
return false ;
}
/ * *
* Opens the prettyPhoto modal box .
* @ param image { String , Array } Full path to the image to be open , can also be an array containing full images paths .
* @ param title { String , Array } The title to be displayed with the picture , can also be an array containing all the titles .
* @ param description { String , Array } The description to be displayed with the picture , can also be an array containing all the descriptions .
* /
$ . prettyPhoto . open = function ( event ) {
if ( typeof settings == "undefined" ) { // Means it's an API call, need to manually get the settings and set the variables
settings = pp _settings ;
pp _images = $ . makeArray ( arguments [ 0 ] ) ;
pp _titles = ( arguments [ 1 ] ) ? $ . makeArray ( arguments [ 1 ] ) : $ . makeArray ( "" ) ;
pp _descriptions = ( arguments [ 2 ] ) ? $ . makeArray ( arguments [ 2 ] ) : $ . makeArray ( "" ) ;
isSet = ( pp _images . length > 1 ) ? true : false ;
set _position = ( arguments [ 3 ] ) ? arguments [ 3 ] : 0 ;
_build _overlay ( event . target ) ; // Build the overlay {this} being the caller
}
if ( settings . hideflash ) $ ( 'object,embed,iframe[src*=youtube],iframe[src*=vimeo]' ) . css ( 'visibility' , 'hidden' ) ; // Hide the flash
_checkPosition ( $ ( pp _images ) . size ( ) ) ; // Hide the next/previous links if on first or last images.
$ ( '.pp_loaderIcon' ) . show ( ) ;
if ( settings . deeplinking )
setHashtag ( ) ;
// Rebuild Facebook Like Button with updated href
if ( settings . social _tools ) {
facebook _like _link = settings . social _tools . replace ( '{location_href}' , encodeURIComponent ( location . href ) ) ;
$pp _pic _holder . find ( '.pp_social' ) . html ( facebook _like _link ) ;
}
// Fade the content in
if ( $ppt . is ( ':hidden' ) ) $ppt . css ( 'opacity' , 0 ) . show ( ) ;
$pp _overlay . show ( ) . fadeTo ( settings . animation _speed , settings . opacity ) ;
// Display the current position
$pp _pic _holder . find ( '.currentTextHolder' ) . text ( ( set _position + 1 ) + settings . counter _separator _label + $ ( pp _images ) . size ( ) ) ;
// Set the description
if ( typeof pp _descriptions [ set _position ] != 'undefined' && pp _descriptions [ set _position ] != "" ) {
$pp _pic _holder . find ( '.pp_description' ) . show ( ) . html ( unescape ( pp _descriptions [ set _position ] ) ) ;
} else {
$pp _pic _holder . find ( '.pp_description' ) . hide ( ) ;
}
// Get the dimensions
movie _width = ( parseFloat ( getParam ( 'width' , pp _images [ set _position ] ) ) ) ? getParam ( 'width' , pp _images [ set _position ] ) : settings . default _width . toString ( ) ;
movie _height = ( parseFloat ( getParam ( 'height' , pp _images [ set _position ] ) ) ) ? getParam ( 'height' , pp _images [ set _position ] ) : settings . default _height . toString ( ) ;
// If the size is % based, calculate according to window dimensions
percentBased = false ;
if ( movie _height . indexOf ( '%' ) != - 1 ) { movie _height = parseFloat ( ( $ ( window ) . height ( ) * parseFloat ( movie _height ) / 100 ) - 150 ) ; percentBased = true ; }
if ( movie _width . indexOf ( '%' ) != - 1 ) { movie _width = parseFloat ( ( $ ( window ) . width ( ) * parseFloat ( movie _width ) / 100 ) - 150 ) ; percentBased = true ; }
// Fade the holder
$pp _pic _holder . fadeIn ( function ( ) {
// Set the title
( settings . show _title && pp _titles [ set _position ] != "" && typeof pp _titles [ set _position ] != "undefined" ) ? $ppt . html ( unescape ( pp _titles [ set _position ] ) ) : $ppt . html ( ' ' ) ;
imgPreloader = "" ;
skipInjection = false ;
// Inject the proper content
switch ( _getFileType ( pp _images [ set _position ] ) ) {
case 'image' :
imgPreloader = new Image ( ) ;
// Preload the neighbour images
nextImage = new Image ( ) ;
if ( isSet && set _position < $ ( pp _images ) . size ( ) - 1 ) nextImage . src = pp _images [ set _position + 1 ] ;
prevImage = new Image ( ) ;
if ( isSet && pp _images [ set _position - 1 ] ) prevImage . src = pp _images [ set _position - 1 ] ;
$pp _pic _holder . find ( '#pp_full_res' ) [ 0 ] . innerHTML = settings . image _markup . replace ( /{path}/g , pp _images [ set _position ] ) ;
imgPreloader . onload = function ( ) {
// Fit item to viewport
pp _dimensions = _fitToViewport ( imgPreloader . width , imgPreloader . height ) ;
_showContent ( ) ;
} ;
imgPreloader . onerror = function ( ) {
alert ( 'Image cannot be loaded. Make sure the path is correct and image exist.' ) ;
$ . prettyPhoto . close ( ) ;
} ;
imgPreloader . src = pp _images [ set _position ] ;
break ;
case 'youtube' :
pp _dimensions = _fitToViewport ( movie _width , movie _height ) ; // Fit item to viewport
// Regular youtube link
movie _id = getParam ( 'v' , pp _images [ set _position ] ) ;
// youtu.be link
if ( movie _id == "" ) {
movie _id = pp _images [ set _position ] . split ( 'youtu.be/' ) ;
movie _id = movie _id [ 1 ] ;
if ( movie _id . indexOf ( '?' ) > 0 )
movie _id = movie _id . substr ( 0 , movie _id . indexOf ( '?' ) ) ; // Strip anything after the ?
if ( movie _id . indexOf ( '&' ) > 0 )
movie _id = movie _id . substr ( 0 , movie _id . indexOf ( '&' ) ) ; // Strip anything after the &
}
movie = 'http://www.youtube.com/embed/' + movie _id ;
( getParam ( 'rel' , pp _images [ set _position ] ) ) ? movie += "?rel=" + getParam ( 'rel' , pp _images [ set _position ] ) : movie += "?rel=1" ;
if ( settings . autoplay ) movie += "&autoplay=1" ;
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 ) ;
break ;
case 'vimeo' :
pp _dimensions = _fitToViewport ( movie _width , movie _height ) ; // Fit item to viewport
movie _id = pp _images [ set _position ] ;
var regExp = /http(s?):\/\/(www\.)?vimeo.com\/(\d+)/ ;
var match = movie _id . match ( regExp ) ;
movie = 'http://player.vimeo.com/video/' + match [ 3 ] + '?title=0&byline=0&portrait=0' ;
if ( settings . autoplay ) movie += "&autoplay=1;" ;
vimeo _width = pp _dimensions [ 'width' ] + '/embed/?moog_width=' + pp _dimensions [ 'width' ] ;
toInject = settings . iframe _markup . replace ( /{width}/g , vimeo _width ) . replace ( /{height}/g , pp _dimensions [ 'height' ] ) . replace ( /{path}/g , movie ) ;
break ;
case 'quicktime' :
pp _dimensions = _fitToViewport ( movie _width , movie _height ) ; // Fit item to viewport
pp _dimensions [ 'height' ] += 15 ; pp _dimensions [ 'contentHeight' ] += 15 ; pp _dimensions [ 'containerHeight' ] += 15 ; // Add space for the control bar
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 ) ;
break ;
case 'flash' :
pp _dimensions = _fitToViewport ( movie _width , movie _height ) ; // Fit item to viewport
flash _vars = pp _images [ set _position ] ;
flash _vars = flash _vars . substring ( pp _images [ set _position ] . indexOf ( 'flashvars' ) + 10 , pp _images [ set _position ] . length ) ;
filename = pp _images [ set _position ] ;
filename = filename . substring ( 0 , filename . indexOf ( '?' ) ) ;
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 ) ;
break ;
case 'iframe' :
pp _dimensions = _fitToViewport ( movie _width , movie _height ) ; // Fit item to viewport
frame _url = pp _images [ set _position ] ;
frame _url = frame _url . substr ( 0 , frame _url . indexOf ( 'iframe' ) - 1 ) ;
toInject = settings . iframe _markup . replace ( /{width}/g , pp _dimensions [ 'width' ] ) . replace ( /{height}/g , pp _dimensions [ 'height' ] ) . replace ( /{path}/g , frame _url ) ;
break ;
case 'ajax' :
doresize = false ; // Make sure the dimensions are not resized.
pp _dimensions = _fitToViewport ( movie _width , movie _height ) ;
doresize = true ; // Reset the dimensions
skipInjection = true ;
$ . get ( pp _images [ set _position ] , function ( responseHTML ) {
toInject = settings . inline _markup . replace ( /{content}/g , responseHTML ) ;
$pp _pic _holder . find ( '#pp_full_res' ) [ 0 ] . innerHTML = toInject ;
_showContent ( ) ;
} ) ;
break ;
case 'custom' :
pp _dimensions = _fitToViewport ( movie _width , movie _height ) ; // Fit item to viewport
toInject = settings . custom _markup ;
break ;
case 'inline' :
// to get the item height clone it, apply default width, wrap it in the prettyPhoto containers , then delete
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 ( ) ;
doresize = false ; // Make sure the dimensions are not resized.
pp _dimensions = _fitToViewport ( $ ( myClone ) . width ( ) , $ ( myClone ) . height ( ) ) ;
doresize = true ; // Reset the dimensions
$ ( myClone ) . remove ( ) ;
toInject = settings . inline _markup . replace ( /{content}/g , $ ( pp _images [ set _position ] ) . html ( ) ) ;
break ;
} ;
if ( ! imgPreloader && ! skipInjection ) {
$pp _pic _holder . find ( '#pp_full_res' ) [ 0 ] . innerHTML = toInject ;
// Show content
_showContent ( ) ;
} ;
} ) ;
return false ;
} ;
/ * *
* Change page in the prettyPhoto modal box
* @ param direction { String } Direction of the paging , previous or next .
* /
$ . prettyPhoto . changePage = function ( direction ) {
currentGalleryPage = 0 ;
if ( direction == 'previous' ) {
set _position -- ;
if ( set _position < 0 ) set _position = $ ( pp _images ) . size ( ) - 1 ;
} else if ( direction == 'next' ) {
set _position ++ ;
if ( set _position > $ ( pp _images ) . size ( ) - 1 ) set _position = 0 ;
} else {
set _position = direction ;
} ;
rel _index = set _position ;
if ( ! doresize ) doresize = true ; // Allow the resizing of the images
if ( settings . allow _expand ) {
$ ( '.pp_contract' ) . removeClass ( 'pp_contract' ) . addClass ( 'pp_expand' ) ;
}
_hideContent ( function ( ) { $ . prettyPhoto . open ( ) ; } ) ;
} ;
/ * *
* Change gallery page in the prettyPhoto modal box
* @ param direction { String } Direction of the paging , previous or next .
* /
$ . prettyPhoto . changeGalleryPage = function ( direction ) {
if ( direction == 'next' ) {
currentGalleryPage ++ ;
if ( currentGalleryPage > totalPage ) currentGalleryPage = 0 ;
} else if ( direction == 'previous' ) {
currentGalleryPage -- ;
if ( currentGalleryPage < 0 ) currentGalleryPage = totalPage ;
} else {
currentGalleryPage = direction ;
} ;
slide _speed = ( direction == 'next' || direction == 'previous' ) ? settings . animation _speed : 0 ;
slide _to = currentGalleryPage * ( itemsPerPage * itemWidth ) ;
$pp _gallery . find ( 'ul' ) . animate ( { left : - slide _to } , slide _speed ) ;
} ;
/ * *
* Start the slideshow ...
* /
$ . prettyPhoto . startSlideshow = function ( ) {
if ( typeof pp _slideshow == 'undefined' ) {
$pp _pic _holder . find ( '.pp_play' ) . unbind ( 'click' ) . removeClass ( 'pp_play' ) . addClass ( 'pp_pause' ) . click ( function ( ) {
$ . prettyPhoto . stopSlideshow ( ) ;
return false ;
} ) ;
pp _slideshow = setInterval ( $ . prettyPhoto . startSlideshow , settings . slideshow ) ;
} else {
$ . prettyPhoto . changePage ( 'next' ) ;
} ;
}
/ * *
* Stop the slideshow ...
* /
$ . prettyPhoto . stopSlideshow = function ( ) {
$pp _pic _holder . find ( '.pp_pause' ) . unbind ( 'click' ) . removeClass ( 'pp_pause' ) . addClass ( 'pp_play' ) . click ( function ( ) {
$ . prettyPhoto . startSlideshow ( ) ;
return false ;
} ) ;
clearInterval ( pp _slideshow ) ;
pp _slideshow = undefined ;
}
/ * *
* Closes prettyPhoto .
* /
$ . prettyPhoto . close = function ( ) {
if ( $pp _overlay . is ( ":animated" ) ) return ;
$ . prettyPhoto . stopSlideshow ( ) ;
$pp _pic _holder . stop ( ) . find ( 'object,embed' ) . css ( 'visibility' , 'hidden' ) ;
$ ( 'div.pp_pic_holder,div.ppt,.pp_fade' ) . fadeOut ( settings . animation _speed , function ( ) { $ ( this ) . remove ( ) ; } ) ;
$pp _overlay . fadeOut ( settings . animation _speed , function ( ) {
if ( settings . hideflash ) $ ( 'object,embed,iframe[src*=youtube],iframe[src*=vimeo]' ) . css ( 'visibility' , 'visible' ) ; // Show the flash
$ ( this ) . remove ( ) ; // No more need for the prettyPhoto markup
$ ( window ) . unbind ( 'scroll.prettyphoto' ) ;
clearHashtag ( ) ;
settings . callback ( ) ;
doresize = true ;
pp _open = false ;
delete settings ;
} ) ;
} ;
/ * *
* Set the proper sizes on the containers and animate the content in .
* /
function _showContent ( ) {
$ ( '.pp_loaderIcon' ) . hide ( ) ;
// Calculate the opened top position of the pic holder
projectedTop = scroll _pos [ 'scrollTop' ] + ( ( windowHeight / 2 ) - ( pp _dimensions [ 'containerHeight' ] / 2 ) ) ;
if ( projectedTop < 0 ) projectedTop = 0 ;
$ppt . fadeTo ( settings . animation _speed , 1 ) ;
// Resize the content holder
$pp _pic _holder . find ( '.pp_content' )
. animate ( {
height : pp _dimensions [ 'contentHeight' ] ,
width : pp _dimensions [ 'contentWidth' ]
} , settings . animation _speed ) ;
// Resize picture the holder
$pp _pic _holder . animate ( {
'top' : projectedTop ,
'left' : ( ( windowWidth / 2 ) - ( pp _dimensions [ 'containerWidth' ] / 2 ) < 0 ) ? 0 : ( windowWidth / 2 ) - ( pp _dimensions [ 'containerWidth' ] / 2 ) ,
width : pp _dimensions [ 'containerWidth' ]
} , settings . animation _speed , function ( ) {
$pp _pic _holder . find ( '.pp_hoverContainer,#fullResImage' ) . height ( pp _dimensions [ 'height' ] ) . width ( pp _dimensions [ 'width' ] ) ;
$pp _pic _holder . find ( '.pp_fade' ) . fadeIn ( settings . animation _speed ) ; // Fade the new content
// Show the nav
if ( isSet && _getFileType ( pp _images [ set _position ] ) == "image" ) { $pp _pic _holder . find ( '.pp_hoverContainer' ) . show ( ) ; } else { $pp _pic _holder . find ( '.pp_hoverContainer' ) . hide ( ) ; }
if ( settings . allow _expand ) {
if ( pp _dimensions [ 'resized' ] ) { // Fade the resizing link if the image is resized
$ ( 'a.pp_expand,a.pp_contract' ) . show ( ) ;
} else {
$ ( 'a.pp_expand' ) . hide ( ) ;
}
}
if ( settings . autoplay _slideshow && ! pp _slideshow && ! pp _open ) $ . prettyPhoto . startSlideshow ( ) ;
settings . changepicturecallback ( ) ; // Callback!
pp _open = true ;
} ) ;
_insert _gallery ( ) ;
pp _settings . ajaxcallback ( ) ;
} ;
/ * *
* Hide the content ... DUH !
* /
function _hideContent ( callback ) {
// Fade out the current picture
$pp _pic _holder . find ( '#pp_full_res object,#pp_full_res embed' ) . css ( 'visibility' , 'hidden' ) ;
$pp _pic _holder . find ( '.pp_fade' ) . fadeOut ( settings . animation _speed , function ( ) {
$ ( '.pp_loaderIcon' ) . show ( ) ;
callback ( ) ;
} ) ;
} ;
/ * *
* Check the item position in the gallery array , hide or show the navigation links
* @ param setCount { integer } The total number of items in the set
* /
function _checkPosition ( setCount ) {
( setCount > 1 ) ? $ ( '.pp_nav' ) . show ( ) : $ ( '.pp_nav' ) . hide ( ) ; // Hide the bottom nav if it's not a set.
} ;
/ * *
* Resize the item dimensions if it ' s bigger than the viewport
* @ param width { integer } Width of the item to be opened
* @ param height { integer } Height of the item to be opened
* @ return An array containin the "fitted" dimensions
* /
function _fitToViewport ( width , height ) {
resized = false ;
_getDimensions ( width , height ) ;
// Define them in case there's no resize needed
imageWidth = width , imageHeight = height ;
if ( ( ( pp _containerWidth > windowWidth ) || ( pp _containerHeight > windowHeight ) ) && doresize && settings . allow _resize && ! percentBased ) {
resized = true , fitting = false ;
while ( ! fitting ) {
if ( ( pp _containerWidth > windowWidth ) ) {
imageWidth = ( windowWidth - 200 ) ;
imageHeight = ( height / width ) * imageWidth ;
} else if ( ( pp _containerHeight > windowHeight ) ) {
imageHeight = ( windowHeight - 200 ) ;
imageWidth = ( width / height ) * imageHeight ;
} else {
fitting = true ;
} ;
pp _containerHeight = imageHeight , pp _containerWidth = imageWidth ;
} ;
if ( ( pp _containerWidth > windowWidth ) || ( pp _containerHeight > windowHeight ) ) {
_fitToViewport ( pp _containerWidth , pp _containerHeight )
} ;
_getDimensions ( imageWidth , imageHeight ) ;
} ;
return {
width : Math . floor ( imageWidth ) ,
height : Math . floor ( imageHeight ) ,
containerHeight : Math . floor ( pp _containerHeight ) ,
containerWidth : Math . floor ( pp _containerWidth ) + ( settings . horizontal _padding * 2 ) ,
contentHeight : Math . floor ( pp _contentHeight ) ,
contentWidth : Math . floor ( pp _contentWidth ) ,
resized : resized
} ;
} ;
/ * *
* Get the containers dimensions according to the item size
* @ param width { integer } Width of the item to be opened
* @ param height { integer } Height of the item to be opened
* /
function _getDimensions ( width , height ) {
width = parseFloat ( width ) ;
height = parseFloat ( height ) ;
// Get the details height, to do so, I need to clone it since it's invisible
$pp _details = $pp _pic _holder . find ( '.pp_details' ) ;
$pp _details . width ( width ) ;
detailsHeight = parseFloat ( $pp _details . css ( 'marginTop' ) ) + parseFloat ( $pp _details . css ( 'marginBottom' ) ) ;
$pp _details = $pp _details . clone ( ) . addClass ( settings . theme ) . width ( width ) . appendTo ( $ ( 'body' ) ) . css ( {
'position' : 'absolute' ,
'top' : - 10000
} ) ;
detailsHeight += $pp _details . height ( ) ;
detailsHeight = ( detailsHeight <= 34 ) ? 36 : detailsHeight ; // Min-height for the details
$pp _details . remove ( ) ;
// Get the titles height, to do so, I need to clone it since it's invisible
$pp _title = $pp _pic _holder . find ( '.ppt' ) ;
$pp _title . width ( width ) ;
titleHeight = parseFloat ( $pp _title . css ( 'marginTop' ) ) + parseFloat ( $pp _title . css ( 'marginBottom' ) ) ;
$pp _title = $pp _title . clone ( ) . appendTo ( $ ( 'body' ) ) . css ( {
'position' : 'absolute' ,
'top' : - 10000
} ) ;
titleHeight += $pp _title . height ( ) ;
$pp _title . remove ( ) ;
// Get the container size, to resize the holder to the right dimensions
pp _contentHeight = height + detailsHeight ;
pp _contentWidth = width ;
pp _containerHeight = pp _contentHeight + titleHeight + $pp _pic _holder . find ( '.pp_top' ) . height ( ) + $pp _pic _holder . find ( '.pp_bottom' ) . height ( ) ;
pp _containerWidth = width ;
}
function _getFileType ( itemSrc ) {
if ( itemSrc . match ( /youtube\.com\/watch/i ) || itemSrc . match ( /youtu\.be/i ) ) {
return 'youtube' ;
} else if ( itemSrc . match ( /vimeo\.com/i ) ) {
return 'vimeo' ;
} else if ( itemSrc . match ( /\b.mov\b/i ) ) {
return 'quicktime' ;
} else if ( itemSrc . match ( /\b.swf\b/i ) ) {
return 'flash' ;
} else if ( itemSrc . match ( /\biframe=true\b/i ) ) {
return 'iframe' ;
} else if ( itemSrc . match ( /\bajax=true\b/i ) ) {
return 'ajax' ;
} else if ( itemSrc . match ( /\bcustom=true\b/i ) ) {
return 'custom' ;
} else if ( itemSrc . substr ( 0 , 1 ) == '#' ) {
return 'inline' ;
} else {
return 'image' ;
} ;
} ;
function _center _overlay ( ) {
if ( doresize && typeof $pp _pic _holder != 'undefined' ) {
scroll _pos = _get _scroll ( ) ;
contentHeight = $pp _pic _holder . height ( ) , contentwidth = $pp _pic _holder . width ( ) ;
projectedTop = ( windowHeight / 2 ) + scroll _pos [ 'scrollTop' ] - ( contentHeight / 2 ) ;
if ( projectedTop < 0 ) projectedTop = 0 ;
if ( contentHeight > windowHeight )
return ;
$pp _pic _holder . css ( {
'top' : projectedTop ,
'left' : ( windowWidth / 2 ) + scroll _pos [ 'scrollLeft' ] - ( contentwidth / 2 )
} ) ;
} ;
} ;
function _get _scroll ( ) {
if ( self . pageYOffset ) {
return { scrollTop : self . pageYOffset , scrollLeft : self . pageXOffset } ;
} else if ( document . documentElement && document . documentElement . scrollTop ) { // Explorer 6 Strict
return { scrollTop : document . documentElement . scrollTop , scrollLeft : document . documentElement . scrollLeft } ;
} else if ( document . body ) { // all other Explorers
return { scrollTop : document . body . scrollTop , scrollLeft : document . body . scrollLeft } ;
} ;
} ;
function _resize _overlay ( ) {
windowHeight = $ ( window ) . height ( ) , windowWidth = $ ( window ) . width ( ) ;
if ( typeof $pp _overlay != "undefined" ) $pp _overlay . height ( $ ( document ) . height ( ) ) . width ( windowWidth ) ;
} ;
function _insert _gallery ( ) {
if ( isSet && settings . overlay _gallery && _getFileType ( pp _images [ set _position ] ) == "image" ) {
itemWidth = 52 + 5 ; // 52 beign the thumb width, 5 being the right margin.
navWidth = ( settings . theme == "facebook" || settings . theme == "pp_default" ) ? 50 : 30 ; // Define the arrow width depending on the theme
itemsPerPage = Math . floor ( ( pp _dimensions [ 'containerWidth' ] - 100 - navWidth ) / itemWidth ) ;
itemsPerPage = ( itemsPerPage < pp _images . length ) ? itemsPerPage : pp _images . length ;
totalPage = Math . ceil ( pp _images . length / itemsPerPage ) - 1 ;
// Hide the nav in the case there's no need for links
if ( totalPage == 0 ) {
navWidth = 0 ; // No nav means no width!
$pp _gallery . find ( '.pp_arrow_next,.pp_arrow_previous' ) . hide ( ) ;
} else {
$pp _gallery . find ( '.pp_arrow_next,.pp_arrow_previous' ) . show ( ) ;
} ;
galleryWidth = itemsPerPage * itemWidth ;
fullGalleryWidth = pp _images . length * itemWidth ;
// Set the proper width to the gallery items
$pp _gallery
. css ( 'margin-left' , - ( ( galleryWidth / 2 ) + ( navWidth / 2 ) ) )
. find ( 'div:first' ) . width ( galleryWidth + 5 )
. find ( 'ul' ) . width ( fullGalleryWidth )
. find ( 'li.selected' ) . removeClass ( 'selected' ) ;
goToPage = ( Math . floor ( set _position / itemsPerPage ) < totalPage ) ? Math . floor ( set _position / itemsPerPage ) : totalPage ;
$ . prettyPhoto . changeGalleryPage ( goToPage ) ;
$pp _gallery _li . filter ( ':eq(' + set _position + ')' ) . addClass ( 'selected' ) ;
} else {
$pp _pic _holder . find ( '.pp_content' ) . unbind ( 'mouseenter mouseleave' ) ;
// $pp_gallery.hide();
}
}
function _build _overlay ( caller ) {
// Inject Social Tool markup into General markup
if ( settings . social _tools )
facebook _like _link = settings . social _tools . replace ( '{location_href}' , encodeURIComponent ( location . href ) ) ;
settings . markup = settings . markup . replace ( '{pp_social}' , '' ) ;
$ ( 'body' ) . append ( settings . markup ) ; // Inject the markup
$pp _pic _holder = $ ( '.pp_pic_holder' ) , $ppt = $ ( '.ppt' ) , $pp _overlay = $ ( 'div.pp_overlay' ) ; // Set my global selectors
// Inject the inline gallery!
if ( isSet && settings . overlay _gallery ) {
currentGalleryPage = 0 ;
toInject = "" ;
for ( var i = 0 ; i < pp _images . length ; i ++ ) {
if ( ! pp _images [ i ] . match ( /\b(jpg|jpeg|png|gif)\b/gi ) ) {
classname = 'default' ;
img _src = '' ;
} else {
classname = '' ;
img _src = pp _images [ i ] ;
}
toInject += "<li class='" + classname + "'><a href='#'><img src='" + img _src + "' width='50' alt='' /></a></li>" ;
} ;
toInject = settings . gallery _markup . replace ( /{gallery}/g , toInject ) ;
$pp _pic _holder . find ( '#pp_full_res' ) . after ( toInject ) ;
$pp _gallery = $ ( '.pp_pic_holder .pp_gallery' ) , $pp _gallery _li = $pp _gallery . find ( 'li' ) ; // Set the gallery selectors
$pp _gallery . find ( '.pp_arrow_next' ) . click ( function ( ) {
$ . prettyPhoto . changeGalleryPage ( 'next' ) ;
$ . prettyPhoto . stopSlideshow ( ) ;
return false ;
} ) ;
$pp _gallery . find ( '.pp_arrow_previous' ) . click ( function ( ) {
$ . prettyPhoto . changeGalleryPage ( 'previous' ) ;
$ . prettyPhoto . stopSlideshow ( ) ;
return false ;
} ) ;
$pp _pic _holder . find ( '.pp_content' ) . hover (
function ( ) {
$pp _pic _holder . find ( '.pp_gallery:not(.disabled)' ) . fadeIn ( ) ;
} ,
function ( ) {
$pp _pic _holder . find ( '.pp_gallery:not(.disabled)' ) . fadeOut ( ) ;
} ) ;
itemWidth = 52 + 5 ; // 52 beign the thumb width, 5 being the right margin.
$pp _gallery _li . each ( function ( i ) {
$ ( this )
. find ( 'a' )
. click ( function ( ) {
$ . prettyPhoto . changePage ( i ) ;
$ . prettyPhoto . stopSlideshow ( ) ;
return false ;
} ) ;
} ) ;
} ;
// Inject the play/pause if it's a slideshow
if ( settings . slideshow ) {
$pp _pic _holder . find ( '.pp_nav' ) . prepend ( '<a href="#" class="pp_play">Play</a>' )
$pp _pic _holder . find ( '.pp_nav .pp_play' ) . click ( function ( ) {
$ . prettyPhoto . startSlideshow ( ) ;
return false ;
} ) ;
}
$pp _pic _holder . attr ( 'class' , 'pp_pic_holder ' + settings . theme ) ; // Set the proper theme
$pp _overlay
. css ( {
'opacity' : 0 ,
'height' : $ ( document ) . height ( ) ,
'width' : $ ( window ) . width ( )
} )
. bind ( 'click' , function ( ) {
if ( ! settings . modal ) $ . prettyPhoto . close ( ) ;
} ) ;
$ ( 'a.pp_close' ) . bind ( 'click' , function ( ) { $ . prettyPhoto . close ( ) ; return false ; } ) ;
if ( settings . allow _expand ) {
$ ( 'a.pp_expand' ) . bind ( 'click' , function ( e ) {
// Expand the image
if ( $ ( this ) . hasClass ( 'pp_expand' ) ) {
$ ( this ) . removeClass ( 'pp_expand' ) . addClass ( 'pp_contract' ) ;
doresize = false ;
} else {
$ ( this ) . removeClass ( 'pp_contract' ) . addClass ( 'pp_expand' ) ;
doresize = true ;
} ;
_hideContent ( function ( ) { $ . prettyPhoto . open ( ) ; } ) ;
return false ;
} ) ;
}
$pp _pic _holder . find ( '.pp_previous, .pp_nav .pp_arrow_previous' ) . bind ( 'click' , function ( ) {
$ . prettyPhoto . changePage ( 'previous' ) ;
$ . prettyPhoto . stopSlideshow ( ) ;
return false ;
} ) ;
$pp _pic _holder . find ( '.pp_next, .pp_nav .pp_arrow_next' ) . bind ( 'click' , function ( ) {
$ . prettyPhoto . changePage ( 'next' ) ;
$ . prettyPhoto . stopSlideshow ( ) ;
return false ;
} ) ;
_center _overlay ( ) ; // Center it
} ;
if ( ! pp _alreadyInitialized && getHashtag ( ) ) {
pp _alreadyInitialized = true ;
// Grab the rel index to trigger the click on the correct element
hashIndex = getHashtag ( ) ;
hashRel = hashIndex ;
hashIndex = hashIndex . substring ( hashIndex . indexOf ( '/' ) + 1 , hashIndex . length - 1 ) ;
hashRel = hashRel . substring ( 0 , hashRel . indexOf ( '/' ) ) ;
// Little timeout to make sure all the prettyPhoto initialize scripts has been run.
// Useful in the event the page contain several init scripts.
setTimeout ( function ( ) { $ ( "a[" + pp _settings . hook + "^='" + hashRel + "']:eq(" + hashIndex + ")" ) . trigger ( 'click' ) ; } , 50 ) ;
}
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
} ;
function getHashtag ( ) {
var url = location . href ;
hashtag = ( url . indexOf ( '#prettyPhoto' ) !== - 1 ) ? decodeURI ( url . substring ( url . indexOf ( '#prettyPhoto' ) + 1 , url . length ) ) : false ;
return hashtag ;
} ;
function setHashtag ( ) {
if ( typeof theRel == 'undefined' ) return ; // theRel is set on normal calls, it's impossible to deeplink using the API
location . hash = theRel + '/' + rel _index + '/' ;
} ;
function clearHashtag ( ) {
if ( location . href . indexOf ( '#prettyPhoto' ) !== - 1 ) location . hash = "prettyPhoto" ;
}
function getParam ( name , url ) {
name = name . replace ( /[\[]/ , "\\\[" ) . replace ( /[\]]/ , "\\\]" ) ;
var regexS = "[\\?&]" + name + "=([^&#]*)" ;
var regex = new RegExp ( regexS ) ;
var results = regex . exec ( url ) ;
return ( results == null ) ? "" : results [ 1 ] ;
}
} ) ( jQuery ) ;
2014-03-11 11:14:25 +00:00
var pp _alreadyInitialized = false ; // Used for the deep linking to make sure not to call the same function several times.