/*! * fancybox - jquery plugin * version: 2.0.6 (16/04/2012) * @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 w = $(window), d = $(document), f = $.fancybox = function () { f.open.apply( this, arguments ); }, didresize = false, resizetimer = null, istouch = document.createtouch !== undefined, isstring = function(str) { return $.type(str) === "string"; }, ispercentage = function(str) { return isstring(str) && str.indexof('%') > 0; }, getvalue = function(value, dim) { if (dim && ispercentage(value)) { value = f.getviewport()[ dim ] / 100 * parseint(value, 10); } return math.round(value) + 'px'; }; $.extend(f, { // the current version of fancybox version: '2.0.5', defaults: { padding: 0, margin: 0, width: 700, height: 400, minwidth: 100, minheight: 100, maxwidth: 9999, maxheight: 9999, autosize: true, autoresize: !istouch, autocenter : !istouch, fittoview: true, aspectratio: false, topratio: 0.5, fixed: false, 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 } }, keys: { next: [13, 32, 34, 39, 40], // enter, space, page down, right arrow, down arrow prev: [8, 33, 37, 38], // backspace, page up, left arrow, up arrow close: [27] // escape key }, // override some properties index: 0, type: null, href: null, content: null, title: null, // html templates tpl: { wrap: '
', image: '', iframe: '', swf: '', error: '

the requested content cannot be loaded.
please try again later.

', closebtn: '
', next: '', prev: '' }, // properties for each animation type // opening fancybox openeffect: 'fade', // 'elastic', 'fade' or 'none' openspeed: 300, openeasing: 'swing', openopacity: true, openmethod: 'zoomin', // closing fancybox closeeffect: 'fade', // 'elastic', 'fade' or 'none' closespeed: 300, closeeasing: 'swing', closeopacity: true, closemethod: 'zoomout', // changing next gallery item nexteffect: 'elastic', // 'elastic', 'fade' or 'none' nextspeed: 300, nexteasing: 'swing', nextmethod: 'changein', // changing previous gallery item preveffect: 'elastic', // 'elastic', 'fade' or 'none' prevspeed: 300, preveasing: 'swing', prevmethod: 'changeout', // enabled helpers helpers: { overlay: { speedin: 0, speedout: 300, opacity: 0.8, css: { cursor: 'pointer' }, closeclick: true }, title: { type: 'float' // 'float', 'inside', 'outside' or 'over' } }, // callbacks oncancel: $.noop, // if canceling beforeload: $.noop, // before loading afterload: $.noop, // after loading beforeshow: $.noop, // before changing in current item aftershow: $.noop, // after opening beforeclose: $.noop, // before closing afterclose: $.noop // after closing }, //current state group: {}, // selected group opts: {}, // group options coming: null, // element being loaded current: null, // currently loaded element isopen: false, // is currently open isopened: false, // have been fully opened at least once wrap: null, skin: null, outer: null, inner: null, player: { timer: null, isactive: false }, // loaders ajaxload: null, imgpreload: null, // some collections transitions: {}, helpers: {}, /* * static methods */ open: function (group, opts) { //kill existing instances f.close(true); //normalize group if (group && !$.isarray(group)) { group = group instanceof $ ? $(group).get() : [group]; } f.isactive = true; //extend the defaults f.opts = $.extend(true, {}, f.defaults, opts); //all options are merged recursive except keys if ($.isplainobject(opts) && opts.keys !== undefined) { f.opts.keys = opts.keys ? $.extend({}, f.defaults.keys, opts.keys) : false; } f.group = group; f._start(f.opts.index || 0); }, cancel: function () { if (f.coming && false === f.trigger('oncancel')) { return; } f.coming = null; f.hideloading(); if (f.ajaxload) { f.ajaxload.abort(); } f.ajaxload = null; if (f.imgpreload) { f.imgpreload.onload = f.imgpreload.onabort = f.imgpreload.onerror = null; } }, close: function (a) { f.cancel(); if (!f.current || false === f.trigger('beforeclose')) { return; } f.unbindevents(); //if forced or is still opening then remove immediately if (!f.isopen || (a && a[0] === true)) { $('.fancybox-wrap').stop().trigger('onreset').remove(); f._afterzoomout(); } else { f.isopen = f.isopened = false; $('.fancybox-item, .fancybox-nav').remove(); f.wrap.stop(true).removeclass('fancybox-opened'); f.inner.css('overflow', 'hidden'); f.transitions[f.current.closemethod](); } }, // start/stop slideshow play: function (a) { var clear = function () { cleartimeout(f.player.timer); }, set = function () { clear(); if (f.current && f.player.isactive) { f.player.timer = settimeout(f.next, f.current.playspeed); } }, stop = function () { clear(); $('body').unbind('.player'); f.player.isactive = false; f.trigger('onplayend'); }, start = function () { if (f.current && (f.current.loop || f.current.index < f.group.length - 1)) { f.player.isactive = true; $('body').bind({ 'aftershow.player onupdate.player': set, 'oncancel.player beforeclose.player': stop, 'beforeload.player': clear }); set(); f.trigger('onplaystart'); } }; if (f.player.isactive || (a && a[0] === false)) { stop(); } else { start(); } }, next: function () { if (f.current) { f.jumpto(f.current.index + 1); } }, prev: function () { if (f.current) { f.jumpto(f.current.index - 1); } }, jumpto: function (index) { if (!f.current) { return; } index = parseint(index, 10); if (f.group.length > 1 && f.current.loop) { if (index >= f.group.length) { index = 0; } else if (index < 0) { index = f.group.length - 1; } } if (f.group[index] !== undefined) { f.cancel(); f._start(index); } }, reposition: function (e, onlyabsolute) { var pos; if (f.isopen) { pos = f._getposition(onlyabsolute); if (e && e.type === 'scroll') { delete pos.position; f.wrap.stop(true, true).animate(pos, 200); } else { f.wrap.css(pos); } } }, update: function (e) { if (!f.isopen) { return; } // run this code after a delay for better performance if (!didresize) { resizetimer = settimeout(function () { var current = f.current, anyway = !e || (e && e.type === 'orientationchange'); if (didresize) { didresize = false; if (!current) { return; } if ((!e || e.type !== 'scroll') || anyway) { if (current.autosize && current.type !== 'iframe') { f.inner.height('auto'); current.height = f.inner.height(); } if (current.autoresize || anyway) { f._setdimension(); } if (current.cangrow && current.type !== 'iframe') { f.inner.height('auto'); } } if (current.autocenter || anyway) { f.reposition(e); } f.trigger('onupdate'); } }, 200); } didresize = true; }, toggle: function () { if (f.isopen) { f.current.fittoview = !f.current.fittoview; f.update(); } }, hideloading: function () { d.unbind('keypress.fb'); $('#fancybox-loading').remove(); }, showloading: function () { f.hideloading(); //if user will press the escape-button, the request will be canceled d.bind('keypress.fb', function(e) { if (e.keycode === 27) { e.preventdefault(); f.cancel(); } }); $('
').click(f.cancel).appendto('body'); }, getviewport: function () { // see http://bugs.jquery.com/ticket/6724 return { x: w.scrollleft(), y: w.scrolltop(), w: istouch && window.innerwidth ? window.innerwidth : w.width(), h: istouch && window.innerheight ? window.innerheight : w.height() }; }, // unbind the keyboard / clicking actions unbindevents: function () { if (f.wrap) { f.wrap.unbind('.fb'); } d.unbind('.fb'); w.unbind('.fb'); }, bindevents: function () { var current = f.current, keys = current.keys; if (!current) { return; } w.bind('resize.fb orientationchange.fb' + (current.autocenter && !current.fixed ? ' scroll.fb' : ''), f.update); if (keys) { d.bind('keydown.fb', function (e) { var code, target = e.target || e.srcelement; // ignore key combinations and key events within form elements if (!e.ctrlkey && !e.altkey && !e.shiftkey && !e.metakey && !(target && (target.type || $(target).is('[contenteditable]')))) { code = e.keycode; if ($.inarray(code, keys.close) > -1) { f.close(); e.preventdefault(); } else if ($.inarray(code, keys.next) > -1) { f.next(); e.preventdefault(); } else if ($.inarray(code, keys.prev) > -1) { f.prev(); e.preventdefault(); } } }); } if ($.fn.mousewheel && current.mousewheel && f.group.length > 1) { f.wrap.bind('mousewheel.fb', function (e, delta) { var target = e.target || null; if (delta !== 0 && (!target || target.clientheight === 0 || (target.scrollheight === target.clientheight && target.scrollwidth === target.clientwidth))) { e.preventdefault(); f[delta > 0 ? 'prev' : 'next'](); } }); } }, trigger: function (event, o) { var ret, obj = o || f[ $.inarray(event, ['oncancel', 'beforeload', 'afterload']) > -1 ? 'coming' : 'current' ]; if (!obj) { return; } if ($.isfunction( obj[event] )) { ret = obj[event].apply(obj, array.prototype.slice.call(arguments, 1)); } if (ret === false) { return false; } if (obj.helpers) { $.each(obj.helpers, function (helper, opts) { if (opts && $.isplainobject(f.helpers[helper]) && $.isfunction(f.helpers[helper][event])) { f.helpers[helper][event](opts, obj); } }); } $.event.trigger(event + '.fb'); }, isimage: function (str) { return isstring(str) && str.match(/\.(jpe?g|gif|png|bmp)((\?|#).*)?$/i); }, isswf: function (str) { return isstring(str) && str.match(/\.(swf)((\?|#).*)?$/i); }, _start: function (index) { var coming = {}, element = f.group[index] || null, isdom, href, type, rez, hrefparts; if (element && (element.nodetype || element instanceof $)) { isdom = true; if ($.metadata) { coming = $(element).metadata(); } } coming = $.extend(true, {}, f.opts, {index : index, element : element}, ($.isplainobject(element) ? element : coming)); // re-check overridable options $.each(['href', 'title', 'content', 'type'], function(i,v) { coming[v] = f.opts[ v ] || (isdom && $(element).attr( v )) || coming[ v ] || null; }); // convert margin property to array - top, right, bottom, left if (typeof coming.margin === 'number') { coming.margin = [coming.margin, coming.margin, coming.margin, coming.margin]; } // 'modal' propery is just a shortcut if (coming.modal) { $.extend(true, coming, { closebtn : false, closeclick: false, nextclick : false, arrows : false, mousewheel : false, keys : null, helpers: { overlay : { css: { cursor : 'auto' }, closeclick : false } } }); } //give a chance for callback or helpers to update coming item (type, title, etc) f.coming = coming; if (false === f.trigger('beforeload')) { f.coming = null; return; } type = coming.type; href = coming.href || element; ///check if content type is set, if not, try to get if (!type) { if (isdom) { type = $(element).data('fancybox-type'); if (!type) { rez = element.classname.match(/fancybox\.(\w+)/); type = rez ? rez[1] : null; } } if (!type && isstring(href)) { if (f.isimage(href)) { type = 'image'; } else if (f.isswf(href)) { type = 'swf'; } else if (href.match(/^#/)) { type = 'inline'; } } // ...if not - display element itself if (!type) { type = isdom ? 'inline' : 'html'; } coming.type = type; } // check before try to load; 'inline' and 'html' types need content, others - href if (type === 'inline' || type === 'html') { if (!coming.content) { if (type === 'inline') { coming.content = $( isstring(href) ? href.replace(/.*(?=#[^\s]+$)/, '') : href ); //strip for ie7 } else { coming.content = element; } } if (!coming.content || !coming.content.length) { type = null; } } else if (!href) { type = null; } /* * add reference to the group, so it`s possible to access from callbacks, example: * afterload : function() { * this.title = 'image ' + (this.index + 1) + ' of ' + this.group.length + (this.title ? ' - ' + this.title : ''); * } */ if (type === 'ajax' && isstring(href)) { hrefparts = href.split(/\s+/, 2); href = hrefparts.shift(); coming.selector = hrefparts.shift(); } coming.href = href; coming.group = f.group; coming.isdom = isdom; switch (type) { case 'image': f._loadimage(); break; case 'ajax': f._loadajax(); break; case 'inline': case 'iframe': case 'swf': case 'html': f._afterload(); break; default: f._error( 'type' ); } }, _error: function ( type ) { f.hideloading(); $.extend(f.coming, { type : 'html', autosize : true, minwidth : 0, minheight : 0, padding : 15, haserror : type, content : f.coming.tpl.error }); f._afterload(); }, _loadimage: function () { // reset preload image so it is later possible to check "complete" property var img = f.imgpreload = new image(); img.onload = function () { this.onload = this.onerror = null; f.coming.width = this.width; f.coming.height = this.height; f._afterload(); }; img.onerror = function () { this.onload = this.onerror = null; f._error( 'image' ); }; img.src = f.coming.href; if (img.complete === undefined || !img.complete) { f.showloading(); } }, _loadajax: function () { f.showloading(); f.ajaxload = $.ajax($.extend({}, f.coming.ajax, { url: f.coming.href, error: function (jqxhr, textstatus) { if (f.coming && textstatus !== 'abort') { f._error( 'ajax', jqxhr ); } else { f.hideloading(); } }, success: function (data, textstatus) { if (textstatus === 'success') { f.coming.content = data; f._afterload(); } } })); }, _preloadimages: function() { var group = f.group, current = f.current, len = group.length, item, href, i, cnt = math.min(current.preload, len - 1); if (!current.preload || group.length < 2) { return; } for (i = 1; i <= cnt; i += 1) { item = group[ (current.index + i ) % len ]; href = item.href || $( item ).attr('href') || item; if (item.type === 'image' || f.isimage(href)) { new image().src = href; } } }, _afterload: function () { f.hideloading(); if (!f.coming || false === f.trigger('afterload', f.current)) { f.coming = false; return; } if (f.isopened) { $('.fancybox-item, .fancybox-nav').remove(); f.wrap.stop(true).removeclass('fancybox-opened'); f.inner.css('overflow', 'hidden'); f.transitions[f.current.prevmethod](); } else { $('.fancybox-wrap').stop().trigger('onreset').remove(); f.trigger('afterclose'); } f.unbindevents(); f.isopen = false; f.current = f.coming; //build the neccessary markup f.wrap = $(f.current.tpl.wrap).addclass('fancybox-' + (istouch ? 'mobile' : 'desktop') + ' fancybox-type-' + f.current.type + ' fancybox-tmp ' + f.current.wrapcss).appendto('body'); f.skin = $('.fancybox-skin', f.wrap).css('padding', getvalue(f.current.padding)); f.outer = $('.fancybox-outer', f.wrap); f.inner = $('.fancybox-inner', f.wrap); f._setcontent(); }, _setcontent: function () { var current = f.current, content = current.content, type = current.type, minwidth = current.minwidth, minheight = current.minheight, maxwidth = current.maxwidth, maxheight = current.maxheight, loadingbay; switch (type) { case 'inline': case 'ajax': case 'html': if (current.selector) { content = $('
').html(content).find(current.selector); } else if (content instanceof $) { if (content.parent().hasclass('fancybox-inner')) { content.parents('.fancybox-wrap').unbind('onreset'); } content = content.show().detach(); $(f.wrap).bind('onreset', function () { content.appendto('body').hide(); }); } if (current.autosize) { loadingbay = $('
') .appendto('body') .css({ minwidth : getvalue(minwidth, 'w'), minheight : getvalue(minheight, 'h'), maxwidth : getvalue(maxwidth, 'w'), maxheight : getvalue(maxheight, 'h') }) .append(content); current.width = loadingbay.width(); current.height = loadingbay.height(); // re-check to fix 1px bug in some browsers loadingbay.width( f.current.width ); if (loadingbay.height() > current.height) { loadingbay.width(current.width + 1); current.width = loadingbay.width(); current.height = loadingbay.height(); } content = loadingbay.contents().detach(); loadingbay.remove(); } break; case 'image': content = current.tpl.image.replace('{href}', current.href); current.aspectratio = true; break; case 'swf': content = current.tpl.swf.replace(/\{width\}/g, current.width).replace(/\{height\}/g, current.height).replace(/\{href\}/g, current.href); break; case 'iframe': content = $(current.tpl.iframe.replace('{rnd}', new date().gettime()) ) .attr('scrolling', current.scrolling) .attr('src', current.href); current.scrolling = istouch ? 'scroll' : 'auto'; break; } if (type === 'image' || type === 'swf') { current.autosize = false; current.scrolling = 'visible'; } if (type === 'iframe' && current.autosize) { f.showloading(); f._setdimension(); f.inner.css('overflow', current.scrolling); content.bind({ oncancel : function() { $(this).unbind(); f._afterzoomout(); }, load : function() { f.hideloading(); try { if (this.contentwindow.document.location) { f.current.height = $(this).contents().find('body').height(); } } catch (e) { f.current.autosize = false; } f[ f.isopen ? '_afterzoomin' : '_beforeshow'](); } }).appendto(f.inner); } else { f.inner.append(content); f._beforeshow(); } }, _beforeshow : function() { f.coming = null; //give a chance for helpers or callbacks to update elements f.trigger('beforeshow'); //set initial dimensions and hide f._setdimension(); f.wrap.hide().removeclass('fancybox-tmp'); f.bindevents(); f._preloadimages(); f.transitions[ f.isopened ? f.current.nextmethod : f.current.openmethod ](); }, _setdimension: function () { var wrap = f.wrap, inner = f.inner, current = f.current, viewport = f.getviewport(), margin = current.margin, padding2 = current.padding * 2, width = current.width, height = current.height, maxwidth = current.maxwidth + padding2, maxheight = current.maxheight + padding2, minwidth = current.minwidth + padding2, minheight = current.minheight + padding2, ratio, height_; viewport.w -= (margin[1] + margin[3]); viewport.h -= (margin[0] + margin[2]); if (ispercentage(width)) { width = (((viewport.w - padding2) * parsefloat(width)) / 100); } if (ispercentage(height)) { height = (((viewport.h - padding2) * parsefloat(height)) / 100); } ratio = width / height; width += padding2; height += padding2; if (current.fittoview) { maxwidth = math.min(viewport.w, maxwidth); maxheight = math.min(viewport.h, maxheight); } if (current.aspectratio) { if (width > maxwidth) { width = maxwidth; height = ((width - padding2) / ratio) + padding2; } if (height > maxheight) { height = maxheight; width = ((height - padding2) * ratio) + padding2; } if (width < minwidth) { width = minwidth; height = ((width - padding2) / ratio) + padding2; } if (height < minheight) { height = minheight; width = ((height - padding2) * ratio) + padding2; } } else { width = math.max(minwidth, math.min(width, maxwidth)); height = math.max(minheight, math.min(height, maxheight)); } width = math.round(width); height = math.round(height); //reset dimensions $(wrap.add(inner)).width('auto').height('auto'); inner.width(width - padding2).height(height - padding2); wrap.width(width); height_ = wrap.height(); // real wrap height //fit wrapper inside if (width > maxwidth || height_ > maxheight) { while ((width > maxwidth || height_ > maxheight) && width > minwidth && height_ > minheight) { height = height - 10; if (current.aspectratio) { width = math.round(((height - padding2) * ratio) + padding2); if (width < minwidth) { width = minwidth; height = ((width - padding2) / ratio) + padding2; } } else { width = width - 10; } inner.width(width - padding2).height(height - padding2); wrap.width(width); height_ = wrap.height(); } } current.dim = { width : getvalue(width), height : getvalue(height_) }; current.cangrow = current.autosize && height > minheight && height < maxheight; current.canshrink = false; current.canexpand = false; if ((width - padding2) < current.width || (height - padding2) < current.height) { current.canexpand = true; } else if ((width > viewport.w || height_ > viewport.h) && width > minwidth && height > minheight) { current.canshrink = true; } f.innerspace = height_ - padding2 - inner.height(); }, _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] + viewport.y, left : margin[3] + viewport.x }; if (current.autocenter && current.fixed && !onlyabsolute && height <= viewport.h && width <= viewport.w) { rez = { position: 'fixed', top : margin[0], left : margin[3] }; } 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) * 0.5))); return rez; }, _afterzoomin: function () { var current = f.current, scrolling = current ? current.scrolling : 'no'; if (!current) { return; } f.isopen = f.isopened = true; f.wrap.addclass('fancybox-opened'); f.inner.css('overflow', scrolling === 'yes' ? 'scroll' : (scrolling === 'no' ? 'hidden' : scrolling)); f.trigger('aftershow'); f.update(); //assign a click event if (current.closeclick || current.nextclick) { f.inner.css('cursor', 'pointer').bind('click.fb', function(e) { if (!$(e.target).is('a') && !$(e.target).parent().is('a')) { f[ current.closeclick ? 'close' : 'next' ](); } }); } //create a close button if (current.closebtn) { $(current.tpl.closebtn).appendto(f.skin).bind('click.fb', 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); } } if (f.opts.autoplay && !f.player.isactive) { f.opts.autoplay = false; f.play(); } }, _afterzoomout: function () { var current = f.current; f.wrap.trigger('onreset').remove(); $.extend(f, { group: {}, opts: {}, current: null, isactive: false, isopened: false, isopen: false, wrap: null, skin: null, outer: null, inner: null }); f.trigger('afterclose', current); } }); /* * default transitions */ f.transitions = { getorigposition: function () { var current = f.current, element = current.element, padding = current.padding, orig = $(current.orig), pos = {}, width = 50, height = 50, viewport; if (!orig.length && current.isdom && $(element).is(':visible')) { orig = $(element).find('img:first'); if (!orig.length) { orig = $(element); } } if (orig.length) { pos = orig.offset(); if (orig.is('img')) { width = orig.outerwidth(); height = orig.outerheight(); } } else { viewport = f.getviewport(); pos.top = viewport.y + (viewport.h - height) * 0.5; pos.left = viewport.x + (viewport.w - width) * 0.5; } pos = { top : getvalue(pos.top - padding), left : getvalue(pos.left - padding), width : getvalue(width + padding * 2), height : getvalue(height + padding * 2) }; return pos; }, step: function (now, fx) { var prop = fx.prop, value, ratio; if (prop === 'width' || prop === 'height') { value = math.ceil(now - (f.current.padding * 2)); if (prop === 'height') { ratio = (now - fx.start) / (fx.end - fx.start); if (fx.start > fx.end) { ratio = 1 - ratio; } value -= f.innerspace * ratio; } f.inner[prop](value); } }, zoomin: function () { var wrap = f.wrap, current = f.current, effect = current.openeffect, elastic = effect === 'elastic', dim = current.dim, startpos = $.extend({}, dim, f._getposition( 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; } f.outer.add(f.inner).width('auto').height('auto'); } else if (effect === 'fade') { startpos.opacity = 0; } wrap.css(startpos) .show() .animate(endpos, { duration : effect === 'none' ? 0 : current.openspeed, easing : current.openeasing, step : elastic ? this.step : null, complete : f._afterzoomin }); }, zoomout: function () { var wrap = f.wrap, current = f.current, effect = current.openeffect, elastic = effect === 'elastic', endpos = {opacity : 0}; if (elastic) { if (wrap.css('position') === 'fixed') { wrap.css(f._getposition(true)); } endpos = this.getorigposition(); if (current.closeopacity) { endpos.opacity = 0; } } wrap.animate(endpos, { duration : effect === 'none' ? 0 : current.closespeed, easing : current.closeeasing, step : elastic ? this.step : null, complete : f._afterzoomout }); }, changein: function () { var wrap = f.wrap, current = f.current, effect = current.nexteffect, elastic = effect === 'elastic', startpos = f._getposition( elastic ), endpos = { opacity : 1 }; startpos.opacity = 0; if (elastic) { startpos.top = getvalue(parseint(startpos.top, 10) - 200); endpos.top = '+=200px'; } wrap.css(startpos) .show() .animate(endpos, { duration : effect === 'none' ? 0 : current.nextspeed, easing : current.nexteasing, complete : f._afterzoomin }); }, changeout: function () { var wrap = f.wrap, current = f.current, effect = current.preveffect, endpos = { opacity : 0 }, cleanup = function () { $(this).trigger('onreset').remove(); }; wrap.removeclass('fancybox-opened'); if (effect === 'elastic') { endpos.top = '+=200px'; } wrap.animate(endpos, { duration : effect === 'none' ? 0 : current.prevspeed, easing : current.preveasing, complete : cleanup }); } }; /* * overlay helper */ f.helpers.overlay = { overlay: null, update: function () { var width, scrollwidth, offsetwidth; //reset width/height so it will not mess this.overlay.width('100%').height('100%'); if ($.browser.msie || istouch) { scrollwidth = math.max(document.documentelement.scrollwidth, document.body.scrollwidth); offsetwidth = math.max(document.documentelement.offsetwidth, document.body.offsetwidth); width = scrollwidth < offsetwidth ? w.width() : scrollwidth; } else { width = d.width(); } this.overlay.width(width).height(d.height()); }, beforeshow: function (opts) { if (this.overlay) { return; } opts = $.extend(true, {}, f.defaults.helpers.overlay, opts); this.overlay = $('
').css(opts.css).appendto('body'); if (opts.closeclick) { this.overlay.bind('click.fb', f.close); } if (f.current.fixed && !istouch) { this.overlay.addclass('overlay-fixed'); } else { this.update(); this.onupdate = function () { this.update(); }; } this.overlay.fadeto(opts.speedin, opts.opacity); }, afterclose: function (opts) { if (this.overlay) { this.overlay.fadeout(opts.speedout || 0, function () { $(this).remove(); }); } this.overlay = null; } }; /* * title helper */ f.helpers.title = { beforeshow: function (opts) { var title, text = f.current.title; if (text) { title = $('
' + text + '
').appendto('body'); if (opts.type === 'float') { //this helps for some browsers title.width(title.width()); title.wrapinner(''); //increase bottom margin so this title will also fit into viewport f.current.margin[2] += math.abs(parseint(title.css('margin-bottom'), 10)); } title.appendto(opts.type === 'over' ? f.inner : (opts.type === 'outside' ? f.wrap : f.skin)); } } }; // jquery plugin initialization $.fn.fancybox = function (options) { var that = $(this), selector = this.selector || '', index, run = function(e) { var what = this, idx = index, reltype, relval; if (!(e.ctrlkey || e.altkey || e.shiftkey || e.metakey) && !$(what).is('.fancybox-wrap')) { e.preventdefault(); reltype = options.groupattr || 'data-fancybox-group'; relval = $(what).attr(reltype); if (!relval) { reltype = 'rel'; relval = what[ reltype ]; } if (relval && relval !== '' && relval !== 'nofollow') { what = selector.length ? $(selector) : that; what = what.filter('[' + reltype + '="' + relval + '"]'); idx = what.index(this); } options.index = idx; f.open(what, options); } }; options = options || {}; index = options.index || 0; if (selector) { d.undelegate(selector, 'click.fb-start').delegate(selector, 'click.fb-start', run); } else { that.unbind('click.fb-start').bind('click.fb-start', run); } return this; }; // test for fixedposition needs a body at doc ready $(document).ready(function() { f.defaults.fixed = $.support.fixedposition || (!($.browser.msie && $.browser.version <= 6) && !istouch); }); }(window, document, jquery));