').html( content );
}
}
// If "filter" option is provided, then filter content
if ( slide.opts.filter ) {
content = $('
').html( content ).find( slide.opts.filter );
}
}
slide.$slide.one('onReset', function () {
// Put content back
if ( slide.$placeholder ) {
slide.$placeholder.after( content.hide() ).remove();
slide.$placeholder = null;
}
// Remove custom close button
if ( slide.$smallBtn ) {
slide.$smallBtn.remove();
slide.$smallBtn = null;
}
// Remove content and mark slide as not loaded
if ( !slide.hasError ) {
$(this).empty();
slide.isLoaded = false;
}
});
slide.$content = $( content ).appendTo( slide.$slide );
if ( slide.opts.smallBtn && !slide.$smallBtn ) {
slide.$smallBtn = $( self.translate( slide, slide.opts.btnTpl.smallBtn ) ).appendTo( slide.$content );
}
this.afterLoad( slide );
},
// Display error message
// =====================
setError : function ( slide ) {
slide.hasError = true;
slide.$slide.removeClass( 'fancybox-slide--' + slide.type );
this.setContent( slide, this.translate( slide, slide.opts.errorTpl ) );
},
// Show loading icon inside the slide
// ==================================
showLoading : function( slide ) {
var self = this;
slide = slide || self.current;
if ( slide && !slide.$spinner ) {
slide.$spinner = $( self.opts.spinnerTpl ).appendTo( slide.$slide );
}
},
// Remove loading icon from the slide
// ==================================
hideLoading : function( slide ) {
var self = this;
slide = slide || self.current;
if ( slide && slide.$spinner ) {
slide.$spinner.remove();
delete slide.$spinner;
}
},
// Adjustments after slide content has been loaded
// ===============================================
afterLoad : function( slide ) {
var self = this;
if ( self.isClosing ) {
return;
}
slide.isLoading = false;
slide.isLoaded = true;
self.trigger( 'afterLoad', slide );
self.hideLoading( slide );
if ( slide.opts.protect && slide.$content && !slide.hasError ) {
// Disable right click
slide.$content.on( 'contextmenu.fb', function( e ) {
if ( e.button == 2 ) {
e.preventDefault();
}
return true;
});
// Add fake element on top of the image
// This makes a bit harder for user to select image
if ( slide.type === 'image' ) {
$( '
' ).appendTo( slide.$content );
}
}
self.revealContent( slide );
},
// Make content visible
// This method is called right after content has been loaded or
// user navigates gallery and transition should start
// ============================================================
revealContent : function( slide ) {
var self = this;
var $slide = slide.$slide;
var effect, effectClassName, duration, opacity, end, start = false;
effect = slide.opts[ self.firstRun ? 'animationEffect' : 'transitionEffect' ];
duration = slide.opts[ self.firstRun ? 'animationDuration' : 'transitionDuration' ];
duration = parseInt( slide.forcedDuration === undefined ? duration : slide.forcedDuration, 10 );
if ( slide.isMoved || slide.pos !== self.currPos || !duration ) {
effect = false;
}
// Check if can zoom
if ( effect === 'zoom' && !( slide.pos === self.currPos && duration && slide.type === 'image' && !slide.hasError && ( start = self.getThumbPos( slide ) ) ) ) {
effect = 'fade';
}
// Zoom animation
// ==============
if ( effect === 'zoom' ) {
end = self.getFitPos( slide );
end.scaleX = Math.round( (end.width / start.width) * 100 ) / 100;
end.scaleY = Math.round( (end.height / start.height) * 100 ) / 100;
delete end.width;
delete end.height;
// Check if we need to animate opacity
opacity = slide.opts.zoomOpacity;
if ( opacity == 'auto' ) {
opacity = Math.abs( slide.width / slide.height - start.width / start.height ) > 0.1;
}
if ( opacity ) {
start.opacity = 0.1;
end.opacity = 1;
}
// Draw image at start position
$.fancybox.setTranslate( slide.$content.removeClass( 'fancybox-is-hidden' ), start );
forceRedraw( slide.$content );
// Start animation
$.fancybox.animate( slide.$content, end, duration, function() {
self.complete();
});
return;
}
self.updateSlide( slide );
// Simply show content
// ===================
if ( !effect ) {
forceRedraw( $slide );
slide.$content.removeClass( 'fancybox-is-hidden' );
if ( slide.pos === self.currPos ) {
self.complete();
}
return;
}
$.fancybox.stop( $slide );
effectClassName = 'fancybox-animated fancybox-slide--' + ( slide.pos > self.prevPos ? 'next' : 'previous' ) + ' fancybox-fx-' + effect;
$slide.removeAttr( 'style' ).removeClass( 'fancybox-slide--current fancybox-slide--next fancybox-slide--previous' ).addClass( effectClassName );
slide.$content.removeClass( 'fancybox-is-hidden' );
//Force reflow for CSS3 transitions
forceRedraw( $slide );
$.fancybox.animate( $slide, 'fancybox-slide--current', duration, function(e) {
$slide.removeClass( effectClassName ).removeAttr( 'style' );
if ( slide.pos === self.currPos ) {
self.complete();
}
}, true);
},
// Check if we can and have to zoom from thumbnail
//================================================
getThumbPos : function( slide ) {
var self = this;
var rez = false;
// Check if element is inside the viewport by at least 1 pixel
var isElementVisible = function( $el ) {
var element = $el[0];
var elementRect = element.getBoundingClientRect();
var parentRects = [];
var visibleInAllParents;
while ( element.parentElement !== null ) {
if ( $(element.parentElement).css('overflow') === 'hidden' || $(element.parentElement).css('overflow') === 'auto' ) {
parentRects.push(element.parentElement.getBoundingClientRect());
}
element = element.parentElement;
}
visibleInAllParents = parentRects.every(function(parentRect){
var visiblePixelX = Math.min(elementRect.right, parentRect.right) - Math.max(elementRect.left, parentRect.left);
var visiblePixelY = Math.min(elementRect.bottom, parentRect.bottom) - Math.max(elementRect.top, parentRect.top);
return visiblePixelX > 0 && visiblePixelY > 0;
});
return visibleInAllParents &&
elementRect.bottom > 0 && elementRect.right > 0 &&
elementRect.left < $(window).width() && elementRect.top < $(window).height();
};
var $thumb = slide.opts.$thumb;
var thumbPos = $thumb ? $thumb.offset() : 0;
var slidePos;
if ( thumbPos && $thumb[0].ownerDocument === document && isElementVisible( $thumb ) ) {
slidePos = self.$refs.stage.offset();
rez = {
top : thumbPos.top - slidePos.top + parseFloat( $thumb.css( "border-top-width" ) || 0 ),
left : thumbPos.left - slidePos.left + parseFloat( $thumb.css( "border-left-width" ) || 0 ),
width : $thumb.width(),
height : $thumb.height(),
scaleX : 1,
scaleY : 1
};
}
return rez;
},
// Final adjustments after current gallery item is moved to position
// and it`s content is loaded
// ==================================================================
complete : function() {
var self = this;
var current = self.current;
var slides = {};
if ( current.isMoved || !current.isLoaded || current.isComplete ) {
return;
}
current.isComplete = true;
current.$slide.siblings().trigger( 'onReset' );
// Trigger any CSS3 transiton inside the slide
forceRedraw( current.$slide );
current.$slide.addClass( 'fancybox-slide--complete' );
// Remove unnecessary slides
$.each( self.slides, function( key, slide ) {
if ( slide.pos >= self.currPos - 1 && slide.pos <= self.currPos + 1 ) {
slides[ slide.pos ] = slide;
} else if ( slide ) {
$.fancybox.stop( slide.$slide );
slide.$slide.unbind().remove();
}
});
self.slides = slides;
self.updateCursor();
self.trigger( 'afterShow' );
// Try to focus on the first focusable element
if ( $( document.activeElement ).is( '[disabled]' ) || ( current.opts.autoFocus && !( current.type == 'image' || current.type === 'iframe' ) ) ) {
self.focus();
}
},
// Preload next and previous slides
// ================================
preload : function() {
var self = this;
var next, prev;
if ( self.group.length < 2 ) {
return;
}
next = self.slides[ self.currPos + 1 ];
prev = self.slides[ self.currPos - 1 ];
if ( next && next.type === 'image' ) {
self.loadSlide( next );
}
if ( prev && prev.type === 'image' ) {
self.loadSlide( prev );
}
},
// Try to find and focus on the first focusable element
// ====================================================
focus : function() {
var current = this.current;
var $el;
if ( this.isClosing ) {
return;
}
// Skip for images and iframes
$el = current && current.isComplete ? current.$slide.find('button,:input,[tabindex],a').filter(':not([disabled]):visible:first') : null;
$el = $el && $el.length ? $el : this.$refs.container;
$el.focus();
},
// Activates current instance - brings container to the front and enables keyboard,
// notifies other instances about deactivating
// =================================================================================
activate : function () {
var self = this;
// Deactivate all instances
$( '.fancybox-container' ).each(function () {
var instance = $(this).data( 'FancyBox' );
// Skip self and closing instances
if (instance && instance.uid !== self.uid && !instance.isClosing) {
instance.trigger( 'onDeactivate' );
}
});
if ( self.current ) {
if ( self.$refs.container.index() > 0 ) {
self.$refs.container.prependTo( document.body );
}
self.updateControls();
}
self.trigger( 'onActivate' );
self.addEvents();
},
// Start closing procedure
// This will start "zoom-out" animation if needed and clean everything up afterwards
// =================================================================================
close : function( e, d ) {
var self = this;
var current = self.current;
var effect, duration;
var $what, opacity, start, end;
var done = function() {
self.cleanUp( e );
};
if ( self.isClosing ) {
return false;
}
self.isClosing = true;
// If beforeClose callback prevents closing, make sure content is centered
if ( self.trigger( 'beforeClose', e ) === false ) {
self.isClosing = false;
requestAFrame(function() {
self.update();
});
return false;
}
// Remove all events
// If there are multiple instances, they will be set again by "activate" method
self.removeEvents();
if ( current.timouts ) {
clearTimeout( current.timouts );
}
$what = current.$content;
effect = current.opts.animationEffect;
duration = $.isNumeric( d ) ? d : ( effect ? current.opts.animationDuration : 0 );
// Remove other slides
current.$slide.off( transitionEnd ).removeClass( 'fancybox-slide--complete fancybox-slide--next fancybox-slide--previous fancybox-animated' );
current.$slide.siblings().trigger( 'onReset' ).remove();
// Trigger animations
if ( duration ) {
self.$refs.container.removeClass( 'fancybox-is-open' ).addClass( 'fancybox-is-closing' );
}
// Clean up
self.hideLoading( current );
self.hideControls();
self.updateCursor();
// Check if possible to zoom-out
if ( effect === 'zoom' && !( e !== true && $what && duration && current.type === 'image' && !current.hasError && ( end = self.getThumbPos( current ) ) ) ) {
effect = 'fade';
}
if ( effect === 'zoom' ) {
$.fancybox.stop( $what );
start = $.fancybox.getTranslate( $what );
start.width = start.width * start.scaleX;
start.height = start.height * start.scaleY;
// Check if we need to animate opacity
opacity = current.opts.zoomOpacity;
if ( opacity == 'auto' ) {
opacity = Math.abs( current.width / current.height - end.width / end.height ) > 0.1;
}
if ( opacity ) {
end.opacity = 0;
}
start.scaleX = start.width / end.width;
start.scaleY = start.height / end.height;
start.width = end.width;
start.height = end.height;
$.fancybox.setTranslate( current.$content, start );
$.fancybox.animate( current.$content, end, duration, done );
return true;
}
if ( effect && duration ) {
// If skip animation
if ( e === true ) {
setTimeout( done, duration );
} else {
$.fancybox.animate( current.$slide.removeClass( 'fancybox-slide--current' ), 'fancybox-animated fancybox-slide--previous fancybox-fx-' + effect, duration, done );
}
} else {
done();
}
return true;
},
// Final adjustments after removing the instance
// =============================================
cleanUp : function( e ) {
var self = this,
instance;
self.current.$slide.trigger( 'onReset' );
self.$refs.container.empty().remove();
self.trigger( 'afterClose', e );
// Place back focus
if ( self.$lastFocus && !!!self.current.focusBack ) {
self.$lastFocus.focus();
}
self.current = null;
// Check if there are other instances
instance = $.fancybox.getInstance();
if ( instance ) {
instance.activate();
} else {
$W.scrollTop( self.scrollTop ).scrollLeft( self.scrollLeft );
$( 'html' ).removeClass( 'fancybox-enabled' );
$( '#fancybox-style-noscroll' ).remove();
}
},
// Call callback and trigger an event
// ==================================
trigger : function( name, slide ) {
var args = Array.prototype.slice.call(arguments, 1),
self = this,
obj = slide && slide.opts ? slide : self.current,
rez;
if ( obj ) {
args.unshift( obj );
} else {
obj = self;
}
args.unshift( self );
if ( $.isFunction( obj.opts[ name ] ) ) {
rez = obj.opts[ name ].apply( obj, args );
}
if ( rez === false ) {
return rez;
}
if ( name === 'afterClose' ) {
$D.trigger( name + '.fb', args );
} else {
self.$refs.container.trigger( name + '.fb', args );
}
},
// Update infobar values, navigation button states and reveal caption
// ==================================================================
updateControls : function ( force ) {
var self = this;
var current = self.current;
var index = current.index;
var opts = current.opts;
var caption = opts.caption;
var $caption = self.$refs.caption;
// Recalculate content dimensions
current.$slide.trigger( 'refresh' );
self.$caption = caption && caption.length ? $caption.html( caption ) : null;
if ( !self.isHiddenControls ) {
self.showControls();
}
// Update info and navigation elements
$('[data-fancybox-count]').html( self.group.length );
$('[data-fancybox-index]').html( index + 1 );
$('[data-fancybox-prev]').prop('disabled', ( !opts.loop && index <= 0 ) );
$('[data-fancybox-next]').prop('disabled', ( !opts.loop && index >= self.group.length - 1 ) );
},
// Hide toolbar and caption
// ========================
hideControls : function () {
this.isHiddenControls = true;
this.$refs.container.removeClass('fancybox-show-infobar fancybox-show-toolbar fancybox-show-caption fancybox-show-nav');
},
showControls : function() {
var self = this;
var opts = self.current ? self.current.opts : self.opts;
var $container = self.$refs.container;
self.isHiddenControls = false;
self.idleSecondsCounter = 0;
$container
.toggleClass('fancybox-show-toolbar', !!( opts.toolbar && opts.buttons ) )
.toggleClass('fancybox-show-infobar', !!( opts.infobar && self.group.length > 1 ) )
.toggleClass('fancybox-show-nav', !!( opts.arrows && self.group.length > 1 ) )
.toggleClass('fancybox-is-modal', !!opts.modal );
if ( self.$caption ) {
$container.addClass( 'fancybox-show-caption ');
} else {
$container.removeClass( 'fancybox-show-caption' );
}
},
// Toggle toolbar and caption
// ==========================
toggleControls : function() {
if ( this.isHiddenControls ) {
this.showControls();
} else {
this.hideControls();
}
},
});
$.fancybox = {
version : "3.1.20",
defaults : defaults,
// Get current instance and execute a command.
//
// Examples of usage:
//
// $instance = $.fancybox.getInstance();
// $.fancybox.getInstance().jumpTo( 1 );
// $.fancybox.getInstance( 'jumpTo', 1 );
// $.fancybox.getInstance( function() {
// console.info( this.currIndex );
// });
// ======================================================
getInstance : function ( command ) {
var instance = $('.fancybox-container:not(".fancybox-is-closing"):first').data( 'FancyBox' );
var args = Array.prototype.slice.call(arguments, 1);
if ( instance instanceof FancyBox ) {
if ( $.type( command ) === 'string' ) {
instance[ command ].apply( instance, args );
} else if ( $.type( command ) === 'function' ) {
command.apply( instance, args );
}
return instance;
}
return false;
},
// Create new instance
// ===================
open : function ( items, opts, index ) {
return new FancyBox( items, opts, index );
},
// Close current or all instances
// ==============================
close : function ( all ) {
var instance = this.getInstance();
if ( instance ) {
instance.close();
// Try to find and close next instance
if ( all === true ) {
this.close();
}
}
},
// Close instances and unbind all events
// ==============================
destroy : function() {
this.close( true );
$D.off( 'click.fb-start' );
},
// Try to detect mobile devices
// ============================
isMobile : document.createTouch !== undefined && /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent),
// Detect if 'translate3d' support is available
// ============================================
use3d : (function() {
var div = document.createElement('div');
return window.getComputedStyle && window.getComputedStyle( div ).getPropertyValue('transform') && !(document.documentMode && document.documentMode < 11);
}()),
// Helper function to get current visual state of an element
// returns array[ top, left, horizontal-scale, vertical-scale, opacity ]
// =====================================================================
getTranslate : function( $el ) {
var matrix;
if ( !$el || !$el.length ) {
return false;
}
matrix = $el.eq( 0 ).css('transform');
if ( matrix && matrix.indexOf( 'matrix' ) !== -1 ) {
matrix = matrix.split('(')[1];
matrix = matrix.split(')')[0];
matrix = matrix.split(',');
} else {
matrix = [];
}
if ( matrix.length ) {
// If IE
if ( matrix.length > 10 ) {
matrix = [ matrix[13], matrix[12], matrix[0], matrix[5] ];
} else {
matrix = [ matrix[5], matrix[4], matrix[0], matrix[3]];
}
matrix = matrix.map(parseFloat);
} else {
matrix = [ 0, 0, 1, 1 ];
var transRegex = /\.*translate\((.*)px,(.*)px\)/i;
var transRez = transRegex.exec( $el.eq( 0 ).attr('style') );
if ( transRez ) {
matrix[ 0 ] = parseFloat( transRez[2] );
matrix[ 1 ] = parseFloat( transRez[1] );
}
}
return {
top : matrix[ 0 ],
left : matrix[ 1 ],
scaleX : matrix[ 2 ],
scaleY : matrix[ 3 ],
opacity : parseFloat( $el.css('opacity') ),
width : $el.width(),
height : $el.height()
};
},
// Shortcut for setting "translate3d" properties for element
// Can set be used to set opacity, too
// ========================================================
setTranslate : function( $el, props ) {
var str = '';
var css = {};
if ( !$el || !props ) {
return;
}
if ( props.left !== undefined || props.top !== undefined ) {
str = ( props.left === undefined ? $el.position().left : props.left ) + 'px, ' + ( props.top === undefined ? $el.position().top : props.top ) + 'px';
if ( this.use3d ) {
str = 'translate3d(' + str + ', 0px)';
} else {
str = 'translate(' + str + ')';
}
}
if ( props.scaleX !== undefined && props.scaleY !== undefined ) {
str = (str.length ? str + ' ' : '') + 'scale(' + props.scaleX + ', ' + props.scaleY + ')';
}
if ( str.length ) {
css.transform = str;
}
if ( props.opacity !== undefined ) {
css.opacity = props.opacity;
}
if ( props.width !== undefined ) {
css.width = props.width;
}
if ( props.height !== undefined ) {
css.height = props.height;
}
return $el.css( css );
},
// Simple CSS transition handler
// =============================
animate : function ( $el, to, duration, callback, leaveAnimationName ) {
var event = transitionEnd || 'transitionend';
if ( $.isFunction( duration ) ) {
callback = duration;
duration = null;
}
if ( !$.isPlainObject( to ) ) {
$el.removeAttr('style');
}
$el.on( event, function(e) {
// Skip events from child elements and z-index change
if ( e && e.originalEvent && ( !$el.is( e.originalEvent.target ) || e.originalEvent.propertyName == 'z-index' ) ) {
return;
}
$el.off( event );
if ( $.isPlainObject( to ) ) {
if ( to.scaleX !== undefined && to.scaleY !== undefined ) {
$el.css( 'transition-duration', '0ms' );
to.width = $el.width() * to.scaleX;
to.height = $el.height() * to.scaleY;
to.scaleX = 1;
to.scaleY = 1;
$.fancybox.setTranslate( $el, to );
}
} else if ( leaveAnimationName !== true ) {
$el.removeClass( to );
}
if ( $.isFunction( callback ) ) {
callback( e );
}
});
if ( $.isNumeric( duration ) ) {
$el.css( 'transition-duration', duration + 'ms' );
}
if ( $.isPlainObject( to ) ) {
$.fancybox.setTranslate( $el, to );
} else {
$el.addClass( to );
}
$el.data("timer", setTimeout(function() {
$el.trigger( 'transitionend' );
}, duration + 16));
},
stop : function( $el ) {
clearTimeout( $el.data("timer") );
$el.off( transitionEnd );
}
};
// Default click handler for "fancyboxed" links
// ============================================
function _run( e ) {
var target = e.currentTarget,
opts = e.data ? e.data.options : {},
items = e.data ? e.data.items : [],
value = $(target).attr( 'data-fancybox' ) || '',
index = 0;
e.preventDefault();
e.stopPropagation();
// Get all related items and find index for clicked one
if ( value ) {
items = items.length ? items.filter( '[data-fancybox="' + value + '"]' ) : $( '[data-fancybox="' + value + '"]' );
index = items.index( target );
// Sometimes current item can not be found
// (for example, when slider clones items)
if ( index < 0 ) {
index = 0;
}
} else {
items = [ target ];
}
$.fancybox.open( items, opts, index );
}
// Create a jQuery plugin
// ======================
$.fn.fancybox = function (options) {
var selector;
options = options || {};
selector = options.selector || false;
if ( selector ) {
$( 'body' ).off( 'click.fb-start', selector ).on( 'click.fb-start', selector, {
items : $( selector ),
options : options
}, _run );
} else {
this.off( 'click.fb-start' ).on( 'click.fb-start', {
items : this,
options : options
}, _run);
}
return this;
};
// Self initializing plugin
// ========================
$D.on( 'click.fb-start', '[data-fancybox]', _run );
}( window, document, window.jQuery ));
// ==========================================================================
//
// Media
// Adds additional media type support
//
// ==========================================================================
;(function ($) {
'use strict';
// Formats matching url to final form
var format = function (url, rez, params) {
if ( !url ) {
return;
}
params = params || '';
if ( $.type(params) === "object" ) {
params = $.param(params, true);
}
$.each(rez, function (key, value) {
url = url.replace('$' + key, value || '');
});
if (params.length) {
url += (url.indexOf('?') > 0 ? '&' : '?') + params;
}
return url;
};
// Object containing properties for each media type
var defaults = {
youtube : {
matcher : /(youtube\.com|youtu\.be|youtube\-nocookie\.com)\/(watch\?(.*&)?v=|v\/|u\/|embed\/?)?(videoseries\?list=(.*)|[\w-]{11}|\?listType=(.*)&list=(.*))(.*)/i,
params : {
autoplay : 1,
autohide : 1,
fs : 1,
rel : 0,
hd : 1,
wmode : 'transparent',
enablejsapi : 1,
html5 : 1
},
paramPlace : 8,
type : 'iframe',
url : '//www.youtube.com/embed/$4',
thumb : '//img.youtube.com/vi/$4/hqdefault.jpg'
},
vimeo : {
matcher : /^.+vimeo.com\/(.*\/)?([\d]+)(.*)?/,
params : {
autoplay : 1,
hd : 1,
show_title : 1,
show_byline : 1,
show_portrait : 0,
fullscreen : 1,
api : 1
},
paramPlace : 3,
type : 'iframe',
url : '//player.vimeo.com/video/$2'
},
metacafe : {
matcher : /metacafe.com\/watch\/(\d+)\/(.*)?/,
type : 'iframe',
url : '//www.metacafe.com/embed/$1/?ap=1'
},
dailymotion : {
matcher : /dailymotion.com\/video\/(.*)\/?(.*)/,
params : {
additionalInfos : 0,
autoStart : 1
},
type : 'iframe',
url : '//www.dailymotion.com/embed/video/$1'
},
vine : {
matcher : /vine.co\/v\/([a-zA-Z0-9\?\=\-]+)/,
type : 'iframe',
url : '//vine.co/v/$1/embed/simple'
},
instagram : {
matcher : /(instagr\.am|instagram\.com)\/p\/([a-zA-Z0-9_\-]+)\/?/i,
type : 'image',
url : '//$1/p/$2/media/?size=l'
},
// Examples:
// http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16
// http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16
// https://www.google.lv/maps/place/Googleplex/@37.4220041,-122.0833494,17z/data=!4m5!3m4!1s0x0:0x6c296c66619367e0!8m2!3d37.4219998!4d-122.0840572
google_maps : {
matcher : /(maps\.)?google\.([a-z]{2,3}(\.[a-z]{2})?)\/(((maps\/(place\/(.*)\/)?\@(.*),(\d+.?\d+?)z))|(\?ll=))(.*)?/i,
type : 'iframe',
url : function (rez) {
return '//maps.google.' + rez[2] + '/?ll=' + ( rez[9] ? rez[9] + '&z=' + Math.floor( rez[10] ) + ( rez[12] ? rez[12].replace(/^\//, "&") : '' ) : rez[12] ) + '&output=' + ( rez[12] && rez[12].indexOf('layer=c') > 0 ? 'svembed' : 'embed' );
}
}
};
$(document).on('onInit.fb', function (e, instance) {
$.each(instance.group, function( i, item ) {
var url = item.src || '',
type = false,
media,
thumb,
rez,
params,
urlParams,
o,
provider;
// Skip items that already have content type
if ( item.type ) {
return;
}
media = $.extend( true, {}, defaults, item.opts.media );
// Look for any matching media type
$.each(media, function ( n, el ) {
rez = url.match(el.matcher);
o = {};
provider = n;
if (!rez) {
return;
}
type = el.type;
if ( el.paramPlace && rez[ el.paramPlace ] ) {
urlParams = rez[ el.paramPlace ];
if ( urlParams[ 0 ] == '?' ) {
urlParams = urlParams.substring(1);
}
urlParams = urlParams.split('&');
for ( var m = 0; m < urlParams.length; ++m ) {
var p = urlParams[ m ].split('=', 2);
if ( p.length == 2 ) {
o[ p[0] ] = decodeURIComponent( p[1].replace(/\+/g, " ") );
}
}
}
params = $.extend( true, {}, el.params, item.opts[ n ], o );
url = $.type(el.url) === "function" ? el.url.call(this, rez, params, item) : format(el.url, rez, params);
thumb = $.type(el.thumb) === "function" ? el.thumb.call(this, rez, params, item) : format(el.thumb, rez);
if ( provider === 'vimeo' ) {
url = url.replace('&%23', '#');
}
return false;
});
// If it is found, then change content type and update the url
if ( type ) {
item.src = url;
item.type = type;
if ( !item.opts.thumb && !( item.opts.$thumb && item.opts.$thumb.length ) ) {
item.opts.thumb = thumb;
}
if ( type === 'iframe' ) {
$.extend(true, item.opts, {
iframe : {
preload : false,
attr : {
scrolling : "no"
}
}
});
item.contentProvider = provider;
item.opts.slideClass += ' fancybox-slide--' + ( provider == 'google_maps' ? 'map' : 'video' );
}
} else {
// If no content type is found, then set it to `image` as fallback
item.type = 'image';
}
});
});
}(window.jQuery));
// ==========================================================================
//
// Guestures
// Adds touch guestures, handles click and tap events
//
// ==========================================================================
;(function (window, document, $) {
'use strict';
var requestAFrame = (function () {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
// if all else fails, use setTimeout
function (callback) {
return window.setTimeout(callback, 1000 / 60);
};
})();
var cancelAFrame = (function () {
return window.cancelAnimationFrame ||
window.webkitCancelAnimationFrame ||
window.mozCancelAnimationFrame ||
window.oCancelAnimationFrame ||
function (id) {
window.clearTimeout(id);
};
})();
var pointers = function( e ) {
var result = [];
e = e.originalEvent || e || window.e;
e = e.touches && e.touches.length ? e.touches : ( e.changedTouches && e.changedTouches.length ? e.changedTouches : [ e ] );
for ( var key in e ) {
if ( e[ key ].pageX ) {
result.push( { x : e[ key ].pageX, y : e[ key ].pageY } );
} else if ( e[ key ].clientX ) {
result.push( { x : e[ key ].clientX, y : e[ key ].clientY } );
}
}
return result;
};
var distance = function( point2, point1, what ) {
if ( !point1 || !point2 ) {
return 0;
}
if ( what === 'x' ) {
return point2.x - point1.x;
} else if ( what === 'y' ) {
return point2.y - point1.y;
}
return Math.sqrt( Math.pow( point2.x - point1.x, 2 ) + Math.pow( point2.y - point1.y, 2 ) );
};
var isClickable = function( $el ) {
if ( $el.is('a,button,input,select,textarea') || $.isFunction( $el.get(0).onclick ) ) {
return true;
}
// Check for attributes like data-fancybox-next or data-fancybox-close
for ( var i = 0, atts = $el[0].attributes, n = atts.length; i < n; i++ ) {
if ( atts[i].nodeName.substr(0, 14) === 'data-fancybox-' ) {
return true;
}
}
return false;
};
var hasScrollbars = function( el ) {
var overflowY = window.getComputedStyle( el )['overflow-y'];
var overflowX = window.getComputedStyle( el )['overflow-x'];
var vertical = (overflowY === 'scroll' || overflowY === 'auto') && el.scrollHeight > el.clientHeight;
var horizontal = (overflowX === 'scroll' || overflowX === 'auto') && el.scrollWidth > el.clientWidth;
return vertical || horizontal;
};
var isScrollable = function ( $el ) {
var rez = false;
while ( true ) {
rez = hasScrollbars( $el.get(0) );
if ( rez ) {
break;
}
$el = $el.parent();
if ( !$el.length || $el.hasClass( 'fancybox-stage' ) || $el.is( 'body' ) ) {
break;
}
}
return rez;
};
var Guestures = function ( instance ) {
var self = this;
self.instance = instance;
self.$bg = instance.$refs.bg;
self.$stage = instance.$refs.stage;
self.$container = instance.$refs.container;
self.destroy();
self.$container.on( 'touchstart.fb.touch mousedown.fb.touch', $.proxy(self, 'ontouchstart') );
};
Guestures.prototype.destroy = function() {
this.$container.off( '.fb.touch' );
};
Guestures.prototype.ontouchstart = function( e ) {
var self = this;
var $target = $( e.target );
var instance = self.instance;
var current = instance.current;
var $content = current.$content;
var isTouchDevice = ( e.type == 'touchstart' );
// Do not respond to both events
if ( isTouchDevice ) {
self.$container.off( 'mousedown.fb.touch' );
}
// Ignore clicks while zooming or closing
if ( !current || self.instance.isAnimating || self.instance.isClosing ) {
e.stopPropagation();
e.preventDefault();
return;
}
// Ignore right click
if ( e.originalEvent && e.originalEvent.button == 2 ) {
return;
}
// Ignore taping on links, buttons, input elements
if ( !$target.length || isClickable( $target ) || isClickable( $target.parent() ) ) {
return;
}
// Ignore clicks on the scrollbar
if ( e.originalEvent.clientX > $target[0].clientWidth + $target.offset().left ) {
return;
}
self.startPoints = pointers( e );
// Prevent zooming if already swiping
if ( !self.startPoints || ( self.startPoints.length > 1 && instance.isSliding ) ) {
return;
}
self.$target = $target;
self.$content = $content;
self.canTap = true;
$(document).off( '.fb.touch' );
$(document).on( isTouchDevice ? 'touchend.fb.touch touchcancel.fb.touch' : 'mouseup.fb.touch mouseleave.fb.touch', $.proxy(self, "ontouchend"));
$(document).on( isTouchDevice ? 'touchmove.fb.touch' : 'mousemove.fb.touch', $.proxy(self, "ontouchmove"));
e.stopPropagation();
if ( !(instance.current.opts.touch || instance.canPan() ) || !( $target.is( self.$stage ) || self.$stage.find( $target ).length ) ) {
// Prevent ghosting
if ( $target.is('img') ) {
e.preventDefault();
}
return;
}
if ( !( $.fancybox.isMobile && ( isScrollable( self.$target ) || isScrollable( self.$target.parent() ) ) ) ) {
e.preventDefault();
}
self.canvasWidth = Math.round( current.$slide[0].clientWidth );
self.canvasHeight = Math.round( current.$slide[0].clientHeight );
self.startTime = new Date().getTime();
self.distanceX = self.distanceY = self.distance = 0;
self.isPanning = false;
self.isSwiping = false;
self.isZooming = false;
self.sliderStartPos = self.sliderLastPos || { top: 0, left: 0 };
self.contentStartPos = $.fancybox.getTranslate( self.$content );
self.contentLastPos = null;
if ( self.startPoints.length === 1 && !self.isZooming ) {
self.canTap = !instance.isSliding;
if ( current.type === 'image' && ( self.contentStartPos.width > self.canvasWidth + 1 || self.contentStartPos.height > self.canvasHeight + 1 ) ) {
$.fancybox.stop( self.$content );
self.$content.css( 'transition-duration', '0ms' );
self.isPanning = true;
} else {
self.isSwiping = true;
}
self.$container.addClass('fancybox-controls--isGrabbing');
}
if ( self.startPoints.length === 2 && !instance.isAnimating && !current.hasError && current.type === 'image' && ( current.isLoaded || current.$ghost ) ) {
self.isZooming = true;
self.isSwiping = false;
self.isPanning = false;
$.fancybox.stop( self.$content );
self.$content.css( 'transition-duration', '0ms' );
self.centerPointStartX = ( ( self.startPoints[0].x + self.startPoints[1].x ) * 0.5 ) - $(window).scrollLeft();
self.centerPointStartY = ( ( self.startPoints[0].y + self.startPoints[1].y ) * 0.5 ) - $(window).scrollTop();
self.percentageOfImageAtPinchPointX = ( self.centerPointStartX - self.contentStartPos.left ) / self.contentStartPos.width;
self.percentageOfImageAtPinchPointY = ( self.centerPointStartY - self.contentStartPos.top ) / self.contentStartPos.height;
self.startDistanceBetweenFingers = distance( self.startPoints[0], self.startPoints[1] );
}
};
Guestures.prototype.ontouchmove = function( e ) {
var self = this;
self.newPoints = pointers( e );
if ( $.fancybox.isMobile && ( isScrollable( self.$target ) || isScrollable( self.$target.parent() ) ) ) {
e.stopPropagation();
self.canTap = false;
return;
}
if ( !( self.instance.current.opts.touch || self.instance.canPan() ) || !self.newPoints || !self.newPoints.length ) {
return;
}
self.distanceX = distance( self.newPoints[0], self.startPoints[0], 'x' );
self.distanceY = distance( self.newPoints[0], self.startPoints[0], 'y' );
self.distance = distance( self.newPoints[0], self.startPoints[0] );
// Skip false ontouchmove events (Chrome)
if ( self.distance > 0 ) {
if ( !( self.$target.is( self.$stage ) || self.$stage.find( self.$target ).length ) ) {
return;
}
e.stopPropagation();
e.preventDefault();
if ( self.isSwiping ) {
self.onSwipe();
} else if ( self.isPanning ) {
self.onPan();
} else if ( self.isZooming ) {
self.onZoom();
}
}
};
Guestures.prototype.onSwipe = function() {
var self = this;
var swiping = self.isSwiping;
var left = self.sliderStartPos.left || 0;
var angle;
if ( swiping === true ) {
if ( Math.abs( self.distance ) > 10 ) {
self.canTap = false;
if ( self.instance.group.length < 2 && self.instance.opts.touch.vertical ) {
self.isSwiping = 'y';
} else if ( self.instance.isSliding || self.instance.opts.touch.vertical === false || ( self.instance.opts.touch.vertical === 'auto' && $( window ).width() > 800 ) ) {
self.isSwiping = 'x';
} else {
angle = Math.abs( Math.atan2( self.distanceY, self.distanceX ) * 180 / Math.PI );
self.isSwiping = ( angle > 45 && angle < 135 ) ? 'y' : 'x';
}
self.instance.isSliding = self.isSwiping;
// Reset points to avoid jumping, because we dropped first swipes to calculate the angle
self.startPoints = self.newPoints;
$.each(self.instance.slides, function( index, slide ) {
$.fancybox.stop( slide.$slide );
slide.$slide.css( 'transition-duration', '0ms' );
slide.inTransition = false;
if ( slide.pos === self.instance.current.pos ) {
self.sliderStartPos.left = $.fancybox.getTranslate( slide.$slide ).left;
}
});
//self.instance.current.isMoved = true;
// Stop slideshow
if ( self.instance.SlideShow && self.instance.SlideShow.isActive ) {
self.instance.SlideShow.stop();
}
}
} else {
if ( swiping == 'x' ) {
// Sticky edges
if ( self.distanceX > 0 && ( self.instance.group.length < 2 || ( self.instance.current.index === 0 && !self.instance.current.opts.loop ) ) ) {
left = left + Math.pow( self.distanceX, 0.8 );
} else if ( self.distanceX < 0 && ( self.instance.group.length < 2 || ( self.instance.current.index === self.instance.group.length - 1 && !self.instance.current.opts.loop ) ) ) {
left = left - Math.pow( -self.distanceX, 0.8 );
} else {
left = left + self.distanceX;
}
}
self.sliderLastPos = {
top : swiping == 'x' ? 0 : self.sliderStartPos.top + self.distanceY,
left : left
};
if ( self.requestId ) {
cancelAFrame( self.requestId );
self.requestId = null;
}
self.requestId = requestAFrame(function() {
if ( self.sliderLastPos ) {
$.each(self.instance.slides, function( index, slide ) {
var pos = slide.pos - self.instance.currPos;
$.fancybox.setTranslate( slide.$slide, {
top : self.sliderLastPos.top,
left : self.sliderLastPos.left + ( pos * self.canvasWidth ) + ( pos * slide.opts.gutter )
});
});
self.$container.addClass( 'fancybox-is-sliding' );
}
});
}
};
Guestures.prototype.onPan = function() {
var self = this;
var newOffsetX, newOffsetY, newPos;
self.canTap = false;
if ( self.contentStartPos.width > self.canvasWidth ) {
newOffsetX = self.contentStartPos.left + self.distanceX;
} else {
newOffsetX = self.contentStartPos.left;
}
newOffsetY = self.contentStartPos.top + self.distanceY;
newPos = self.limitMovement( newOffsetX, newOffsetY, self.contentStartPos.width, self.contentStartPos.height );
newPos.scaleX = self.contentStartPos.scaleX;
newPos.scaleY = self.contentStartPos.scaleY;
self.contentLastPos = newPos;
if ( self.requestId ) {
cancelAFrame( self.requestId );
self.requestId = null;
}
self.requestId = requestAFrame(function() {
$.fancybox.setTranslate( self.$content, self.contentLastPos );
});
};
// Make panning sticky to the edges
Guestures.prototype.limitMovement = function( newOffsetX, newOffsetY, newWidth, newHeight ) {
var self = this;
var minTranslateX, minTranslateY, maxTranslateX, maxTranslateY;
var canvasWidth = self.canvasWidth;
var canvasHeight = self.canvasHeight;
var currentOffsetX = self.contentStartPos.left;
var currentOffsetY = self.contentStartPos.top;
var distanceX = self.distanceX;
var distanceY = self.distanceY;
// Slow down proportionally to traveled distance
minTranslateX = Math.max(0, canvasWidth * 0.5 - newWidth * 0.5 );
minTranslateY = Math.max(0, canvasHeight * 0.5 - newHeight * 0.5 );
maxTranslateX = Math.min( canvasWidth - newWidth, canvasWidth * 0.5 - newWidth * 0.5 );
maxTranslateY = Math.min( canvasHeight - newHeight, canvasHeight * 0.5 - newHeight * 0.5 );
if ( newWidth > canvasWidth ) {
// ->
if ( distanceX > 0 && newOffsetX > minTranslateX ) {
newOffsetX = minTranslateX - 1 + Math.pow( -minTranslateX + currentOffsetX + distanceX, 0.8 ) || 0;
}
// <-
if ( distanceX < 0 && newOffsetX < maxTranslateX ) {
newOffsetX = maxTranslateX + 1 - Math.pow( maxTranslateX - currentOffsetX - distanceX, 0.8 ) || 0;
}
}
if ( newHeight > canvasHeight ) {
// \/
if ( distanceY > 0 && newOffsetY > minTranslateY ) {
newOffsetY = minTranslateY - 1 + Math.pow(-minTranslateY + currentOffsetY + distanceY, 0.8 ) || 0;
}
// /\
if ( distanceY < 0 && newOffsetY < maxTranslateY ) {
newOffsetY = maxTranslateY + 1 - Math.pow ( maxTranslateY - currentOffsetY - distanceY, 0.8 ) || 0;
}
}
return {
top : newOffsetY,
left : newOffsetX
};
};
Guestures.prototype.limitPosition = function( newOffsetX, newOffsetY, newWidth, newHeight ) {
var self = this;
var canvasWidth = self.canvasWidth;
var canvasHeight = self.canvasHeight;
if ( newWidth > canvasWidth ) {
newOffsetX = newOffsetX > 0 ? 0 : newOffsetX;
newOffsetX = newOffsetX < canvasWidth - newWidth ? canvasWidth - newWidth : newOffsetX;
} else {
// Center horizontally
newOffsetX = Math.max( 0, canvasWidth / 2 - newWidth / 2 );
}
if ( newHeight > canvasHeight ) {
newOffsetY = newOffsetY > 0 ? 0 : newOffsetY;
newOffsetY = newOffsetY < canvasHeight - newHeight ? canvasHeight - newHeight : newOffsetY;
} else {
// Center vertically
newOffsetY = Math.max( 0, canvasHeight / 2 - newHeight / 2 );
}
return {
top : newOffsetY,
left : newOffsetX
};
};
Guestures.prototype.onZoom = function() {
var self = this;
// Calculate current distance between points to get pinch ratio and new width and height
var currentWidth = self.contentStartPos.width;
var currentHeight = self.contentStartPos.height;
var currentOffsetX = self.contentStartPos.left;
var currentOffsetY = self.contentStartPos.top;
var endDistanceBetweenFingers = distance( self.newPoints[0], self.newPoints[1] );
var pinchRatio = endDistanceBetweenFingers / self.startDistanceBetweenFingers;
var newWidth = Math.floor( currentWidth * pinchRatio );
var newHeight = Math.floor( currentHeight * pinchRatio );
// This is the translation due to pinch-zooming
var translateFromZoomingX = (currentWidth - newWidth) * self.percentageOfImageAtPinchPointX;
var translateFromZoomingY = (currentHeight - newHeight) * self.percentageOfImageAtPinchPointY;
//Point between the two touches
var centerPointEndX = ((self.newPoints[0].x + self.newPoints[1].x) / 2) - $(window).scrollLeft();
var centerPointEndY = ((self.newPoints[0].y + self.newPoints[1].y) / 2) - $(window).scrollTop();
// And this is the translation due to translation of the centerpoint
// between the two fingers
var translateFromTranslatingX = centerPointEndX - self.centerPointStartX;
var translateFromTranslatingY = centerPointEndY - self.centerPointStartY;
// The new offset is the old/current one plus the total translation
var newOffsetX = currentOffsetX + ( translateFromZoomingX + translateFromTranslatingX );
var newOffsetY = currentOffsetY + ( translateFromZoomingY + translateFromTranslatingY );
var newPos = {
top : newOffsetY,
left : newOffsetX,
scaleX : self.contentStartPos.scaleX * pinchRatio,
scaleY : self.contentStartPos.scaleY * pinchRatio
};
self.canTap = false;
self.newWidth = newWidth;
self.newHeight = newHeight;
self.contentLastPos = newPos;
if ( self.requestId ) {
cancelAFrame( self.requestId );
self.requestId = null;
}
self.requestId = requestAFrame(function() {
$.fancybox.setTranslate( self.$content, self.contentLastPos );
});
};
Guestures.prototype.ontouchend = function( e ) {
var self = this;
var dMs = Math.max( (new Date().getTime() ) - self.startTime, 1);
var swiping = self.isSwiping;
var panning = self.isPanning;
var zooming = self.isZooming;
self.endPoints = pointers( e );
self.$container.removeClass( 'fancybox-controls--isGrabbing' );
$(document).off( '.fb.touch' );
if ( self.requestId ) {
cancelAFrame( self.requestId );
self.requestId = null;
}
self.isSwiping = false;
self.isPanning = false;
self.isZooming = false;
if ( self.canTap ) {
return self.onTap( e );
}
self.speed = 366;
// Speed in px/ms
self.velocityX = self.distanceX / dMs * 0.5;
self.velocityY = self.distanceY / dMs * 0.5;
self.speedX = Math.max( self.speed * 0.5, Math.min( self.speed * 1.5, ( 1 / Math.abs( self.velocityX ) ) * self.speed ) );
if ( panning ) {
self.endPanning();
} else if ( zooming ) {
self.endZooming();
} else {
self.endSwiping( swiping );
}
return;
};
Guestures.prototype.endSwiping = function( swiping ) {
var self = this;
var ret = false;
self.instance.isSliding = false;
self.sliderLastPos = null;
// Close if swiped vertically / navigate if horizontally
if ( swiping == 'y' && Math.abs( self.distanceY ) > 50 ) {
// Continue vertical movement
$.fancybox.animate( self.instance.current.$slide, {
top : self.sliderStartPos.top + self.distanceY + ( self.velocityY * 150 ),
opacity : 0
}, 150 );
ret = self.instance.close( true, 300 );
} else if ( swiping == 'x' && self.distanceX > 50 && self.instance.group.length > 1 ) {
ret = self.instance.previous( self.speedX );
} else if ( swiping == 'x' && self.distanceX < -50 && self.instance.group.length > 1 ) {
ret = self.instance.next( self.speedX );
}
if ( ret === false && ( swiping == 'x' || swiping == 'y' ) ) {
self.instance.jumpTo( self.instance.current.index, 150 );
}
self.$container.removeClass( 'fancybox-is-sliding' );
};
// Limit panning from edges
// ========================
Guestures.prototype.endPanning = function() {
var self = this;
var newOffsetX, newOffsetY, newPos;
if ( !self.contentLastPos ) {
return;
}
if ( self.instance.current.opts.touch.momentum === false ) {
newOffsetX = self.contentLastPos.left;
newOffsetY = self.contentLastPos.top;
} else {
// Continue movement
newOffsetX = self.contentLastPos.left + ( self.velocityX * self.speed );
newOffsetY = self.contentLastPos.top + ( self.velocityY * self.speed );
}
newPos = self.limitPosition( newOffsetX, newOffsetY, self.contentStartPos.width, self.contentStartPos.height );
newPos.width = self.contentStartPos.width;
newPos.height = self.contentStartPos.height;
$.fancybox.animate( self.$content, newPos, 330 );
};
Guestures.prototype.endZooming = function() {
var self = this;
var current = self.instance.current;
var newOffsetX, newOffsetY, newPos, reset;
var newWidth = self.newWidth;
var newHeight = self.newHeight;
if ( !self.contentLastPos ) {
return;
}
newOffsetX = self.contentLastPos.left;
newOffsetY = self.contentLastPos.top;
reset = {
top : newOffsetY,
left : newOffsetX,
width : newWidth,
height : newHeight,
scaleX : 1,
scaleY : 1
};
// Reset scalex/scaleY values; this helps for perfomance and does not break animation
$.fancybox.setTranslate( self.$content, reset );
if ( newWidth < self.canvasWidth && newHeight < self.canvasHeight ) {
self.instance.scaleToFit( 150 );
} else if ( newWidth > current.width || newHeight > current.height ) {
self.instance.scaleToActual( self.centerPointStartX, self.centerPointStartY, 150 );
} else {
newPos = self.limitPosition( newOffsetX, newOffsetY, newWidth, newHeight );
// Switch from scale() to width/height or animation will not work correctly
$.fancybox.setTranslate( self.content, $.fancybox.getTranslate( self.$content ) );
$.fancybox.animate( self.$content, newPos, 150 );
}
};
Guestures.prototype.onTap = function(e) {
var self = this;
var $target = $( e.target );
var instance = self.instance;
var current = instance.current;
var endPoints = ( e && pointers( e ) ) || self.startPoints;
var tapX = endPoints[0] ? endPoints[0].x - self.$stage.offset().left : 0;
var tapY = endPoints[0] ? endPoints[0].y - self.$stage.offset().top : 0;
var where;
var process = function ( prefix ) {
var action = current.opts[ prefix ];
if ( $.isFunction( action ) ) {
action = action.apply( instance, [ current, e ] );
}
if ( !action) {
return;
}
switch ( action ) {
case "close" :
instance.close( self.startEvent );
break;
case "toggleControls" :
instance.toggleControls( true );
break;
case "next" :
instance.next();
break;
case "nextOrClose" :
if ( instance.group.length > 1 ) {
instance.next();
} else {
instance.close( self.startEvent );
}
break;
case "zoom" :
if ( current.type == 'image' && ( current.isLoaded || current.$ghost ) ) {
if ( instance.canPan() ) {
instance.scaleToFit();
} else if ( instance.isScaledDown() ) {
instance.scaleToActual( tapX, tapY );
} else if ( instance.group.length < 2 ) {
instance.close( self.startEvent );
}
}
break;
}
};
// Ignore right click
if ( e.originalEvent && e.originalEvent.button == 2 ) {
return;
}
// Skip if current slide is not in the center
if ( instance.isSliding ) {
return;
}
// Skip if clicked on the scrollbar
if ( tapX > $target[0].clientWidth + $target.offset().left ) {
return;
}
// Check where is clicked
if ( $target.is( '.fancybox-bg,.fancybox-inner,.fancybox-outer,.fancybox-container' ) ) {
where = 'Outside';
} else if ( $target.is( '.fancybox-slide' ) ) {
where = 'Slide';
} else if ( instance.current.$content && instance.current.$content.has( e.target ).length ) {
where = 'Content';
} else {
return;
}
// Check if this is a double tap
if ( self.tapped ) {
// Stop previously created single tap
clearTimeout( self.tapped );
self.tapped = null;
// Skip if distance between taps is too big
if ( Math.abs( tapX - self.tapX ) > 50 || Math.abs( tapY - self.tapY ) > 50 || instance.isSliding ) {
return this;
}
// OK, now we assume that this is a double-tap
process( 'dblclick' + where );
} else {
// Single tap will be processed if user has not clicked second time within 300ms
// or there is no need to wait for double-tap
self.tapX = tapX;
self.tapY = tapY;
if ( current.opts[ 'dblclick' + where ] && current.opts[ 'dblclick' + where ] !== current.opts[ 'click' + where ] ) {
self.tapped = setTimeout(function() {
self.tapped = null;
process( 'click' + where );
}, 300);
} else {
process( 'click' + where );
}
}
return this;
};
$(document).on('onActivate.fb', function (e, instance) {
if ( instance && !instance.Guestures ) {
instance.Guestures = new Guestures( instance );
}
});
$(document).on('beforeClose.fb', function (e, instance) {
if ( instance && instance.Guestures ) {
instance.Guestures.destroy();
}
});
}(window, document, window.jQuery));
// ==========================================================================
//
// SlideShow
// Enables slideshow functionality
//
// Example of usage:
// $.fancybox.getInstance().SlideShow.start()
//
// ==========================================================================
;(function (document, $) {
'use strict';
var SlideShow = function( instance ) {
this.instance = instance;
this.init();
};
$.extend( SlideShow.prototype, {
timer : null,
isActive : false,
$button : null,
speed : 3000,
init : function() {
var self = this;
self.$button = self.instance.$refs.toolbar.find('[data-fancybox-play]').on('click', function() {
self.toggle();
});
if ( self.instance.group.length < 2 || !self.instance.group[ self.instance.currIndex ].opts.slideShow ) {
self.$button.hide();
}
},
set : function() {
var self = this;
// Check if reached last element
if ( self.instance && self.instance.current && (self.instance.current.opts.loop || self.instance.currIndex < self.instance.group.length - 1 )) {
self.timer = setTimeout(function() {
self.instance.next();
}, self.instance.current.opts.slideShow.speed || self.speed);
} else {
self.stop();
self.instance.idleSecondsCounter = 0;
self.instance.showControls();
}
},
clear : function() {
var self = this;
clearTimeout( self.timer );
self.timer = null;
},
start : function() {
var self = this;
var current = self.instance.current;
if ( self.instance && current && ( current.opts.loop || current.index < self.instance.group.length - 1 )) {
self.isActive = true;
self.$button
.attr( 'title', current.opts.i18n[ current.opts.lang ].PLAY_STOP )
.addClass( 'fancybox-button--pause' );
if ( current.isComplete ) {
self.set();
}
}
},
stop : function() {
var self = this;
var current = self.instance.current;
self.clear();
self.$button
.attr( 'title', current.opts.i18n[ current.opts.lang ].PLAY_START )
.removeClass( 'fancybox-button--pause' );
self.isActive = false;
},
toggle : function() {
var self = this;
if ( self.isActive ) {
self.stop();
} else {
self.start();
}
}
});
$(document).on({
'onInit.fb' : function(e, instance) {
if ( instance && !instance.SlideShow ) {
instance.SlideShow = new SlideShow( instance );
}
},
'beforeShow.fb' : function(e, instance, current, firstRun) {
var SlideShow = instance && instance.SlideShow;
if ( firstRun ) {
if ( SlideShow && current.opts.slideShow.autoStart ) {
SlideShow.start();
}
} else if ( SlideShow && SlideShow.isActive ) {
SlideShow.clear();
}
},
'afterShow.fb' : function(e, instance, current) {
var SlideShow = instance && instance.SlideShow;
if ( SlideShow && SlideShow.isActive ) {
SlideShow.set();
}
},
'afterKeydown.fb' : function(e, instance, current, keypress, keycode) {
var SlideShow = instance && instance.SlideShow;
// "P" or Spacebar
if ( SlideShow && current.opts.slideShow && ( keycode === 80 || keycode === 32 ) && !$(document.activeElement).is( 'button,a,input' ) ) {
keypress.preventDefault();
SlideShow.toggle();
}
},
'beforeClose.fb onDeactivate.fb' : function(e, instance) {
var SlideShow = instance && instance.SlideShow;
if ( SlideShow ) {
SlideShow.stop();
}
}
});
// Page Visibility API to pause slideshow when window is not active
$(document).on("visibilitychange", function() {
var instance = $.fancybox.getInstance();
var SlideShow = instance && instance.SlideShow;
if ( SlideShow && SlideShow.isActive ) {
if ( document.hidden ) {
SlideShow.clear();
} else {
SlideShow.set();
}
}
});
}(document, window.jQuery));
// ==========================================================================
//
// FullScreen
// Adds fullscreen functionality
//
// ==========================================================================
;(function (document, $) {
'use strict';
// Collection of methods supported by user browser
var fn = (function () {
var fnMap = [
[
'requestFullscreen',
'exitFullscreen',
'fullscreenElement',
'fullscreenEnabled',
'fullscreenchange',
'fullscreenerror'
],
// new WebKit
[
'webkitRequestFullscreen',
'webkitExitFullscreen',
'webkitFullscreenElement',
'webkitFullscreenEnabled',
'webkitfullscreenchange',
'webkitfullscreenerror'
],
// old WebKit (Safari 5.1)
[
'webkitRequestFullScreen',
'webkitCancelFullScreen',
'webkitCurrentFullScreenElement',
'webkitCancelFullScreen',
'webkitfullscreenchange',
'webkitfullscreenerror'
],
[
'mozRequestFullScreen',
'mozCancelFullScreen',
'mozFullScreenElement',
'mozFullScreenEnabled',
'mozfullscreenchange',
'mozfullscreenerror'
],
[
'msRequestFullscreen',
'msExitFullscreen',
'msFullscreenElement',
'msFullscreenEnabled',
'MSFullscreenChange',
'MSFullscreenError'
]
];
var val;
var ret = {};
var i, j;
for ( i = 0; i < fnMap.length; i++ ) {
val = fnMap[ i ];
if ( val && val[ 1 ] in document ) {
for ( j = 0; j < val.length; j++ ) {
ret[ fnMap[ 0 ][ j ] ] = val[ j ];
}
return ret;
}
}
return false;
})();
// If browser does not have Full Screen API, then simply unset default button template and stop
if ( !fn ) {
$.fancybox.defaults.btnTpl.fullScreen = false;
return;
}
var FullScreen = {
request : function ( elem ) {
elem = elem || document.documentElement;
elem[ fn.requestFullscreen ]( elem.ALLOW_KEYBOARD_INPUT );
},
exit : function () {
document[ fn.exitFullscreen ]();
},
toggle : function ( elem ) {
elem = elem || document.documentElement;
if ( this.isFullscreen() ) {
this.exit();
} else {
this.request( elem );
}
},
isFullscreen : function() {
return Boolean( document[ fn.fullscreenElement ] );
},
enabled : function() {
return Boolean( document[ fn.fullscreenEnabled ] );
}
};
$(document).on({
'onInit.fb' : function(e, instance) {
var $container;
var $button = instance.$refs.toolbar.find('[data-fancybox-fullscreen]');
if ( instance && !instance.FullScreen && instance.group[ instance.currIndex ].opts.fullScreen ) {
$container = instance.$refs.container;
$container.on('click.fb-fullscreen', '[data-fancybox-fullscreen]', function(e) {
e.stopPropagation();
e.preventDefault();
FullScreen.toggle( $container[ 0 ] );
});
if ( instance.opts.fullScreen && instance.opts.fullScreen.autoStart === true ) {
FullScreen.request( $container[ 0 ] );
}
// Expose API
instance.FullScreen = FullScreen;
} else {
$button.hide();
}
},
'afterKeydown.fb' : function(e, instance, current, keypress, keycode) {
// "P" or Spacebar
if ( instance && instance.FullScreen && keycode === 70 ) {
keypress.preventDefault();
instance.FullScreen.toggle( instance.$refs.container[ 0 ] );
}
},
'beforeClose.fb' : function( instance ) {
if ( instance && instance.FullScreen ) {
FullScreen.exit();
}
}
});
$(document).on(fn.fullscreenchange, function() {
var instance = $.fancybox.getInstance();
// If image is zooming, then force to stop and reposition properly
if ( instance.current && instance.current.type === 'image' && instance.isAnimating ) {
instance.current.$content.css( 'transition', 'none' );
instance.isAnimating = false;
instance.update( true, true, 0 );
}
});
}(document, window.jQuery));
// ==========================================================================
//
// Thumbs
// Displays thumbnails in a grid
//
// ==========================================================================
;(function (document, $) {
'use strict';
var FancyThumbs = function( instance ) {
this.instance = instance;
this.init();
};
$.extend( FancyThumbs.prototype, {
$button : null,
$grid : null,
$list : null,
isVisible : false,
init : function() {
var self = this;
var first = self.instance.group[0],
second = self.instance.group[1];
self.$button = self.instance.$refs.toolbar.find( '[data-fancybox-thumbs]' );
if ( self.instance.group.length > 1 && self.instance.group[ self.instance.currIndex ].opts.thumbs && (
( first.type == 'image' || first.opts.thumb || first.opts.$thumb ) &&
( second.type == 'image' || second.opts.thumb || second.opts.$thumb )
)) {
self.$button.on('click', function() {
self.toggle();
});
self.isActive = true;
} else {
self.$button.hide();
self.isActive = false;
}
},
create : function() {
var instance = this.instance,
list,
src;
this.$grid = $('
').appendTo( instance.$refs.container );
list = '
';
$.each(instance.group, function( i, item ) {
src = item.opts.thumb || ( item.opts.$thumb ? item.opts.$thumb.attr('src') : null );
if ( !src && item.type === 'image' ) {
src = item.src;
}
if ( src && src.length ) {
list += '';
}
});
list += '
';
this.$list = $( list ).appendTo( this.$grid ).on('click', 'li', function() {
instance.jumpTo( $(this).data('index') );
});
this.$list.find('img').hide().one('load', function() {
var $parent = $(this).parent().removeClass('fancybox-thumbs-loading'),
thumbWidth = $parent.outerWidth(),
thumbHeight = $parent.outerHeight(),
width,
height,
widthRatio,
heightRatio;
width = this.naturalWidth || this.width;
height = this.naturalHeight || this.height;
//Calculate thumbnail width/height and center it
widthRatio = width / thumbWidth;
heightRatio = height / thumbHeight;
if (widthRatio >= 1 && heightRatio >= 1) {
if (widthRatio > heightRatio) {
width = width / heightRatio;
height = thumbHeight;
} else {
width = thumbWidth;
height = height / widthRatio;
}
}
$(this).css({
width : Math.floor(width),
height : Math.floor(height),
'margin-top' : Math.min( 0, Math.floor(thumbHeight * 0.3 - height * 0.3 ) ),
'margin-left' : Math.min( 0, Math.floor(thumbWidth * 0.5 - width * 0.5 ) )
}).show();
})
.each(function() {
this.src = $( this ).data( 'src' );
});
},
focus : function() {
if ( this.instance.current ) {
this.$list
.children()
.removeClass('fancybox-thumbs-active')
.filter('[data-index="' + this.instance.current.index + '"]')
.addClass('fancybox-thumbs-active')
.focus();
}
},
close : function() {
this.$grid.hide();
},
update : function() {
this.instance.$refs.container.toggleClass( 'fancybox-show-thumbs', this.isVisible );
if ( this.isVisible ) {
if ( !this.$grid ) {
this.create();
}
this.instance.trigger( 'onThumbsShow' );
this.focus();
} else if ( this.$grid ) {
this.instance.trigger( 'onThumbsHide' );
}
// Update content position
this.instance.update();
},
hide : function() {
this.isVisible = false;
this.update();
},
show : function() {
this.isVisible = true;
this.update();
},
toggle : function() {
this.isVisible = !this.isVisible;
this.update();
}
});
$(document).on({
'onInit.fb' : function(e, instance) {
if ( instance && !instance.Thumbs ) {
instance.Thumbs = new FancyThumbs( instance );
}
},
'beforeShow.fb' : function(e, instance, item, firstRun) {
var Thumbs = instance && instance.Thumbs;
if ( !Thumbs || !Thumbs.isActive ) {
return;
}
if ( item.modal ) {
Thumbs.$button.hide();
Thumbs.hide();
return;
}
if ( firstRun && instance.opts.thumbs.autoStart === true ) {
Thumbs.show();
}
if ( Thumbs.isVisible ) {
Thumbs.focus();
}
},
'afterKeydown.fb' : function(e, instance, current, keypress, keycode) {
var Thumbs = instance && instance.Thumbs;
// "G"
if ( Thumbs && Thumbs.isActive && keycode === 71 ) {
keypress.preventDefault();
Thumbs.toggle();
}
},
'beforeClose.fb' : function( e, instance ) {
var Thumbs = instance && instance.Thumbs;
if ( Thumbs && Thumbs.isVisible && instance.opts.thumbs.hideOnClose !== false ) {
Thumbs.close();
}
}
});
}(document, window.jQuery));
// ==========================================================================
//
// Hash
// Enables linking to each modal
//
// ==========================================================================
;(function (document, window, $) {
'use strict';
// Simple $.escapeSelector polyfill (for jQuery prior v3)
if ( !$.escapeSelector ) {
$.escapeSelector = function( sel ) {
var rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g;
var fcssescape = function( ch, asCodePoint ) {
if ( asCodePoint ) {
// U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER
if ( ch === "\0" ) {
return "\uFFFD";
}
// Control characters and (dependent upon position) numbers get escaped as code points
return ch.slice( 0, -1 ) + "\\" + ch.charCodeAt( ch.length - 1 ).toString( 16 ) + " ";
}
// Other potentially-special ASCII characters get backslash-escaped
return "\\" + ch;
};
return ( sel + "" ).replace( rcssescape, fcssescape );
};
}
// Variable containing last hash value set by fancyBox
// It will be used to determine if fancyBox needs to close after hash change is detected
var currentHash = null;
// Throtlling the history change
var timerID = null;
// Get info about gallery name and current index from url
function parseUrl() {
var hash = window.location.hash.substr( 1 );
var rez = hash.split( '-' );
var index = rez.length > 1 && /^\+?\d+$/.test( rez[ rez.length - 1 ] ) ? parseInt( rez.pop( -1 ), 10 ) || 1 : 1;
var gallery = rez.join( '-' );
// Index is starting from 1
if ( index < 1 ) {
index = 1;
}
return {
hash : hash,
index : index,
gallery : gallery
};
}
// Trigger click evnt on links to open new fancyBox instance
function triggerFromUrl( url ) {
var $el;
if ( url.gallery !== '' ) {
// If we can find element matching 'data-fancybox' atribute, then trigger click event for that ..
$el = $( "[data-fancybox='" + $.escapeSelector( url.gallery ) + "']" ).eq( url.index - 1 );
if ( $el.length ) {
$el.trigger( 'click' );
} else {
// .. if not, try finding element by ID
$( "#" + $.escapeSelector( url.gallery ) + "" ).trigger( 'click' );
}
}
}
// Get gallery name from current instance
function getGallery( instance ) {
var opts;
if ( !instance ) {
return false;
}
opts = instance.current ? instance.current.opts : instance.opts;
return opts.$orig ? opts.$orig.data( 'fancybox' ) : ( opts.hash || '' );
}
// Star when DOM becomes ready
$(function() {
// Small delay is used to allow other scripts to process "dom ready" event
setTimeout(function() {
// Check if this module is not disabled
if ( $.fancybox.defaults.hash === false ) {
return;
}
// Update hash when opening/closing fancyBox
$(document).on({
'onInit.fb' : function( e, instance ) {
var url, gallery;
if ( instance.group[ instance.currIndex ].opts.hash === false ) {
return;
}
url = parseUrl();
gallery = getGallery( instance );
// Make sure gallery start index matches index from hash
if ( gallery && url.gallery && gallery == url.gallery ) {
instance.currIndex = url.index - 1;
}
},
'beforeShow.fb' : function( e, instance, current, firstRun ) {
var gallery;
if ( current.opts.hash === false ) {
return;
}
gallery = getGallery( instance );
// Update window hash
if ( gallery && gallery !== '' ) {
if ( window.location.hash.indexOf( gallery ) < 0 ) {
instance.opts.origHash = window.location.hash;
}
currentHash = gallery + ( instance.group.length > 1 ? '-' + ( current.index + 1 ) : '' );
if ( 'replaceState' in window.history ) {
if ( timerID ) {
clearTimeout( timerID );
}
timerID = setTimeout(function() {
window.history[ firstRun ? 'pushState' : 'replaceState' ]( {} , document.title, window.location.pathname + window.location.search + '#' + currentHash );
timerID = null;
}, 300);
} else {
window.location.hash = currentHash;
}
}
},
'beforeClose.fb' : function( e, instance, current ) {
var gallery, origHash;
if ( timerID ) {
clearTimeout( timerID );
}
if ( current.opts.hash === false ) {
return;
}
gallery = getGallery( instance );
origHash = instance && instance.opts.origHash ? instance.opts.origHash : '';
// Remove hash from location bar
if ( gallery && gallery !== '' ) {
if ( 'replaceState' in history ) {
window.history.replaceState( {} , document.title, window.location.pathname + window.location.search + origHash );
} else {
window.location.hash = origHash;
// Keep original scroll position
$( window ).scrollTop( instance.scrollTop ).scrollLeft( instance.scrollLeft );
}
}
currentHash = null;
}
});
// Check if need to close after url has changed
$(window).on('hashchange.fb', function() {
var url = parseUrl();
if ( $.fancybox.getInstance() ) {
if ( currentHash && currentHash !== url.gallery + '-' + url.index && !( url.index === 1 && currentHash == url.gallery ) ) {
currentHash = null;
$.fancybox.close();
}
} else if ( url.gallery !== '' ) {
triggerFromUrl( url );
}
});
// If navigating away from current page
$(window).one('unload.fb popstate.fb', function() {
$.fancybox.getInstance( 'close', true, 0 );
});
// Check current hash and trigger click event on matching element to start fancyBox, if needed
triggerFromUrl( parseUrl() );
}, 50);
});
}(document, window, window.jQuery));