/*!
* fancybox - jquery plugin
* version: 2.1.5 (fri, 14 jun 2013)
* @requires jquery v1.6 or later
*
* examples at http://fancyapps.com/fancybox/
* license: www.fancyapps.com/fancybox/#license
*
* copyright 2012 janis skarnelis - janis@fancyapps.com
*
*/
(function (window, document, $, undefined) {
"use strict";
var h = $("html"),
w = $(window),
d = $(document),
f = $.fancybox = function () {
f.open.apply( this, arguments );
},
ie = navigator.useragent.match(/msie/i),
didupdate = null,
istouch = document.createtouch !== undefined,
isquery = function(obj) {
return obj && obj.hasownproperty && obj instanceof $;
},
isstring = function(str) {
return str && $.type(str) === "string";
},
ispercentage = function(str) {
return isstring(str) && str.indexof('%') > 0;
},
isscrollable = function(el) {
return (el && !(el.style.overflow && el.style.overflow === 'hidden') && ((el.clientwidth && el.scrollwidth > el.clientwidth) || (el.clientheight && el.scrollheight > el.clientheight)));
},
getscalar = function(orig, dim) {
var value = parseint(orig, 10) || 0;
if (dim && ispercentage(orig)) {
value = f.getviewport()[ dim ] / 100 * value;
}
return math.ceil(value);
},
getvalue = function(value, dim) {
return getscalar(value, dim) + 'px';
};
$.extend(f, {
// the current version of fancybox
version: '2.1.5',
defaults: {
padding : 15,
margin : 58,
width : 800,
height : 600,
minwidth : 100,
minheight : 100,
maxwidth : 9999,
maxheight : 9999,
pixelratio: 1, // set to 2 for retina display support
autosize : true,
autoheight : false,
autowidth : false,
autoresize : true,
autocenter : !istouch,
fittoview : true,
aspectratio : false,
topratio : 0.5,
leftratio : 0.5,
scrolling : 'auto', // 'auto', 'yes' or 'no'
wrapcss : '',
arrows : true,
closebtn : true,
closeclick : false,
nextclick : false,
mousewheel : true,
autoplay : false,
playspeed : 3000,
preload : 3,
modal : false,
loop : true,
ajax : {
datatype : 'html',
headers : { 'x-fancybox': true }
},
iframe : {
scrolling : 'auto',
preload : true
},
swf : {
wmode: 'transparent',
allowfullscreen : 'true',
allowscriptaccess : 'always'
},
keys : {
next : {
13 : 'left', // enter
34 : 'up', // page down
39 : 'left', // right arrow
40 : 'up' // down arrow
},
prev : {
8 : 'right', // backspace
33 : 'down', // page up
37 : 'right', // left arrow
38 : 'down' // up arrow
},
close : [27], // escape key
play : [32], // space - start/stop slideshow
toggle : [70] // letter "f" - toggle fullscreen
},
direction : {
next : 'left',
prev : 'right'
},
scrolloutside : true,
// override some properties
index : 0,
type : null,
href : null,
content : null,
title : null,
// html templates
tpl: {
wrap : '
the requested content cannot be loaded.
please try again later.
',
closebtn : '').html(content).find(current.selector);
} else if (isquery(content)) {
if (!content.data(placeholder)) {
content.data(placeholder, $('
').insertafter( content ).hide() );
}
content = content.show().detach();
current.wrap.bind('onreset', function () {
if ($(this).find(content).length) {
content.hide().replaceall( content.data(placeholder) ).data(placeholder, false);
}
});
}
break;
case 'image':
content = current.tpl.image.replace('{href}', href);
break;
case 'swf':
content = '
';
break;
}
if (!(isquery(content) && content.parent().is(current.inner))) {
current.inner.append( content );
}
// give a chance for helpers or callbacks to update elements
f.trigger('beforeshow');
// set scrolling before calculating dimensions
current.inner.css('overflow', scrolling === 'yes' ? 'scroll' : (scrolling === 'no' ? 'hidden' : scrolling));
// set initial dimensions and start position
f._setdimension();
f.reposition();
f.isopen = false;
f.coming = null;
f.bindevents();
if (!f.isopened) {
$('.fancybox-wrap').not( current.wrap ).stop(true).trigger('onreset').remove();
} else if (previous.prevmethod) {
f.transitions[ previous.prevmethod ]();
}
f.transitions[ f.isopened ? current.nextmethod : current.openmethod ]();
f._preloadimages();
},
_setdimension: function () {
var viewport = f.getviewport(),
steps = 0,
canshrink = false,
canexpand = false,
wrap = f.wrap,
skin = f.skin,
inner = f.inner,
current = f.current,
width = current.width,
height = current.height,
minwidth = current.minwidth,
minheight = current.minheight,
maxwidth = current.maxwidth,
maxheight = current.maxheight,
scrolling = current.scrolling,
scrollout = current.scrolloutside ? current.scrollbarwidth : 0,
margin = current.margin,
wmargin = getscalar(margin[1] + margin[3]),
hmargin = getscalar(margin[0] + margin[2]),
wpadding,
hpadding,
wspace,
hspace,
origwidth,
origheight,
origmaxwidth,
origmaxheight,
ratio,
width_,
height_,
maxwidth_,
maxheight_,
iframe,
body;
// reset dimensions so we could re-check actual size
wrap.add(skin).add(inner).width('auto').height('auto').removeclass('fancybox-tmp');
wpadding = getscalar(skin.outerwidth(true) - skin.width());
hpadding = getscalar(skin.outerheight(true) - skin.height());
// any space between content and viewport (margin, padding, border, title)
wspace = wmargin + wpadding;
hspace = hmargin + hpadding;
origwidth = ispercentage(width) ? (viewport.w - wspace) * getscalar(width) / 100 : width;
origheight = ispercentage(height) ? (viewport.h - hspace) * getscalar(height) / 100 : height;
if (current.type === 'iframe') {
iframe = current.content;
if (current.autoheight && iframe.data('ready') === 1) {
try {
if (iframe[0].contentwindow.document.location) {
inner.width( origwidth ).height(9999);
body = iframe.contents().find('body');
if (scrollout) {
body.css('overflow-x', 'hidden');
}
origheight = body.outerheight(true);
}
} catch (e) {}
}
} else if (current.autowidth || current.autoheight) {
inner.addclass( 'fancybox-tmp' );
// set width or height in case we need to calculate only one dimension
if (!current.autowidth) {
inner.width( origwidth );
}
if (!current.autoheight) {
inner.height( origheight );
}
if (current.autowidth) {
origwidth = inner.width();
}
if (current.autoheight) {
origheight = inner.height();
}
inner.removeclass( 'fancybox-tmp' );
}
width = getscalar( origwidth );
height = getscalar( origheight );
ratio = origwidth / origheight;
// calculations for the content
minwidth = getscalar(ispercentage(minwidth) ? getscalar(minwidth, 'w') - wspace : minwidth);
maxwidth = getscalar(ispercentage(maxwidth) ? getscalar(maxwidth, 'w') - wspace : maxwidth);
minheight = getscalar(ispercentage(minheight) ? getscalar(minheight, 'h') - hspace : minheight);
maxheight = getscalar(ispercentage(maxheight) ? getscalar(maxheight, 'h') - hspace : maxheight);
// these will be used to determine if wrap can fit in the viewport
origmaxwidth = maxwidth;
origmaxheight = maxheight;
if (current.fittoview) {
maxwidth = math.min(viewport.w - wspace, maxwidth);
maxheight = math.min(viewport.h - hspace, maxheight);
}
maxwidth_ = viewport.w - wmargin;
maxheight_ = viewport.h - hmargin;
if (current.aspectratio) {
if (width > maxwidth) {
width = maxwidth;
height = getscalar(width / ratio);
}
if (height > maxheight) {
height = maxheight;
width = getscalar(height * ratio);
}
if (width < minwidth) {
width = minwidth;
height = getscalar(width / ratio);
}
if (height < minheight) {
height = minheight;
width = getscalar(height * ratio);
}
} else {
width = math.max(minwidth, math.min(width, maxwidth));
if (current.autoheight && current.type !== 'iframe') {
inner.width( width );
height = inner.height();
}
height = math.max(minheight, math.min(height, maxheight));
}
// try to fit inside viewport (including the title)
if (current.fittoview) {
inner.width( width ).height( height );
wrap.width( width + wpadding );
// real wrap dimensions
width_ = wrap.width();
height_ = wrap.height();
if (current.aspectratio) {
while ((width_ > maxwidth_ || height_ > maxheight_) && width > minwidth && height > minheight) {
if (steps++ > 19) {
break;
}
height = math.max(minheight, math.min(maxheight, height - 10));
width = getscalar(height * ratio);
if (width < minwidth) {
width = minwidth;
height = getscalar(width / ratio);
}
if (width > maxwidth) {
width = maxwidth;
height = getscalar(width / ratio);
}
inner.width( width ).height( height );
wrap.width( width + wpadding );
width_ = wrap.width();
height_ = wrap.height();
}
} else {
width = math.max(minwidth, math.min(width, width - (width_ - maxwidth_)));
height = math.max(minheight, math.min(height, height - (height_ - maxheight_)));
}
}
if (scrollout && scrolling === 'auto' && height < origheight && (width + wpadding + scrollout) < maxwidth_) {
width += scrollout;
}
inner.width( width ).height( height );
wrap.width( width + wpadding );
width_ = wrap.width();
height_ = wrap.height();
canshrink = (width_ > maxwidth_ || height_ > maxheight_) && width > minwidth && height > minheight;
canexpand = current.aspectratio ? (width < origmaxwidth && height < origmaxheight && width < origwidth && height < origheight) : ((width < origmaxwidth || height < origmaxheight) && (width < origwidth || height < origheight));
$.extend(current, {
dim : {
width : getvalue( width_ ),
height : getvalue( height_ )
},
origwidth : origwidth,
origheight : origheight,
canshrink : canshrink,
canexpand : canexpand,
wpadding : wpadding,
hpadding : hpadding,
wrapspace : height_ - skin.outerheight(true),
skinspace : skin.height() - height
});
if (!iframe && current.autoheight && height > minheight && height < maxheight && !canexpand) {
inner.height('auto');
}
},
_getposition: function (onlyabsolute) {
var current = f.current,
viewport = f.getviewport(),
margin = current.margin,
width = f.wrap.width() + margin[1] + margin[3],
height = f.wrap.height() + margin[0] + margin[2],
rez = {
position: 'absolute',
top : margin[0],
left : margin[3]
};
if (current.autocenter && current.fixed && !onlyabsolute && height <= viewport.h && width <= viewport.w) {
rez.position = 'fixed';
} else if (!current.locked) {
rez.top += viewport.y;
rez.left += viewport.x;
}
rez.top = getvalue(math.max(rez.top, rez.top + ((viewport.h - height) * current.topratio)));
rez.left = getvalue(math.max(rez.left, rez.left + ((viewport.w - width) * current.leftratio)));
return rez;
},
_afterzoomin: function () {
var current = f.current;
if (!current) {
return;
}
f.isopen = f.isopened = true;
f.wrap.css('overflow', 'visible').addclass('fancybox-opened');
f.update();
// assign a click event
if ( current.closeclick || (current.nextclick && f.group.length > 1) ) {
f.inner.css('cursor', 'pointer').bind('click.fb', function(e) {
if (!$(e.target).is('a') && !$(e.target).parent().is('a')) {
e.preventdefault();
f[ current.closeclick ? 'close' : 'next' ]();
}
});
}
// create a close button
if (current.closebtn) {
$(current.tpl.closebtn).appendto(f.skin).bind('click.fb', function(e) {
e.preventdefault();
f.close();
});
}
// create navigation arrows
if (current.arrows && f.group.length > 1) {
if (current.loop || current.index > 0) {
$(current.tpl.prev).appendto(f.outer).bind('click.fb', f.prev);
}
if (current.loop || current.index < f.group.length - 1) {
$(current.tpl.next).appendto(f.outer).bind('click.fb', f.next);
}
}
f.trigger('aftershow');
// stop the slideshow if this is the last item
if (!current.loop && current.index === current.group.length - 1) {
f.play( false );
} else if (f.opts.autoplay && !f.player.isactive) {
f.opts.autoplay = false;
f.play();
}
},
_afterzoomout: function ( obj ) {
obj = obj || f.current;
$('.fancybox-wrap').trigger('onreset').remove();
$.extend(f, {
group : {},
opts : {},
router : false,
current : null,
isactive : false,
isopened : false,
isopen : false,
isclosing : false,
wrap : null,
skin : null,
outer : null,
inner : null
});
f.trigger('afterclose', obj);
}
});
/*
* default transitions
*/
f.transitions = {
getorigposition: function () {
var current = f.current,
element = current.element,
orig = current.orig,
pos = {},
width = 50,
height = 50,
hpadding = current.hpadding,
wpadding = current.wpadding,
viewport = f.getviewport();
if (!orig && current.isdom && element.is(':visible')) {
orig = element.find('img:first');
if (!orig.length) {
orig = element;
}
}
if (isquery(orig)) {
pos = orig.offset();
if (orig.is('img')) {
width = orig.outerwidth();
height = orig.outerheight();
}
} else {
pos.top = viewport.y + (viewport.h - height) * current.topratio;
pos.left = viewport.x + (viewport.w - width) * current.leftratio;
}
if (f.wrap.css('position') === 'fixed' || current.locked) {
pos.top -= viewport.y;
pos.left -= viewport.x;
}
pos = {
top : getvalue(pos.top - hpadding * current.topratio),
left : getvalue(pos.left - wpadding * current.leftratio),
width : getvalue(width + wpadding),
height : getvalue(height + hpadding)
};
return pos;
},
step: function (now, fx) {
var ratio,
padding,
value,
prop = fx.prop,
current = f.current,
wrapspace = current.wrapspace,
skinspace = current.skinspace;
if (prop === 'width' || prop === 'height') {
ratio = fx.end === fx.start ? 1 : (now - fx.start) / (fx.end - fx.start);
if (f.isclosing) {
ratio = 1 - ratio;
}
padding = prop === 'width' ? current.wpadding : current.hpadding;
value = now - padding;
f.skin[ prop ]( getscalar( prop === 'width' ? value : value - (wrapspace * ratio) ) );
f.inner[ prop ]( getscalar( prop === 'width' ? value : value - (wrapspace * ratio) - (skinspace * ratio) ) );
}
},
zoomin: function () {
var current = f.current,
startpos = current.pos,
effect = current.openeffect,
elastic = effect === 'elastic',
endpos = $.extend({opacity : 1}, startpos);
// remove "position" property that breaks older ie
delete endpos.position;
if (elastic) {
startpos = this.getorigposition();
if (current.openopacity) {
startpos.opacity = 0.1;
}
} else if (effect === 'fade') {
startpos.opacity = 0.1;
}
f.wrap.css(startpos).animate(endpos, {
duration : effect === 'none' ? 0 : current.openspeed,
easing : current.openeasing,
step : elastic ? this.step : null,
complete : f._afterzoomin
});
},
zoomout: function () {
var current = f.current,
effect = current.closeeffect,
elastic = effect === 'elastic',
endpos = {opacity : 0.1};
if (elastic) {
endpos = this.getorigposition();
if (current.closeopacity) {
endpos.opacity = 0.1;
}
}
f.wrap.animate(endpos, {
duration : effect === 'none' ? 0 : current.closespeed,
easing : current.closeeasing,
step : elastic ? this.step : null,
complete : f._afterzoomout
});
},
changein: function () {
var current = f.current,
effect = current.nexteffect,
startpos = current.pos,
endpos = { opacity : 1 },
direction = f.direction,
distance = 200,
field;
startpos.opacity = 0.1;
if (effect === 'elastic') {
field = direction === 'down' || direction === 'up' ? 'top' : 'left';
if (direction === 'down' || direction === 'right') {
startpos[ field ] = getvalue(getscalar(startpos[ field ]) - distance);
endpos[ field ] = '+=' + distance + 'px';
} else {
startpos[ field ] = getvalue(getscalar(startpos[ field ]) + distance);
endpos[ field ] = '-=' + distance + 'px';
}
}
// workaround for http://bugs.jquery.com/ticket/12273
if (effect === 'none') {
f._afterzoomin();
} else {
f.wrap.css(startpos).animate(endpos, {
duration : current.nextspeed,
easing : current.nexteasing,
complete : f._afterzoomin
});
}
},
changeout: function () {
var previous = f.previous,
effect = previous.preveffect,
endpos = { opacity : 0.1 },
direction = f.direction,
distance = 200;
if (effect === 'elastic') {
endpos[ direction === 'down' || direction === 'up' ? 'top' : 'left' ] = ( direction === 'up' || direction === 'left' ? '-' : '+' ) + '=' + distance + 'px';
}
previous.wrap.animate(endpos, {
duration : effect === 'none' ? 0 : previous.prevspeed,
easing : previous.preveasing,
complete : function () {
$(this).trigger('onreset').remove();
}
});
}
};
/*
* overlay helper
*/
f.helpers.overlay = {
defaults : {
closeclick : true, // if true, fancybox will be closed when user clicks on the overlay
speedout : 200, // duration of fadeout animation
showearly : true, // indicates if should be opened immediately or wait until the content is ready
css : {}, // custom css properties
locked : !istouch, // if true, the content will be locked into overlay
fixed : true // if false, the overlay css position property will not be set to "fixed"
},
overlay : null, // current handle
fixed : false, // indicates if the overlay has position "fixed"
el : $('html'), // element that contains "the lock"
// public methods
create : function(opts) {
opts = $.extend({}, this.defaults, opts);
if (this.overlay) {
this.close();
}
this.overlay = $('
').appendto( f.coming ? f.coming.parent : opts.parent );
this.fixed = false;
if (opts.fixed && f.defaults.fixed) {
this.overlay.addclass('fancybox-overlay-fixed');
this.fixed = true;
}
},
open : function(opts) {
var that = this;
opts = $.extend({}, this.defaults, opts);
if (this.overlay) {
this.overlay.unbind('.overlay').width('auto').height('auto');
} else {
this.create(opts);
}
if (!this.fixed) {
w.bind('resize.overlay', $.proxy( this.update, this) );
this.update();
}
if (opts.closeclick) {
this.overlay.bind('click.overlay', function(e) {
if ($(e.target).hasclass('fancybox-overlay')) {
if (f.isactive) {
f.close();
} else {
that.close();
}
return false;
}
});
}
this.overlay.css( opts.css ).show();
},
close : function() {
var scrollv, scrollh;
w.unbind('resize.overlay');
if (this.el.hasclass('fancybox-lock')) {
$('.fancybox-margin').removeclass('fancybox-margin');
scrollv = w.scrolltop();
scrollh = w.scrollleft();
this.el.removeclass('fancybox-lock');
w.scrolltop( scrollv ).scrollleft( scrollh );
}
$('.fancybox-overlay').remove().hide();
$.extend(this, {
overlay : null,
fixed : false
});
},
// private, callbacks
update : function () {
var width = '100%', offsetwidth;
// reset width/height so it will not mess
this.overlay.width(width).height('100%');
// jquery does not return reliable result for ie
if (ie) {
offsetwidth = math.max(document.documentelement.offsetwidth, document.body.offsetwidth);
if (d.width() > offsetwidth) {
width = d.width();
}
} else if (d.width() > w.width()) {
width = d.width();
}
this.overlay.width(width).height(d.height());
},
// this is where we can manipulate dom, because later it would cause iframes to reload
onready : function (opts, obj) {
var overlay = this.overlay;
$('.fancybox-overlay').stop(true, true);
if (!overlay) {
this.create(opts);
}
if (opts.locked && this.fixed && obj.fixed) {
if (!overlay) {
this.margin = d.height() > w.height() ? $('html').css('margin-right').replace("px", "") : false;
}
obj.locked = this.overlay.append( obj.wrap );
obj.fixed = false;
}
if (opts.showearly === true) {
this.beforeshow.apply(this, arguments);
}
},
beforeshow : function(opts, obj) {
var scrollv, scrollh;
if (obj.locked) {
if (this.margin !== false) {
$('*').filter(function(){
return ($(this).css('position') === 'fixed' && !$(this).hasclass("fancybox-overlay") && !$(this).hasclass("fancybox-wrap") );
}).addclass('fancybox-margin');
this.el.addclass('fancybox-margin');
}
scrollv = w.scrolltop();
scrollh = w.scrollleft();
this.el.addclass('fancybox-lock');
w.scrolltop( scrollv ).scrollleft( scrollh );
}
this.open(opts);
},
onupdate : function() {
if (!this.fixed) {
this.update();
}
},
afterclose: function (opts) {
// remove overlay if exists and fancybox is not opening
// (e.g., it is not being open using afterclose callback)
//if (this.overlay && !f.isactive) {
if (this.overlay && !f.coming) {
this.overlay.fadeout(opts.speedout, $.proxy( this.close, this ));
}
}
};
/*
* title helper
*/
f.helpers.title = {
defaults : {
type : 'float', // 'float', 'inside', 'outside' or 'over',
position : 'bottom' // 'top' or 'bottom'
},
beforeshow: function (opts) {
var current = f.current,
text = current.title,
type = opts.type,
title,
target;
if ($.isfunction(text)) {
text = text.call(current.element, current);
}
if (!isstring(text) || $.trim(text) === '') {
return;
}
title = $('
' + text + '
');
switch (type) {
case 'inside':
target = f.skin;
break;
case 'outside':
target = f.wrap;
break;
case 'over':
target = f.inner;
break;
default: // 'float'
target = f.skin;
title.appendto('body');
if (ie) {
title.width( title.width() );
}
title.wrapinner('
');
//increase bottom margin so this title will also fit into viewport
f.current.margin[2] += math.abs( getscalar(title.css('margin-bottom')) );
break;
}
title[ (opts.position === 'top' ? 'prependto' : 'appendto') ](target);
}
};
// jquery plugin initialization
$.fn.fancybox = function (options) {
var index,
that = $(this),
selector = this.selector || '',
run = function(e) {
var what = $(this).blur(), idx = index, reltype, relval;
if (!(e.ctrlkey || e.altkey || e.shiftkey || e.metakey) && !what.is('.fancybox-wrap')) {
reltype = options.groupattr || 'data-fancybox-group';
relval = what.attr(reltype);
if (!relval) {
reltype = 'rel';
relval = what.get(0)[ reltype ];
}
if (relval && relval !== '' && relval !== 'nofollow') {
what = selector.length ? $(selector) : that;
what = what.filter('[' + reltype + '="' + relval + '"]');
idx = what.index(this);
}
options.index = idx;
// stop an event from bubbling if everything is fine
if (f.open(what, options) !== false) {
e.preventdefault();
}
}
};
options = options || {};
index = options.index || 0;
if (!selector || options.live === false) {
that.unbind('click.fb-start').bind('click.fb-start', run);
} else {
d.undelegate(selector, 'click.fb-start').delegate(selector + ":not('.fancybox-item, .fancybox-nav')", 'click.fb-start', run);
}
this.filter('[data-fancybox-start=1]').trigger('click');
return this;
};
// tests that need a body at doc ready
d.ready(function() {
var w1, w2;
if ( $.scrollbarwidth === undefined ) {
// http://benalman.com/projects/jquery-misc-plugins/#scrollbarwidth
$.scrollbarwidth = function() {
var parent = $('
').appendto('body'),
child = parent.children(),
width = child.innerwidth() - child.height( 99 ).innerwidth();
parent.remove();
return width;
};
}
if ( $.support.fixedposition === undefined ) {
$.support.fixedposition = (function() {
var elem = $('
').appendto('body'),
fixed = ( elem[0].offsettop === 20 || elem[0].offsettop === 15 );
elem.remove();
return fixed;
}());
}
$.extend(f.defaults, {
scrollbarwidth : $.scrollbarwidth(),
fixed : $.support.fixedposition,
parent : $('body')
});
//get real width of page scroll-bar
w1 = $(window).width();
h.addclass('fancybox-lock-test');
w2 = $(window).width();
h.removeclass('fancybox-lock-test');
$("").appendto("head");
});
}(window, document, jquery));