bgneal@106: /*!
bgneal@106: * fancyBox - jQuery Plugin
bgneal@106: * version: 2.1.5 (Fri, 14 Jun 2013)
bgneal@106: * @requires jQuery v1.6 or later
bgneal@106: *
bgneal@106: * Examples at http://fancyapps.com/fancybox/
bgneal@106: * License: www.fancyapps.com/fancybox/#license
bgneal@106: *
bgneal@106: * Copyright 2012 Janis Skarnelis - janis@fancyapps.com
bgneal@106: *
bgneal@106: */
bgneal@106:
bgneal@106: (function (window, document, $, undefined) {
bgneal@106: "use strict";
bgneal@106:
bgneal@106: var H = $("html"),
bgneal@106: W = $(window),
bgneal@106: D = $(document),
bgneal@106: F = $.fancybox = function () {
bgneal@106: F.open.apply( this, arguments );
bgneal@106: },
bgneal@106: IE = navigator.userAgent.match(/msie/i),
bgneal@106: didUpdate = null,
bgneal@106: isTouch = document.createTouch !== undefined,
bgneal@106:
bgneal@106: isQuery = function(obj) {
bgneal@106: return obj && obj.hasOwnProperty && obj instanceof $;
bgneal@106: },
bgneal@106: isString = function(str) {
bgneal@106: return str && $.type(str) === "string";
bgneal@106: },
bgneal@106: isPercentage = function(str) {
bgneal@106: return isString(str) && str.indexOf('%') > 0;
bgneal@106: },
bgneal@106: isScrollable = function(el) {
bgneal@106: return (el && !(el.style.overflow && el.style.overflow === 'hidden') && ((el.clientWidth && el.scrollWidth > el.clientWidth) || (el.clientHeight && el.scrollHeight > el.clientHeight)));
bgneal@106: },
bgneal@106: getScalar = function(orig, dim) {
bgneal@106: var value = parseInt(orig, 10) || 0;
bgneal@106:
bgneal@106: if (dim && isPercentage(orig)) {
bgneal@106: value = F.getViewport()[ dim ] / 100 * value;
bgneal@106: }
bgneal@106:
bgneal@106: return Math.ceil(value);
bgneal@106: },
bgneal@106: getValue = function(value, dim) {
bgneal@106: return getScalar(value, dim) + 'px';
bgneal@106: };
bgneal@106:
bgneal@106: $.extend(F, {
bgneal@106: // The current version of fancyBox
bgneal@106: version: '2.1.5',
bgneal@106:
bgneal@106: defaults: {
bgneal@106: padding : 15,
bgneal@106: margin : 20,
bgneal@106:
bgneal@106: width : 800,
bgneal@106: height : 600,
bgneal@106: minWidth : 100,
bgneal@106: minHeight : 100,
bgneal@106: maxWidth : 9999,
bgneal@106: maxHeight : 9999,
bgneal@106: pixelRatio: 1, // Set to 2 for retina display support
bgneal@106:
bgneal@106: autoSize : true,
bgneal@106: autoHeight : false,
bgneal@106: autoWidth : false,
bgneal@106:
bgneal@106: autoResize : true,
bgneal@106: autoCenter : !isTouch,
bgneal@106: fitToView : true,
bgneal@106: aspectRatio : false,
bgneal@106: topRatio : 0.5,
bgneal@106: leftRatio : 0.5,
bgneal@106:
bgneal@106: scrolling : 'auto', // 'auto', 'yes' or 'no'
bgneal@106: wrapCSS : '',
bgneal@106:
bgneal@106: arrows : true,
bgneal@106: closeBtn : true,
bgneal@106: closeClick : false,
bgneal@106: nextClick : false,
bgneal@106: mouseWheel : true,
bgneal@106: autoPlay : false,
bgneal@106: playSpeed : 3000,
bgneal@106: preload : 3,
bgneal@106: modal : false,
bgneal@106: loop : true,
bgneal@106:
bgneal@106: ajax : {
bgneal@106: dataType : 'html',
bgneal@106: headers : { 'X-fancyBox': true }
bgneal@106: },
bgneal@106: iframe : {
bgneal@106: scrolling : 'auto',
bgneal@106: preload : true
bgneal@106: },
bgneal@106: swf : {
bgneal@106: wmode: 'transparent',
bgneal@106: allowfullscreen : 'true',
bgneal@106: allowscriptaccess : 'always'
bgneal@106: },
bgneal@106:
bgneal@106: keys : {
bgneal@106: next : {
bgneal@106: 13 : 'left', // enter
bgneal@106: 34 : 'up', // page down
bgneal@106: 39 : 'left', // right arrow
bgneal@106: 40 : 'up' // down arrow
bgneal@106: },
bgneal@106: prev : {
bgneal@106: 8 : 'right', // backspace
bgneal@106: 33 : 'down', // page up
bgneal@106: 37 : 'right', // left arrow
bgneal@106: 38 : 'down' // up arrow
bgneal@106: },
bgneal@106: close : [27], // escape key
bgneal@106: play : [32], // space - start/stop slideshow
bgneal@106: toggle : [70] // letter "f" - toggle fullscreen
bgneal@106: },
bgneal@106:
bgneal@106: direction : {
bgneal@106: next : 'left',
bgneal@106: prev : 'right'
bgneal@106: },
bgneal@106:
bgneal@106: scrollOutside : true,
bgneal@106:
bgneal@106: // Override some properties
bgneal@106: index : 0,
bgneal@106: type : null,
bgneal@106: href : null,
bgneal@106: content : null,
bgneal@106: title : null,
bgneal@106:
bgneal@106: // HTML templates
bgneal@106: tpl: {
bgneal@106: wrap : '
The requested content cannot be loaded.
Please try again later.
',
bgneal@106: closeBtn : '').html(content).find(current.selector);
bgneal@106:
bgneal@106: } else if (isQuery(content)) {
bgneal@106: if (!content.data(placeholder)) {
bgneal@106: content.data(placeholder, $('
').insertAfter( content ).hide() );
bgneal@106: }
bgneal@106:
bgneal@106: content = content.show().detach();
bgneal@106:
bgneal@106: current.wrap.bind('onReset', function () {
bgneal@106: if ($(this).find(content).length) {
bgneal@106: content.hide().replaceAll( content.data(placeholder) ).data(placeholder, false);
bgneal@106: }
bgneal@106: });
bgneal@106: }
bgneal@106: break;
bgneal@106:
bgneal@106: case 'image':
bgneal@106: content = current.tpl.image.replace('{href}', href);
bgneal@106: break;
bgneal@106:
bgneal@106: case 'swf':
bgneal@106: content = '
';
bgneal@106: break;
bgneal@106: }
bgneal@106:
bgneal@106: if (!(isQuery(content) && content.parent().is(current.inner))) {
bgneal@106: current.inner.append( content );
bgneal@106: }
bgneal@106:
bgneal@106: // Give a chance for helpers or callbacks to update elements
bgneal@106: F.trigger('beforeShow');
bgneal@106:
bgneal@106: // Set scrolling before calculating dimensions
bgneal@106: current.inner.css('overflow', scrolling === 'yes' ? 'scroll' : (scrolling === 'no' ? 'hidden' : scrolling));
bgneal@106:
bgneal@106: // Set initial dimensions and start position
bgneal@106: F._setDimension();
bgneal@106:
bgneal@106: F.reposition();
bgneal@106:
bgneal@106: F.isOpen = false;
bgneal@106: F.coming = null;
bgneal@106:
bgneal@106: F.bindEvents();
bgneal@106:
bgneal@106: if (!F.isOpened) {
bgneal@106: $('.fancybox-wrap').not( current.wrap ).stop(true).trigger('onReset').remove();
bgneal@106:
bgneal@106: } else if (previous.prevMethod) {
bgneal@106: F.transitions[ previous.prevMethod ]();
bgneal@106: }
bgneal@106:
bgneal@106: F.transitions[ F.isOpened ? current.nextMethod : current.openMethod ]();
bgneal@106:
bgneal@106: F._preloadImages();
bgneal@106: },
bgneal@106:
bgneal@106: _setDimension: function () {
bgneal@106: var viewport = F.getViewport(),
bgneal@106: steps = 0,
bgneal@106: canShrink = false,
bgneal@106: canExpand = false,
bgneal@106: wrap = F.wrap,
bgneal@106: skin = F.skin,
bgneal@106: inner = F.inner,
bgneal@106: current = F.current,
bgneal@106: width = current.width,
bgneal@106: height = current.height,
bgneal@106: minWidth = current.minWidth,
bgneal@106: minHeight = current.minHeight,
bgneal@106: maxWidth = current.maxWidth,
bgneal@106: maxHeight = current.maxHeight,
bgneal@106: scrolling = current.scrolling,
bgneal@106: scrollOut = current.scrollOutside ? current.scrollbarWidth : 0,
bgneal@106: margin = current.margin,
bgneal@106: wMargin = getScalar(margin[1] + margin[3]),
bgneal@106: hMargin = getScalar(margin[0] + margin[2]),
bgneal@106: wPadding,
bgneal@106: hPadding,
bgneal@106: wSpace,
bgneal@106: hSpace,
bgneal@106: origWidth,
bgneal@106: origHeight,
bgneal@106: origMaxWidth,
bgneal@106: origMaxHeight,
bgneal@106: ratio,
bgneal@106: width_,
bgneal@106: height_,
bgneal@106: maxWidth_,
bgneal@106: maxHeight_,
bgneal@106: iframe,
bgneal@106: body;
bgneal@106:
bgneal@106: // Reset dimensions so we could re-check actual size
bgneal@106: wrap.add(skin).add(inner).width('auto').height('auto').removeClass('fancybox-tmp');
bgneal@106:
bgneal@106: wPadding = getScalar(skin.outerWidth(true) - skin.width());
bgneal@106: hPadding = getScalar(skin.outerHeight(true) - skin.height());
bgneal@106:
bgneal@106: // Any space between content and viewport (margin, padding, border, title)
bgneal@106: wSpace = wMargin + wPadding;
bgneal@106: hSpace = hMargin + hPadding;
bgneal@106:
bgneal@106: origWidth = isPercentage(width) ? (viewport.w - wSpace) * getScalar(width) / 100 : width;
bgneal@106: origHeight = isPercentage(height) ? (viewport.h - hSpace) * getScalar(height) / 100 : height;
bgneal@106:
bgneal@106: if (current.type === 'iframe') {
bgneal@106: iframe = current.content;
bgneal@106:
bgneal@106: if (current.autoHeight && iframe.data('ready') === 1) {
bgneal@106: try {
bgneal@106: if (iframe[0].contentWindow.document.location) {
bgneal@106: inner.width( origWidth ).height(9999);
bgneal@106:
bgneal@106: body = iframe.contents().find('body');
bgneal@106:
bgneal@106: if (scrollOut) {
bgneal@106: body.css('overflow-x', 'hidden');
bgneal@106: }
bgneal@106:
bgneal@106: origHeight = body.outerHeight(true);
bgneal@106: }
bgneal@106:
bgneal@106: } catch (e) {}
bgneal@106: }
bgneal@106:
bgneal@106: } else if (current.autoWidth || current.autoHeight) {
bgneal@106: inner.addClass( 'fancybox-tmp' );
bgneal@106:
bgneal@106: // Set width or height in case we need to calculate only one dimension
bgneal@106: if (!current.autoWidth) {
bgneal@106: inner.width( origWidth );
bgneal@106: }
bgneal@106:
bgneal@106: if (!current.autoHeight) {
bgneal@106: inner.height( origHeight );
bgneal@106: }
bgneal@106:
bgneal@106: if (current.autoWidth) {
bgneal@106: origWidth = inner.width();
bgneal@106: }
bgneal@106:
bgneal@106: if (current.autoHeight) {
bgneal@106: origHeight = inner.height();
bgneal@106: }
bgneal@106:
bgneal@106: inner.removeClass( 'fancybox-tmp' );
bgneal@106: }
bgneal@106:
bgneal@106: width = getScalar( origWidth );
bgneal@106: height = getScalar( origHeight );
bgneal@106:
bgneal@106: ratio = origWidth / origHeight;
bgneal@106:
bgneal@106: // Calculations for the content
bgneal@106: minWidth = getScalar(isPercentage(minWidth) ? getScalar(minWidth, 'w') - wSpace : minWidth);
bgneal@106: maxWidth = getScalar(isPercentage(maxWidth) ? getScalar(maxWidth, 'w') - wSpace : maxWidth);
bgneal@106:
bgneal@106: minHeight = getScalar(isPercentage(minHeight) ? getScalar(minHeight, 'h') - hSpace : minHeight);
bgneal@106: maxHeight = getScalar(isPercentage(maxHeight) ? getScalar(maxHeight, 'h') - hSpace : maxHeight);
bgneal@106:
bgneal@106: // These will be used to determine if wrap can fit in the viewport
bgneal@106: origMaxWidth = maxWidth;
bgneal@106: origMaxHeight = maxHeight;
bgneal@106:
bgneal@106: if (current.fitToView) {
bgneal@106: maxWidth = Math.min(viewport.w - wSpace, maxWidth);
bgneal@106: maxHeight = Math.min(viewport.h - hSpace, maxHeight);
bgneal@106: }
bgneal@106:
bgneal@106: maxWidth_ = viewport.w - wMargin;
bgneal@106: maxHeight_ = viewport.h - hMargin;
bgneal@106:
bgneal@106: if (current.aspectRatio) {
bgneal@106: if (width > maxWidth) {
bgneal@106: width = maxWidth;
bgneal@106: height = getScalar(width / ratio);
bgneal@106: }
bgneal@106:
bgneal@106: if (height > maxHeight) {
bgneal@106: height = maxHeight;
bgneal@106: width = getScalar(height * ratio);
bgneal@106: }
bgneal@106:
bgneal@106: if (width < minWidth) {
bgneal@106: width = minWidth;
bgneal@106: height = getScalar(width / ratio);
bgneal@106: }
bgneal@106:
bgneal@106: if (height < minHeight) {
bgneal@106: height = minHeight;
bgneal@106: width = getScalar(height * ratio);
bgneal@106: }
bgneal@106:
bgneal@106: } else {
bgneal@106: width = Math.max(minWidth, Math.min(width, maxWidth));
bgneal@106:
bgneal@106: if (current.autoHeight && current.type !== 'iframe') {
bgneal@106: inner.width( width );
bgneal@106:
bgneal@106: height = inner.height();
bgneal@106: }
bgneal@106:
bgneal@106: height = Math.max(minHeight, Math.min(height, maxHeight));
bgneal@106: }
bgneal@106:
bgneal@106: // Try to fit inside viewport (including the title)
bgneal@106: if (current.fitToView) {
bgneal@106: inner.width( width ).height( height );
bgneal@106:
bgneal@106: wrap.width( width + wPadding );
bgneal@106:
bgneal@106: // Real wrap dimensions
bgneal@106: width_ = wrap.width();
bgneal@106: height_ = wrap.height();
bgneal@106:
bgneal@106: if (current.aspectRatio) {
bgneal@106: while ((width_ > maxWidth_ || height_ > maxHeight_) && width > minWidth && height > minHeight) {
bgneal@106: if (steps++ > 19) {
bgneal@106: break;
bgneal@106: }
bgneal@106:
bgneal@106: height = Math.max(minHeight, Math.min(maxHeight, height - 10));
bgneal@106: width = getScalar(height * ratio);
bgneal@106:
bgneal@106: if (width < minWidth) {
bgneal@106: width = minWidth;
bgneal@106: height = getScalar(width / ratio);
bgneal@106: }
bgneal@106:
bgneal@106: if (width > maxWidth) {
bgneal@106: width = maxWidth;
bgneal@106: height = getScalar(width / ratio);
bgneal@106: }
bgneal@106:
bgneal@106: inner.width( width ).height( height );
bgneal@106:
bgneal@106: wrap.width( width + wPadding );
bgneal@106:
bgneal@106: width_ = wrap.width();
bgneal@106: height_ = wrap.height();
bgneal@106: }
bgneal@106:
bgneal@106: } else {
bgneal@106: width = Math.max(minWidth, Math.min(width, width - (width_ - maxWidth_)));
bgneal@106: height = Math.max(minHeight, Math.min(height, height - (height_ - maxHeight_)));
bgneal@106: }
bgneal@106: }
bgneal@106:
bgneal@106: if (scrollOut && scrolling === 'auto' && height < origHeight && (width + wPadding + scrollOut) < maxWidth_) {
bgneal@106: width += scrollOut;
bgneal@106: }
bgneal@106:
bgneal@106: inner.width( width ).height( height );
bgneal@106:
bgneal@106: wrap.width( width + wPadding );
bgneal@106:
bgneal@106: width_ = wrap.width();
bgneal@106: height_ = wrap.height();
bgneal@106:
bgneal@106: canShrink = (width_ > maxWidth_ || height_ > maxHeight_) && width > minWidth && height > minHeight;
bgneal@106: canExpand = current.aspectRatio ? (width < origMaxWidth && height < origMaxHeight && width < origWidth && height < origHeight) : ((width < origMaxWidth || height < origMaxHeight) && (width < origWidth || height < origHeight));
bgneal@106:
bgneal@106: $.extend(current, {
bgneal@106: dim : {
bgneal@106: width : getValue( width_ ),
bgneal@106: height : getValue( height_ )
bgneal@106: },
bgneal@106: origWidth : origWidth,
bgneal@106: origHeight : origHeight,
bgneal@106: canShrink : canShrink,
bgneal@106: canExpand : canExpand,
bgneal@106: wPadding : wPadding,
bgneal@106: hPadding : hPadding,
bgneal@106: wrapSpace : height_ - skin.outerHeight(true),
bgneal@106: skinSpace : skin.height() - height
bgneal@106: });
bgneal@106:
bgneal@106: if (!iframe && current.autoHeight && height > minHeight && height < maxHeight && !canExpand) {
bgneal@106: inner.height('auto');
bgneal@106: }
bgneal@106: },
bgneal@106:
bgneal@106: _getPosition: function (onlyAbsolute) {
bgneal@106: var current = F.current,
bgneal@106: viewport = F.getViewport(),
bgneal@106: margin = current.margin,
bgneal@106: width = F.wrap.width() + margin[1] + margin[3],
bgneal@106: height = F.wrap.height() + margin[0] + margin[2],
bgneal@106: rez = {
bgneal@106: position: 'absolute',
bgneal@106: top : margin[0],
bgneal@106: left : margin[3]
bgneal@106: };
bgneal@106:
bgneal@106: if (current.autoCenter && current.fixed && !onlyAbsolute && height <= viewport.h && width <= viewport.w) {
bgneal@106: rez.position = 'fixed';
bgneal@106:
bgneal@106: } else if (!current.locked) {
bgneal@106: rez.top += viewport.y;
bgneal@106: rez.left += viewport.x;
bgneal@106: }
bgneal@106:
bgneal@106: rez.top = getValue(Math.max(rez.top, rez.top + ((viewport.h - height) * current.topRatio)));
bgneal@106: rez.left = getValue(Math.max(rez.left, rez.left + ((viewport.w - width) * current.leftRatio)));
bgneal@106:
bgneal@106: return rez;
bgneal@106: },
bgneal@106:
bgneal@106: _afterZoomIn: function () {
bgneal@106: var current = F.current;
bgneal@106:
bgneal@106: if (!current) {
bgneal@106: return;
bgneal@106: }
bgneal@106:
bgneal@106: F.isOpen = F.isOpened = true;
bgneal@106:
bgneal@106: F.wrap.css('overflow', 'visible').addClass('fancybox-opened');
bgneal@106:
bgneal@106: F.update();
bgneal@106:
bgneal@106: // Assign a click event
bgneal@106: if ( current.closeClick || (current.nextClick && F.group.length > 1) ) {
bgneal@106: F.inner.css('cursor', 'pointer').bind('click.fb', function(e) {
bgneal@106: if (!$(e.target).is('a') && !$(e.target).parent().is('a')) {
bgneal@106: e.preventDefault();
bgneal@106:
bgneal@106: F[ current.closeClick ? 'close' : 'next' ]();
bgneal@106: }
bgneal@106: });
bgneal@106: }
bgneal@106:
bgneal@106: // Create a close button
bgneal@106: if (current.closeBtn) {
bgneal@106: $(current.tpl.closeBtn).appendTo(F.skin).bind('click.fb', function(e) {
bgneal@106: e.preventDefault();
bgneal@106:
bgneal@106: F.close();
bgneal@106: });
bgneal@106: }
bgneal@106:
bgneal@106: // Create navigation arrows
bgneal@106: if (current.arrows && F.group.length > 1) {
bgneal@106: if (current.loop || current.index > 0) {
bgneal@106: $(current.tpl.prev).appendTo(F.outer).bind('click.fb', F.prev);
bgneal@106: }
bgneal@106:
bgneal@106: if (current.loop || current.index < F.group.length - 1) {
bgneal@106: $(current.tpl.next).appendTo(F.outer).bind('click.fb', F.next);
bgneal@106: }
bgneal@106: }
bgneal@106:
bgneal@106: F.trigger('afterShow');
bgneal@106:
bgneal@106: // Stop the slideshow if this is the last item
bgneal@106: if (!current.loop && current.index === current.group.length - 1) {
bgneal@106: F.play( false );
bgneal@106:
bgneal@106: } else if (F.opts.autoPlay && !F.player.isActive) {
bgneal@106: F.opts.autoPlay = false;
bgneal@106:
bgneal@106: F.play();
bgneal@106: }
bgneal@106: },
bgneal@106:
bgneal@106: _afterZoomOut: function ( obj ) {
bgneal@106: obj = obj || F.current;
bgneal@106:
bgneal@106: $('.fancybox-wrap').trigger('onReset').remove();
bgneal@106:
bgneal@106: $.extend(F, {
bgneal@106: group : {},
bgneal@106: opts : {},
bgneal@106: router : false,
bgneal@106: current : null,
bgneal@106: isActive : false,
bgneal@106: isOpened : false,
bgneal@106: isOpen : false,
bgneal@106: isClosing : false,
bgneal@106: wrap : null,
bgneal@106: skin : null,
bgneal@106: outer : null,
bgneal@106: inner : null
bgneal@106: });
bgneal@106:
bgneal@106: F.trigger('afterClose', obj);
bgneal@106: }
bgneal@106: });
bgneal@106:
bgneal@106: /*
bgneal@106: * Default transitions
bgneal@106: */
bgneal@106:
bgneal@106: F.transitions = {
bgneal@106: getOrigPosition: function () {
bgneal@106: var current = F.current,
bgneal@106: element = current.element,
bgneal@106: orig = current.orig,
bgneal@106: pos = {},
bgneal@106: width = 50,
bgneal@106: height = 50,
bgneal@106: hPadding = current.hPadding,
bgneal@106: wPadding = current.wPadding,
bgneal@106: viewport = F.getViewport();
bgneal@106:
bgneal@106: if (!orig && current.isDom && element.is(':visible')) {
bgneal@106: orig = element.find('img:first');
bgneal@106:
bgneal@106: if (!orig.length) {
bgneal@106: orig = element;
bgneal@106: }
bgneal@106: }
bgneal@106:
bgneal@106: if (isQuery(orig)) {
bgneal@106: pos = orig.offset();
bgneal@106:
bgneal@106: if (orig.is('img')) {
bgneal@106: width = orig.outerWidth();
bgneal@106: height = orig.outerHeight();
bgneal@106: }
bgneal@106:
bgneal@106: } else {
bgneal@106: pos.top = viewport.y + (viewport.h - height) * current.topRatio;
bgneal@106: pos.left = viewport.x + (viewport.w - width) * current.leftRatio;
bgneal@106: }
bgneal@106:
bgneal@106: if (F.wrap.css('position') === 'fixed' || current.locked) {
bgneal@106: pos.top -= viewport.y;
bgneal@106: pos.left -= viewport.x;
bgneal@106: }
bgneal@106:
bgneal@106: pos = {
bgneal@106: top : getValue(pos.top - hPadding * current.topRatio),
bgneal@106: left : getValue(pos.left - wPadding * current.leftRatio),
bgneal@106: width : getValue(width + wPadding),
bgneal@106: height : getValue(height + hPadding)
bgneal@106: };
bgneal@106:
bgneal@106: return pos;
bgneal@106: },
bgneal@106:
bgneal@106: step: function (now, fx) {
bgneal@106: var ratio,
bgneal@106: padding,
bgneal@106: value,
bgneal@106: prop = fx.prop,
bgneal@106: current = F.current,
bgneal@106: wrapSpace = current.wrapSpace,
bgneal@106: skinSpace = current.skinSpace;
bgneal@106:
bgneal@106: if (prop === 'width' || prop === 'height') {
bgneal@106: ratio = fx.end === fx.start ? 1 : (now - fx.start) / (fx.end - fx.start);
bgneal@106:
bgneal@106: if (F.isClosing) {
bgneal@106: ratio = 1 - ratio;
bgneal@106: }
bgneal@106:
bgneal@106: padding = prop === 'width' ? current.wPadding : current.hPadding;
bgneal@106: value = now - padding;
bgneal@106:
bgneal@106: F.skin[ prop ]( getScalar( prop === 'width' ? value : value - (wrapSpace * ratio) ) );
bgneal@106: F.inner[ prop ]( getScalar( prop === 'width' ? value : value - (wrapSpace * ratio) - (skinSpace * ratio) ) );
bgneal@106: }
bgneal@106: },
bgneal@106:
bgneal@106: zoomIn: function () {
bgneal@106: var current = F.current,
bgneal@106: startPos = current.pos,
bgneal@106: effect = current.openEffect,
bgneal@106: elastic = effect === 'elastic',
bgneal@106: endPos = $.extend({opacity : 1}, startPos);
bgneal@106:
bgneal@106: // Remove "position" property that breaks older IE
bgneal@106: delete endPos.position;
bgneal@106:
bgneal@106: if (elastic) {
bgneal@106: startPos = this.getOrigPosition();
bgneal@106:
bgneal@106: if (current.openOpacity) {
bgneal@106: startPos.opacity = 0.1;
bgneal@106: }
bgneal@106:
bgneal@106: } else if (effect === 'fade') {
bgneal@106: startPos.opacity = 0.1;
bgneal@106: }
bgneal@106:
bgneal@106: F.wrap.css(startPos).animate(endPos, {
bgneal@106: duration : effect === 'none' ? 0 : current.openSpeed,
bgneal@106: easing : current.openEasing,
bgneal@106: step : elastic ? this.step : null,
bgneal@106: complete : F._afterZoomIn
bgneal@106: });
bgneal@106: },
bgneal@106:
bgneal@106: zoomOut: function () {
bgneal@106: var current = F.current,
bgneal@106: effect = current.closeEffect,
bgneal@106: elastic = effect === 'elastic',
bgneal@106: endPos = {opacity : 0.1};
bgneal@106:
bgneal@106: if (elastic) {
bgneal@106: endPos = this.getOrigPosition();
bgneal@106:
bgneal@106: if (current.closeOpacity) {
bgneal@106: endPos.opacity = 0.1;
bgneal@106: }
bgneal@106: }
bgneal@106:
bgneal@106: F.wrap.animate(endPos, {
bgneal@106: duration : effect === 'none' ? 0 : current.closeSpeed,
bgneal@106: easing : current.closeEasing,
bgneal@106: step : elastic ? this.step : null,
bgneal@106: complete : F._afterZoomOut
bgneal@106: });
bgneal@106: },
bgneal@106:
bgneal@106: changeIn: function () {
bgneal@106: var current = F.current,
bgneal@106: effect = current.nextEffect,
bgneal@106: startPos = current.pos,
bgneal@106: endPos = { opacity : 1 },
bgneal@106: direction = F.direction,
bgneal@106: distance = 200,
bgneal@106: field;
bgneal@106:
bgneal@106: startPos.opacity = 0.1;
bgneal@106:
bgneal@106: if (effect === 'elastic') {
bgneal@106: field = direction === 'down' || direction === 'up' ? 'top' : 'left';
bgneal@106:
bgneal@106: if (direction === 'down' || direction === 'right') {
bgneal@106: startPos[ field ] = getValue(getScalar(startPos[ field ]) - distance);
bgneal@106: endPos[ field ] = '+=' + distance + 'px';
bgneal@106:
bgneal@106: } else {
bgneal@106: startPos[ field ] = getValue(getScalar(startPos[ field ]) + distance);
bgneal@106: endPos[ field ] = '-=' + distance + 'px';
bgneal@106: }
bgneal@106: }
bgneal@106:
bgneal@106: // Workaround for http://bugs.jquery.com/ticket/12273
bgneal@106: if (effect === 'none') {
bgneal@106: F._afterZoomIn();
bgneal@106:
bgneal@106: } else {
bgneal@106: F.wrap.css(startPos).animate(endPos, {
bgneal@106: duration : current.nextSpeed,
bgneal@106: easing : current.nextEasing,
bgneal@106: complete : F._afterZoomIn
bgneal@106: });
bgneal@106: }
bgneal@106: },
bgneal@106:
bgneal@106: changeOut: function () {
bgneal@106: var previous = F.previous,
bgneal@106: effect = previous.prevEffect,
bgneal@106: endPos = { opacity : 0.1 },
bgneal@106: direction = F.direction,
bgneal@106: distance = 200;
bgneal@106:
bgneal@106: if (effect === 'elastic') {
bgneal@106: endPos[ direction === 'down' || direction === 'up' ? 'top' : 'left' ] = ( direction === 'up' || direction === 'left' ? '-' : '+' ) + '=' + distance + 'px';
bgneal@106: }
bgneal@106:
bgneal@106: previous.wrap.animate(endPos, {
bgneal@106: duration : effect === 'none' ? 0 : previous.prevSpeed,
bgneal@106: easing : previous.prevEasing,
bgneal@106: complete : function () {
bgneal@106: $(this).trigger('onReset').remove();
bgneal@106: }
bgneal@106: });
bgneal@106: }
bgneal@106: };
bgneal@106:
bgneal@106: /*
bgneal@106: * Overlay helper
bgneal@106: */
bgneal@106:
bgneal@106: F.helpers.overlay = {
bgneal@106: defaults : {
bgneal@106: closeClick : true, // if true, fancyBox will be closed when user clicks on the overlay
bgneal@106: speedOut : 200, // duration of fadeOut animation
bgneal@106: showEarly : true, // indicates if should be opened immediately or wait until the content is ready
bgneal@106: css : {}, // custom CSS properties
bgneal@106: locked : !isTouch, // if true, the content will be locked into overlay
bgneal@106: fixed : true // if false, the overlay CSS position property will not be set to "fixed"
bgneal@106: },
bgneal@106:
bgneal@106: overlay : null, // current handle
bgneal@106: fixed : false, // indicates if the overlay has position "fixed"
bgneal@106: el : $('html'), // element that contains "the lock"
bgneal@106:
bgneal@106: // Public methods
bgneal@106: create : function(opts) {
bgneal@106: opts = $.extend({}, this.defaults, opts);
bgneal@106:
bgneal@106: if (this.overlay) {
bgneal@106: this.close();
bgneal@106: }
bgneal@106:
bgneal@106: this.overlay = $('
').appendTo( F.coming ? F.coming.parent : opts.parent );
bgneal@106: this.fixed = false;
bgneal@106:
bgneal@106: if (opts.fixed && F.defaults.fixed) {
bgneal@106: this.overlay.addClass('fancybox-overlay-fixed');
bgneal@106:
bgneal@106: this.fixed = true;
bgneal@106: }
bgneal@106: },
bgneal@106:
bgneal@106: open : function(opts) {
bgneal@106: var that = this;
bgneal@106:
bgneal@106: opts = $.extend({}, this.defaults, opts);
bgneal@106:
bgneal@106: if (this.overlay) {
bgneal@106: this.overlay.unbind('.overlay').width('auto').height('auto');
bgneal@106:
bgneal@106: } else {
bgneal@106: this.create(opts);
bgneal@106: }
bgneal@106:
bgneal@106: if (!this.fixed) {
bgneal@106: W.bind('resize.overlay', $.proxy( this.update, this) );
bgneal@106:
bgneal@106: this.update();
bgneal@106: }
bgneal@106:
bgneal@106: if (opts.closeClick) {
bgneal@106: this.overlay.bind('click.overlay', function(e) {
bgneal@106: if ($(e.target).hasClass('fancybox-overlay')) {
bgneal@106: if (F.isActive) {
bgneal@106: F.close();
bgneal@106: } else {
bgneal@106: that.close();
bgneal@106: }
bgneal@106:
bgneal@106: return false;
bgneal@106: }
bgneal@106: });
bgneal@106: }
bgneal@106:
bgneal@106: this.overlay.css( opts.css ).show();
bgneal@106: },
bgneal@106:
bgneal@106: close : function() {
bgneal@106: var scrollV, scrollH;
bgneal@106:
bgneal@106: W.unbind('resize.overlay');
bgneal@106:
bgneal@106: if (this.el.hasClass('fancybox-lock')) {
bgneal@106: $('.fancybox-margin').removeClass('fancybox-margin');
bgneal@106:
bgneal@106: scrollV = W.scrollTop();
bgneal@106: scrollH = W.scrollLeft();
bgneal@106:
bgneal@106: this.el.removeClass('fancybox-lock');
bgneal@106:
bgneal@106: W.scrollTop( scrollV ).scrollLeft( scrollH );
bgneal@106: }
bgneal@106:
bgneal@106: $('.fancybox-overlay').remove().hide();
bgneal@106:
bgneal@106: $.extend(this, {
bgneal@106: overlay : null,
bgneal@106: fixed : false
bgneal@106: });
bgneal@106: },
bgneal@106:
bgneal@106: // Private, callbacks
bgneal@106:
bgneal@106: update : function () {
bgneal@106: var width = '100%', offsetWidth;
bgneal@106:
bgneal@106: // Reset width/height so it will not mess
bgneal@106: this.overlay.width(width).height('100%');
bgneal@106:
bgneal@106: // jQuery does not return reliable result for IE
bgneal@106: if (IE) {
bgneal@106: offsetWidth = Math.max(document.documentElement.offsetWidth, document.body.offsetWidth);
bgneal@106:
bgneal@106: if (D.width() > offsetWidth) {
bgneal@106: width = D.width();
bgneal@106: }
bgneal@106:
bgneal@106: } else if (D.width() > W.width()) {
bgneal@106: width = D.width();
bgneal@106: }
bgneal@106:
bgneal@106: this.overlay.width(width).height(D.height());
bgneal@106: },
bgneal@106:
bgneal@106: // This is where we can manipulate DOM, because later it would cause iframes to reload
bgneal@106: onReady : function (opts, obj) {
bgneal@106: var overlay = this.overlay;
bgneal@106:
bgneal@106: $('.fancybox-overlay').stop(true, true);
bgneal@106:
bgneal@106: if (!overlay) {
bgneal@106: this.create(opts);
bgneal@106: }
bgneal@106:
bgneal@106: if (opts.locked && this.fixed && obj.fixed) {
bgneal@106: if (!overlay) {
bgneal@106: this.margin = D.height() > W.height() ? $('html').css('margin-right').replace("px", "") : false;
bgneal@106: }
bgneal@106:
bgneal@106: obj.locked = this.overlay.append( obj.wrap );
bgneal@106: obj.fixed = false;
bgneal@106: }
bgneal@106:
bgneal@106: if (opts.showEarly === true) {
bgneal@106: this.beforeShow.apply(this, arguments);
bgneal@106: }
bgneal@106: },
bgneal@106:
bgneal@106: beforeShow : function(opts, obj) {
bgneal@106: var scrollV, scrollH;
bgneal@106:
bgneal@106: if (obj.locked) {
bgneal@106: if (this.margin !== false) {
bgneal@106: $('*').filter(function(){
bgneal@106: return ($(this).css('position') === 'fixed' && !$(this).hasClass("fancybox-overlay") && !$(this).hasClass("fancybox-wrap") );
bgneal@106: }).addClass('fancybox-margin');
bgneal@106:
bgneal@106: this.el.addClass('fancybox-margin');
bgneal@106: }
bgneal@106:
bgneal@106: scrollV = W.scrollTop();
bgneal@106: scrollH = W.scrollLeft();
bgneal@106:
bgneal@106: this.el.addClass('fancybox-lock');
bgneal@106:
bgneal@106: W.scrollTop( scrollV ).scrollLeft( scrollH );
bgneal@106: }
bgneal@106:
bgneal@106: this.open(opts);
bgneal@106: },
bgneal@106:
bgneal@106: onUpdate : function() {
bgneal@106: if (!this.fixed) {
bgneal@106: this.update();
bgneal@106: }
bgneal@106: },
bgneal@106:
bgneal@106: afterClose: function (opts) {
bgneal@106: // Remove overlay if exists and fancyBox is not opening
bgneal@106: // (e.g., it is not being open using afterClose callback)
bgneal@106: //if (this.overlay && !F.isActive) {
bgneal@106: if (this.overlay && !F.coming) {
bgneal@106: this.overlay.fadeOut(opts.speedOut, $.proxy( this.close, this ));
bgneal@106: }
bgneal@106: }
bgneal@106: };
bgneal@106:
bgneal@106: /*
bgneal@106: * Title helper
bgneal@106: */
bgneal@106:
bgneal@106: F.helpers.title = {
bgneal@106: defaults : {
bgneal@106: type : 'float', // 'float', 'inside', 'outside' or 'over',
bgneal@106: position : 'bottom' // 'top' or 'bottom'
bgneal@106: },
bgneal@106:
bgneal@106: beforeShow: function (opts) {
bgneal@106: var current = F.current,
bgneal@106: text = current.title,
bgneal@106: type = opts.type,
bgneal@106: title,
bgneal@106: target;
bgneal@106:
bgneal@106: if ($.isFunction(text)) {
bgneal@106: text = text.call(current.element, current);
bgneal@106: }
bgneal@106:
bgneal@106: if (!isString(text) || $.trim(text) === '') {
bgneal@106: return;
bgneal@106: }
bgneal@106:
bgneal@106: title = $('
' + text + '
');
bgneal@106:
bgneal@106: switch (type) {
bgneal@106: case 'inside':
bgneal@106: target = F.skin;
bgneal@106: break;
bgneal@106:
bgneal@106: case 'outside':
bgneal@106: target = F.wrap;
bgneal@106: break;
bgneal@106:
bgneal@106: case 'over':
bgneal@106: target = F.inner;
bgneal@106: break;
bgneal@106:
bgneal@106: default: // 'float'
bgneal@106: target = F.skin;
bgneal@106:
bgneal@106: title.appendTo('body');
bgneal@106:
bgneal@106: if (IE) {
bgneal@106: title.width( title.width() );
bgneal@106: }
bgneal@106:
bgneal@106: title.wrapInner('
');
bgneal@106:
bgneal@106: //Increase bottom margin so this title will also fit into viewport
bgneal@106: F.current.margin[2] += Math.abs( getScalar(title.css('margin-bottom')) );
bgneal@106: break;
bgneal@106: }
bgneal@106:
bgneal@106: title[ (opts.position === 'top' ? 'prependTo' : 'appendTo') ](target);
bgneal@106: }
bgneal@106: };
bgneal@106:
bgneal@106: // jQuery plugin initialization
bgneal@106: $.fn.fancybox = function (options) {
bgneal@106: var index,
bgneal@106: that = $(this),
bgneal@106: selector = this.selector || '',
bgneal@106: run = function(e) {
bgneal@106: var what = $(this).blur(), idx = index, relType, relVal;
bgneal@106:
bgneal@106: if (!(e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) && !what.is('.fancybox-wrap')) {
bgneal@106: relType = options.groupAttr || 'data-fancybox-group';
bgneal@106: relVal = what.attr(relType);
bgneal@106:
bgneal@106: if (!relVal) {
bgneal@106: relType = 'rel';
bgneal@106: relVal = what.get(0)[ relType ];
bgneal@106: }
bgneal@106:
bgneal@106: if (relVal && relVal !== '' && relVal !== 'nofollow') {
bgneal@106: what = selector.length ? $(selector) : that;
bgneal@106: what = what.filter('[' + relType + '="' + relVal + '"]');
bgneal@106: idx = what.index(this);
bgneal@106: }
bgneal@106:
bgneal@106: options.index = idx;
bgneal@106:
bgneal@106: // Stop an event from bubbling if everything is fine
bgneal@106: if (F.open(what, options) !== false) {
bgneal@106: e.preventDefault();
bgneal@106: }
bgneal@106: }
bgneal@106: };
bgneal@106:
bgneal@106: options = options || {};
bgneal@106: index = options.index || 0;
bgneal@106:
bgneal@106: if (!selector || options.live === false) {
bgneal@106: that.unbind('click.fb-start').bind('click.fb-start', run);
bgneal@106:
bgneal@106: } else {
bgneal@106: D.undelegate(selector, 'click.fb-start').delegate(selector + ":not('.fancybox-item, .fancybox-nav')", 'click.fb-start', run);
bgneal@106: }
bgneal@106:
bgneal@106: this.filter('[data-fancybox-start=1]').trigger('click');
bgneal@106:
bgneal@106: return this;
bgneal@106: };
bgneal@106:
bgneal@106: // Tests that need a body at doc ready
bgneal@106: D.ready(function() {
bgneal@106: var w1, w2;
bgneal@106:
bgneal@106: if ( $.scrollbarWidth === undefined ) {
bgneal@106: // http://benalman.com/projects/jquery-misc-plugins/#scrollbarwidth
bgneal@106: $.scrollbarWidth = function() {
bgneal@106: var parent = $('
').appendTo('body'),
bgneal@106: child = parent.children(),
bgneal@106: width = child.innerWidth() - child.height( 99 ).innerWidth();
bgneal@106:
bgneal@106: parent.remove();
bgneal@106:
bgneal@106: return width;
bgneal@106: };
bgneal@106: }
bgneal@106:
bgneal@106: if ( $.support.fixedPosition === undefined ) {
bgneal@106: $.support.fixedPosition = (function() {
bgneal@106: var elem = $('
').appendTo('body'),
bgneal@106: fixed = ( elem[0].offsetTop === 20 || elem[0].offsetTop === 15 );
bgneal@106:
bgneal@106: elem.remove();
bgneal@106:
bgneal@106: return fixed;
bgneal@106: }());
bgneal@106: }
bgneal@106:
bgneal@106: $.extend(F.defaults, {
bgneal@106: scrollbarWidth : $.scrollbarWidth(),
bgneal@106: fixed : $.support.fixedPosition,
bgneal@106: parent : $('body')
bgneal@106: });
bgneal@106:
bgneal@106: //Get real width of page scroll-bar
bgneal@106: w1 = $(window).width();
bgneal@106:
bgneal@106: H.addClass('fancybox-lock-test');
bgneal@106:
bgneal@106: w2 = $(window).width();
bgneal@106:
bgneal@106: H.removeClass('fancybox-lock-test');
bgneal@106:
bgneal@106: $("").appendTo("head");
bgneal@106: });
bgneal@106:
bgneal@106: }(window, document, jQuery));