woocommerce/assets/js/fancybox.min.js

16 lines
15 KiB
JavaScript

/*
* FancyBox - jQuery Plugin
* Simple and fancy lightbox alternative
*
* Examples and documentation at: http://fancybox.net
*
* Copyright © 2008 - 2010 Janis Skarnelis
* That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
*
* Version: 1.3.4 (11/11/2010)
* Requires: jQuery v1.3+
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/(function(a){var b,c,d,e,f,g,h,i,j,k,l=0,m={},n=[],o=0,p={},q=[],r=null,s=new Image,t=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,u=/[^\.]\.(swf)\s*$/i,v,w=1,x=0,y="",z,A,B=!1,C=a.extend(a("<div/>")[0],{prop:0}),D=a.browser.msie&&a.browser.version<7&&!window.XMLHttpRequest,E=function(){c.hide();s.onerror=s.onload=null;r&&r.abort();b.empty()},F=function(){if(!1===m.onError(n,l,m)){c.hide();B=!1;return}m.titleShow=!1;m.width="auto";m.height="auto";b.html('<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>');H()},G=function(){var d=n[l],e,f,h,i,j,k;E();m=a.extend({},a.fn.fancybox.defaults,typeof a(d).data("fancybox")=="undefined"?m:a(d).data("fancybox"));k=m.onStart(n,l,m);if(k===!1){B=!1;return}typeof k=="object"&&(m=a.extend(m,k));h=m.title||(d.nodeName?a(d).attr("title"):d.title)||"";d.nodeName&&!m.orig&&(m.orig=a(d).children("img:first").length?a(d).children("img:first"):a(d));h===""&&m.orig&&m.titleFromAlt&&(h=m.orig.attr("alt"));e=m.href||(d.nodeName?a(d).attr("href"):d.href)||null;if(/^(?:javascript)/i.test(e)||e=="#")e=null;if(m.type){f=m.type;e||(e=m.content)}else m.content?f="html":e&&(e.match(t)?f="image":e.match(u)?f="swf":a(d).hasClass("iframe")?f="iframe":e.indexOf("#")===0?f="inline":f="ajax");if(!f){F();return}if(f=="inline"){d=e.substr(e.indexOf("#"));f=a(d).length>0?"inline":"ajax"}m.type=f;m.href=e;m.title=h;if(m.autoDimensions)if(m.type=="html"||m.type=="inline"||m.type=="ajax"){m.width="auto";m.height="auto"}else m.autoDimensions=!1;if(m.modal){m.overlayShow=!0;m.hideOnOverlayClick=!1;m.hideOnContentClick=!1;m.enableEscapeButton=!1;m.showCloseButton=!1}m.padding=parseInt(m.padding,10);m.margin=parseInt(m.margin,10);b.css("padding",m.padding+m.margin);a(".fancybox-inline-tmp").unbind("fancybox-cancel").bind("fancybox-change",function(){a(this).replaceWith(g.children())});switch(f){case"html":b.html(m.content);H();break;case"inline":if(a(d).parent().is("#fancybox-content")===!0){B=!1;return}a('<div class="fancybox-inline-tmp" />').hide().insertBefore(a(d)).bind("fancybox-cleanup",function(){a(this).replaceWith(g.children())}).bind("fancybox-cancel",function(){a(this).replaceWith(b.children())});a(d).appendTo(b);H();break;case"image":B=!1;a.fancybox.showActivity();s=new Image;s.onerror=function(){F()};s.onload=function(){B=!0;s.onerror=s.onload=null;I()};s.src=e;break;case"swf":m.scrolling="no";i='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+m.width+'" height="'+m.height+'"><param name="movie" value="'+e+'"></param>';j="";a.each(m.swf,function(a,b){i+='<param name="'+a+'" value="'+b+'"></param>';j+=" "+a+'="'+b+'"'});i+='<embed src="'+e+'" type="application/x-shockwave-flash" width="'+m.width+'" height="'+m.height+'"'+j+"></embed></object>";b.html(i);H();break;case"ajax":B=!1;a.fancybox.showActivity();m.ajax.win=m.ajax.success;r=a.ajax(a.extend({},m.ajax,{url:e,data:m.ajax.data||{},error:function(a,b,c){a.status>0&&F()},success:function(a,d,f){var g=typeof f=="object"?f:r;if(g.status==200){if(typeof m.ajax.win=="function"){k=m.ajax.win(e,a,d,f);if(k===!1){c.hide();return}if(typeof k=="string"||typeof k=="object")a=k}b.html(a);H()}}}));break;case"iframe":J()}},H=function(){var c=m.width,d=m.height;c.toString().indexOf("%")>-1?c=parseInt((a(window).width()-m.margin*2)*parseFloat(c)/100,10)+"px":c=c=="auto"?"auto":c+"px";d.toString().indexOf("%")>-1?d=parseInt((a(window).height()-m.margin*2)*parseFloat(d)/100,10)+"px":d=d=="auto"?"auto":d+"px";b.wrapInner('<div style="width:'+c+";height:"+d+";overflow: "+(m.scrolling=="auto"?"auto":m.scrolling=="yes"?"scroll":"hidden")+';position:relative;"></div>');m.width=b.width();m.height=b.height();J()},I=function(){m.width=s.width;m.height=s.height;a("<img />").attr({id:"fancybox-img",src:s.src,alt:m.title}).appendTo(b);J()},J=function(){var f,r;c.hide();if(e.is(":visible")&&!1===p.onCleanup(q,o,p)){a.event.trigger("fancybox-cancel");B=!1;return}B=!0;a(g.add(d)).unbind();a(window).unbind("resize.fb scroll.fb");a(document).unbind("keydown.fb");e.is(":visible")&&p.titlePosition!=="outside"&&e.css("height",e.height());q=n;o=l;p=m;if(p.overlayShow){d.css({"background-color":p.overlayColor,opacity:p.overlayOpacity,cursor:p.hideOnOverlayClick?"pointer":"auto",height:a(document).height()});if(!d.is(":visible")){D&&a("select:not(#fancybox-tmp select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("fancybox-cleanup",function(){this.style.visibility="inherit"});d.show()}}else d.hide();A=R();L();if(e.is(":visible")){a(h.add(j).add(k)).hide();f=e.position(),z={top:f.top,left:f.left,width:e.width(),height:e.height()};r=z.width==A.width&&z.height==A.height;g.fadeTo(p.changeFade,.3,function(){var c=function(){g.html(b.contents()).fadeTo(p.changeFade,1,N)};a.event.trigger("fancybox-change");g.empty().removeAttr("filter").css({"border-width":p.padding,width:A.width-p.padding*2,height:m.autoDimensions?"auto":A.height-x-p.padding*2});if(r)c();else{C.prop=0;a(C).animate({prop:1},{duration:p.changeSpeed,easing:p.easingChange,step:P,complete:c})}});return}e.removeAttr("style");g.css("border-width",p.padding);if(p.transitionIn=="elastic"){z=T();g.html(b.contents());e.show();p.opacity&&(A.opacity=0);C.prop=0;a(C).animate({prop:1},{duration:p.speedIn,easing:p.easingIn,step:P,complete:N});return}p.titlePosition=="inside"&&x>0&&i.show();g.css({width:A.width-p.padding*2,height:m.autoDimensions?"auto":A.height-x-p.padding*2}).html(b.contents());e.css(A).fadeIn(p.transitionIn=="none"?0:p.speedIn,N)},K=function(a){return a&&a.length?'<div id="fancybox-title-'+p.titlePosition+'">'+a+"</div>":!1},L=function(){y=p.title||"";x=0;i.empty().removeAttr("style").removeClass();if(p.titleShow===!1){i.hide();return}y=a.isFunction(p.titleFormat)?p.titleFormat(y,q,o,p):K(y);if(!y||y===""){i.hide();return}i.addClass("fancybox-title-"+p.titlePosition).html(y).appendTo("body").show();switch(p.titlePosition){case"inside":i.css({width:A.width-p.padding*2,marginLeft:p.padding,marginRight:p.padding});x=i.outerHeight(!0);i.appendTo(f);A.height+=x;break;case"over":i.css({marginLeft:p.padding,width:A.width-p.padding*2,bottom:p.padding}).appendTo(f);break;case"float":i.css("left",parseInt((i.width()-A.width-40)/2,10)*-1).appendTo(e);break;default:i.css({width:A.width-p.padding*2,paddingLeft:p.padding,paddingRight:p.padding}).appendTo(e)}i.hide()},M=function(){(p.enableEscapeButton||p.enableKeyboardNav)&&a(document).bind("keydown.fb",function(b){if(b.keyCode==27&&p.enableEscapeButton){b.preventDefault();a.fancybox.close()}else if((b.keyCode==37||b.keyCode==39)&&p.enableKeyboardNav&&b.target.tagName!=="INPUT"&&b.target.tagName!=="TEXTAREA"&&b.target.tagName!=="SELECT"){b.preventDefault();a.fancybox[b.keyCode==37?"prev":"next"]()}});if(!p.showNavArrows){j.hide();k.hide();return}(p.cyclic&&q.length>1||o!==0)&&j.show();(p.cyclic&&q.length>1||o!=q.length-1)&&k.show()},N=function(){if(!a.support.opacity){g.get(0).style.removeAttribute("filter");e.get(0).style.removeAttribute("filter")}m.autoDimensions&&g.css("height","auto");e.css("height","auto");y&&y.length&&i.show();p.showCloseButton&&h.show();M();p.hideOnContentClick&&g.bind("click",a.fancybox.close);p.hideOnOverlayClick&&d.bind("click",a.fancybox.close);a(window).bind("resize.fb",a.fancybox.resize);p.centerOnScroll&&a(window).bind("scroll.fb",a.fancybox.center);p.type=="iframe"&&a('<iframe id="fancybox-frame" name="fancybox-frame'+(new Date).getTime()+'" frameborder="0" hspace="0" '+(a.browser.msie?'allowtransparency="true""':"")+' scrolling="'+m.scrolling+'" src="'+p.href+'"></iframe>').appendTo(g);e.show();B=!1;a.fancybox.center();p.onComplete(q,o,p);O()},O=function(){var a,b;if(q.length-1>o){a=q[o+1].href;if(typeof a!="undefined"&&a.match(t)){b=new Image;b.src=a}}if(o>0){a=q[o-1].href;if(typeof a!="undefined"&&a.match(t)){b=new Image;b.src=a}}},P=function(a){var b={width:parseInt(z.width+(A.width-z.width)*a,10),height:parseInt(z.height+(A.height-z.height)*a,10),top:parseInt(z.top+(A.top-z.top)*a,10),left:parseInt(z.left+(A.left-z.left)*a,10)};typeof A.opacity!="undefined"&&(b.opacity=a<.5?.5:a);e.css(b);g.css({width:b.width-p.padding*2,height:b.height-x*a-p.padding*2})},Q=function(){return[a(window).width()-p.margin*2,a(window).height()-p.margin*2,a(document).scrollLeft()+p.margin,a(document).scrollTop()+p.margin]},R=function(){var a=Q(),b={},c=p.autoScale,d=p.padding*2,e;p.width.toString().indexOf("%")>-1?b.width=parseInt(a[0]*parseFloat(p.width)/100,10):b.width=p.width+d;p.height.toString().indexOf("%")>-1?b.height=parseInt(a[1]*parseFloat(p.height)/100,10):b.height=p.height+d;if(c&&(b.width>a[0]||b.height>a[1]))if(m.type=="image"||m.type=="swf"){e=p.width/p.height;if(b.width>a[0]){b.width=a[0];b.height=parseInt((b.width-d)/e+d,10)}if(b.height>a[1]){b.height=a[1];b.width=parseInt((b.height-d)*e+d,10)}}else{b.width=Math.min(b.width,a[0]);b.height=Math.min(b.height,a[1])}b.top=parseInt(Math.max(a[3]-20,a[3]+(a[1]-b.height-40)*.5),10);b.left=parseInt(Math.max(a[2]-20,a[2]+(a[0]-b.width-40)*.5),10);return b},S=function(a){var b=a.offset();b.top+=parseInt(a.css("paddingTop"),10)||0;b.left+=parseInt(a.css("paddingLeft"),10)||0;b.top+=parseInt(a.css("border-top-width"),10)||0;b.left+=parseInt(a.css("border-left-width"),10)||0;b.width=a.width();b.height=a.height();return b},T=function(){var b=m.orig?a(m.orig):!1,c={},d,e;if(b&&b.length){d=S(b);c={width:d.width+p.padding*2,height:d.height+p.padding*2,top:d.top-p.padding-20,left:d.left-p.padding-20}}else{e=Q();c={width:p.padding*2,height:p.padding*2,top:parseInt(e[3]+e[1]*.5,10),left:parseInt(e[2]+e[0]*.5,10)}}return c},U=function(){if(!c.is(":visible")){clearInterval(v);return}a("div",c).css("top",w*-40+"px");w=(w+1)%12};a.fn.fancybox=function(b){if(!a(this).length)return this;a(this).data("fancybox",a.extend({},b,a.metadata?a(this).metadata():{})).unbind("click.fb").bind("click.fb",function(b){b.preventDefault();if(B)return;B=!0;a(this).blur();n=[];l=0;var c=a(this).attr("rel")||"";if(!c||c==""||c==="nofollow")n.push(this);else{n=a("a[rel="+c+"], area[rel="+c+"]");l=n.index(this)}G();return});return this};a.fancybox=function(b){var c;if(B)return;B=!0;c=typeof arguments[1]!="undefined"?arguments[1]:{};n=[];l=parseInt(c.index,10)||0;if(a.isArray(b)){for(var d=0,e=b.length;d<e;d++)typeof b[d]=="object"?a(b[d]).data("fancybox",a.extend({},c,b[d])):b[d]=a({}).data("fancybox",a.extend({content:b[d]},c));n=jQuery.merge(n,b)}else{typeof b=="object"?a(b).data("fancybox",a.extend({},c,b)):b=a({}).data("fancybox",a.extend({content:b},c));n.push(b)}if(l>n.length||l<0)l=0;G()};a.fancybox.showActivity=function(){clearInterval(v);c.show();v=setInterval(U,66)};a.fancybox.hideActivity=function(){c.hide()};a.fancybox.next=function(){return a.fancybox.pos(o+1)};a.fancybox.prev=function(){return a.fancybox.pos(o-1)};a.fancybox.pos=function(a){if(B)return;a=parseInt(a);n=q;if(a>-1&&a<q.length){l=a;G()}else if(p.cyclic&&q.length>1){l=a>=q.length?0:q.length-1;G()}return};a.fancybox.cancel=function(){if(B)return;B=!0;a.event.trigger("fancybox-cancel");E();m.onCancel(n,l,m);B=!1};a.fancybox.close=function(){function b(){d.fadeOut("fast");i.empty().hide();e.hide();a.event.trigger("fancybox-cleanup");g.empty();p.onClosed(q,o,p);q=m=[];o=l=0;p=m={};B=!1}if(B||e.is(":hidden"))return;B=!0;if(p&&!1===p.onCleanup(q,o,p)){B=!1;return}E();a(h.add(j).add(k)).hide();a(g.add(d)).unbind();a(window).unbind("resize.fb scroll.fb");a(document).unbind("keydown.fb");g.find("iframe").attr("src",D&&/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank");p.titlePosition!=="inside"&&i.empty();e.stop();if(p.transitionOut=="elastic"){z=T();var c=e.position();A={top:c.top,left:c.left,width:e.width(),height:e.height()};p.opacity&&(A.opacity=1);i.empty().hide();C.prop=1;a(C).animate({prop:0},{duration:p.speedOut,easing:p.easingOut,step:P,complete:b})}else e.fadeOut(p.transitionOut=="none"?0:p.speedOut,b)};a.fancybox.resize=function(){d.is(":visible")&&d.css("height",a(document).height());a.fancybox.center(!0)};a.fancybox.center=function(){var a,b;if(B)return;b=arguments[0]===!0?1:0;a=Q();if(!b&&(e.width()>a[0]||e.height()>a[1]))return;e.stop().animate({top:parseInt(Math.max(a[3]-20,a[3]+(a[1]-g.height()-40)*.5-p.padding)),left:parseInt(Math.max(a[2]-20,a[2]+(a[0]-g.width()-40)*.5-p.padding))},typeof arguments[0]=="number"?arguments[0]:200)};a.fancybox.init=function(){if(a("#fancybox-wrap").length)return;a("body").append(b=a('<div id="fancybox-tmp"></div>'),c=a('<div id="fancybox-loading"><div></div></div>'),d=a('<div id="fancybox-overlay"></div>'),e=a('<div id="fancybox-wrap"></div>'));f=a('<div id="fancybox-outer"></div>').append("").appendTo(e);f.append(g=a('<div id="fancybox-content"></div>'),h=a('<a id="fancybox-close">&times;</a>'),i=a('<div id="fancybox-title"></div>'),j=a('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),k=a('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>'));h.click(a.fancybox.close);c.click(a.fancybox.cancel);j.click(function(b){b.preventDefault();a.fancybox.prev()});k.click(function(b){b.preventDefault();a.fancybox.next()});a.fn.mousewheel&&e.bind("mousewheel.fb",function(b,c){if(B)b.preventDefault();else if(a(b.target).get(0).clientHeight==0||a(b.target).get(0).scrollHeight===a(b.target).get(0).clientHeight){b.preventDefault();a.fancybox[c>0?"prev":"next"]()}});a.support.opacity||e.addClass("fancybox-ie");if(D){c.addClass("fancybox-ie6");e.addClass("fancybox-ie6");a('<iframe id="fancybox-hide-sel-frame" src="'+(/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank")+'" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(f)}};a.fn.fancybox.defaults={padding:20,margin:40,opacity:!1,modal:!1,cyclic:!1,scrolling:"auto",width:560,height:340,autoScale:!0,autoDimensions:!0,centerOnScroll:!1,ajax:{},swf:{wmode:"transparent"},hideOnOverlayClick:!0,hideOnContentClick:!1,overlayShow:!0,overlayOpacity:.7,overlayColor:"#000",titleShow:!0,titlePosition:"float",titleFormat:null,titleFromAlt:!1,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing",easingOut:"swing",showCloseButton:!0,showNavArrows:!0,enableEscapeButton:!0,enableKeyboardNav:!0,onStart:function(){},onCancel:function(){},onComplete:function(){},onCleanup:function(){},onClosed:function(){},onError:function(){}};a(document).ready(function(){a.fancybox.init()})})(jQuery);jQuery(function(){jQuery("#review_form_wrapper").hide();jQuery("a.zoom, a.show_review_form").fancybox({transitionIn:"elastic",transitionOut:"elastic",speedIn:600,speedOut:200,overlayShow:!0})});