mirror of
https://github.com/blasten/turn.js.git
synced 2025-04-05 19:41:54 +08:00
47 lines
23 KiB
JavaScript
47 lines
23 KiB
JavaScript
/* turn.js | turnjs.com | (c) 2012 Emmanuel Garcia | MIT Licensed */
|
|
(function(i){var x,y="",G=Math.PI,E=G/2,w="Touch"in window,I=w?{start:"touchstart",move:"touchmove",end:"touchend"}:{start:"mousedown",move:"mousemove",end:"mouseup"},N={backward:["bl","tl"],forward:["br","tr"],all:["tl","bl","tr","br"]},O=["single","double"],P={page:1,gradients:!0,duration:600,acceleration:!0,display:"double",when:null},Q={folding:null,corners:"forward",cornerSize:100,gradients:!0,duration:600,acceleration:!0},J={"0":{top:0,left:0,right:"auto",bottom:"auto"},1:{top:0,right:0,left:"auto",
|
|
bottom:"auto"}},m=function(a,b,c,d){return{css:{position:"absolute",top:a,left:b,overflow:d||"hidden","z-index":c||"auto"}}},K=function(a,b,c,d,e){var f=1-e,C=f*f*f,h=e*e*e;return j(Math.round(C*a.x+3*e*f*f*b.x+3*e*e*f*c.x+h*d.x),Math.round(C*a.y+3*e*f*f*b.y+3*e*e*f*c.y+h*d.y))},j=function(a,b){return{x:a,y:b}},r=function(a,b,c){return x&&c?" translate3d("+a+"px,"+b+"px, 0px) ":" translate("+a+"px, "+b+"px) "},s=function(a){return" rotate("+a+"deg) "},p=function(a,b){return Object.prototype.hasOwnProperty.call(b,
|
|
a)},R=function(){for(var a=["Moz","Webkit","Khtml","O","ms"],b=document.body.style,c=a.length,d="";c--;)a[c]+"Transform"in b&&(d="-"+a[c].toLowerCase()+"-");return d},L=function(a,b,c,d,e){var f,C=[];if("-webkit-"==y){for(f=0;f<e;f++)C.push("color-stop("+d[f][0]+", "+d[f][1]+")");a.css({"background-image":"-webkit-gradient(linear, "+b.x+"% "+b.y+"%, "+c.x+"% "+c.y+"%, "+C.join(",")+" )"})}else{var h=c.x-b.x;f=c.y-b.y;var i=Math.atan2(f,h),g=i-Math.PI/2,g=Math.abs(100*Math.sin(g))+Math.abs(100*Math.cos(g)),
|
|
h=Math.sqrt(f*f+h*h),c=j(c.x<b.x?100:0,c.y<b.y?100:0),n=Math.tan(i);f=-1/n;n=(f*c.x-c.y-n*b.x+b.y)/(f-n);c=f*n-f*c.x+c.y;b=1*Math.sqrt(Math.pow(n-b.x,2)+Math.pow(c-b.y,2));for(f=0;f<e;f++)C.push(" "+d[f][1]+" "+Math.round(100*(b+h*d[f][0])/g)+"%");a.css({"background-image":y+"linear-gradient("+-i+"rad,"+C.join(",")+")"})}},g={init:function(a){void 0===x&&(x="WebKitCSSMatrix"in window||"MozPerspective"in document.body.style,y=R());var b,c=this.data(),d=this.children(),a=i.extend({width:this.width(),
|
|
height:this.height()},P,a);c.opts=a;c.pageObjs={};c.pages={};c.pageWrap={};c.pagePlace={};c.pageMv=[];c.totalPages=a.pages||0;if(a.when)for(b in a.when)p(b,a.when)&&this.bind(b,a.when[b]);this.css({position:"relative",width:a.width,height:a.height});this.turn("display",a.display);x&&!w&&a.acceleration&&this.transform(r(0,0,!0));for(b=0;b<d.length;b++)this.turn("addPage",d[b],b+1);this.turn("page",a.page);i(this).bind(I.start,function(a){for(var b in c.pages)if(p(b,c.pages)&&!1===h._eventStart.call(c.pages[b],
|
|
a))return!1});i(document).bind(I.move,function(a){for(var b in c.pages)p(b,c.pages)&&h._eventMove.call(c.pages[b],a)}).bind(I.end,function(a){for(var b in c.pages)p(b,c.pages)&&h._eventEnd.call(c.pages[b],a)});c.done=!0;return this},addPage:function(a,b){var c=!1,d=this.data(),e=d.totalPages+1;if(b)if(b==e)b=e,c=!0;else{if(b>e)throw Error('It is impossible to add the page "'+b+'", the maximum value is: "'+e+'"');}else b=e,c=!0;1<=b&&b<=e&&(d.done&&this.turn("stop"),g._movePages.call(this,b,1),c&&
|
|
(d.totalPages=e),d.pageObjs[b]=i(a).addClass("turn-page p"+b),g._addPage.call(this,b),d.done&&this.turn("update"),g._removeFromDOM.call(this));return this},_addPage:function(a){var b=this.data(),c=b.pageObjs[a];if(c)if(g._necessPage.call(this,a)){if(!b.pageWrap[a]){var d="double"==b.display?this.width()/2:this.width(),e=this.height();c.css({width:d,height:e});b.pagePlace[a]=a;b.pageWrap[a]=i("<div/>",{"class":"turn-page-wrapper",page:a,css:{position:"absolute",overflow:"hidden",width:d,height:e}}).css(J["double"==
|
|
b.display?a%2:0]);this.append(b.pageWrap[a]);b.pageWrap[a].prepend(b.pageObjs[a])}(!a||1==g._setPageLoc.call(this,a))&&g._makeFlip.call(this,a)}else b.pagePlace[a]=0,b.pageObjs[a]&&b.pageObjs[a].remove()},hasPage:function(a){return!!this.data().pageObjs[a]},_makeFlip:function(a){var b=this.data();if(!b.pages[a]&&b.pagePlace[a]==a){var c="single"==b.display,d=a%2;b.pages[a]=b.pageObjs[a].css({width:c?this.width():this.width()/2,height:this.height()}).flip({page:a,next:d||c?a+1:a-1,turn:this,duration:b.opts.duration,
|
|
acceleration:b.opts.acceleration,corners:c?"all":d?"forward":"backward",backGradient:b.opts.gradients,frontGradient:b.opts.gradients}).flip("disable",b.disabled).bind("pressed",g._pressed).bind("released",g._released).bind("start",g._start).bind("end",g._end).bind("flip",g._flip)}return b.pages[a]},_makeRange:function(){var a;this.data();var b=this.turn("range");for(a=b[0];a<=b[1];a++)g._addPage.call(this,a)},range:function(a){var b,c,d=this.data(),a=a||d.tpage||d.page,e=g._view.call(this,a);if(1>
|
|
a||a>d.totalPages)throw Error('"'+a+'" is not a page for range');e[1]=e[1]||e[0];1<=e[0]&&e[1]<=d.totalPages?(a=Math.floor(2),d.totalPages-e[1]>e[0]?(b=Math.min(e[0]-1,a),c=2*a-b):(c=Math.min(d.totalPages-e[1],a),b=2*a-c)):c=b=5;return[Math.max(1,e[0]-b),Math.min(d.totalPages,e[1]+c)]},_necessPage:function(a){if(0===a)return!0;var b=this.turn("range");return a>=b[0]&&a<=b[1]},_removeFromDOM:function(){var a,b=this.data();for(a in b.pageWrap)p(a,b.pageWrap)&&!g._necessPage.call(this,a)&&g._removePageFromDOM.call(this,
|
|
a)},_removePageFromDOM:function(a){var b=this.data();if(b.pages[a]){var c=b.pages[a].data();c.f&&c.f.fwrapper&&c.f.fwrapper.remove();b.pages[a].remove();delete b.pages[a]}b.pageObjs[a]&&b.pageObjs[a].remove();b.pageWrap[a]&&(b.pageWrap[a].remove(),delete b.pageWrap[a]);delete b.pagePlace[a]},removePage:function(a){var b=this.data();b.pageObjs[a]&&(this.turn("stop"),g._removePageFromDOM.call(this,a),delete b.pageObjs[a],g._movePages.call(this,a,-1),b.totalPages-=1,g._makeRange.call(this),b.page>b.totalPages&&
|
|
this.turn("page",b.totalPages));return this},_movePages:function(a,b){var c,d=this.data(),e="single"==d.display,f=function(a){var c=a+b,f=c%2;d.pageObjs[a]&&(d.pageObjs[c]=d.pageObjs[a].removeClass("page"+a).addClass("page"+c));d.pagePlace[a]&&d.pageWrap[a]&&(d.pagePlace[c]=c,d.pageWrap[c]=d.pageWrap[a].css(J[e?0:f]).attr("page",c),d.pages[a]&&(d.pages[c]=d.pages[a].flip("options",{page:c,next:e||f?c+1:c-1,corners:e?"all":f?"forward":"backward"})),b&&(delete d.pages[a],delete d.pagePlace[a],delete d.pageObjs[a],
|
|
delete d.pageWrap[a],delete d.pageObjs[a]))};if(0<b)for(c=d.totalPages;c>=a;c--)f(c);else for(c=a;c<=d.totalPages;c++)f(c)},display:function(a){var b=this.data(),c=b.display;if(a){if(-1==i.inArray(a,O))throw Error('"'+a+'" is not a value for display');"single"==a?b.pageObjs[0]||(this.turn("stop").css({overflow:"hidden"}),b.pageObjs[0]=i("<div />",{"class":"turn-page p-temporal"}).css({width:this.width(),height:this.height()}).appendTo(this)):b.pageObjs[0]&&(this.turn("stop").css({overflow:""}),b.pageObjs[0].remove(),
|
|
delete b.pageObjs[0]);b.display=a;c&&(a=this.turn("size"),g._movePages.call(this,1,0),this.turn("size",a.width,a.height).turn("update"));return this}return c},animating:function(){return 0<this.data().pageMv.length},disable:function(a){var b,c=this.data(),d=this.turn("view"),a="undefined"==typeof a||!0===a;c.disabled=a;for(b in c.pages)p(b,c.pages)&&c.pages[b].flip("disable",a?i.inArray(b,d):!1);return this},size:function(a,b){if(a&&b){var c=this.data(),d="double"==c.display?a/2:a,e;this.css({width:a,
|
|
height:b});c.pageObjs[0]&&c.pageObjs[0].css({width:d,height:b});for(e in c.pageWrap)p(e,c.pageWrap)&&(c.pageWrap[e].css({width:d,height:b}),c.pages[e]&&c.pages[e].css({width:d,height:b}));this.turn("resize");return this}return{width:this.width(),height:this.height()}},resize:function(){var a,b=this.data();b.pages[0]&&(b.pageWrap[0].css({left:-this.width()}),b.pages[0].flip("resize",!0));for(a=1;a<=b.totalPages;a++)b.pages[a]&&b.pages[a].flip("resize",!0)},_removeMv:function(a){var b,c=this.data();
|
|
for(b=0;b<c.pageMv.length;b++)if(c.pageMv[b]==a)return c.pageMv.splice(b,1),!0;return!1},_addMv:function(a){var b=this.data();g._removeMv.call(this,a);b.pageMv.push(a)},_view:function(a){var b=this.data(),a=a||b.page;return"double"==b.display?a%2?[a-1,a]:[a,a+1]:[a]},view:function(a){var b=this.data(),a=g._view.call(this,a);return"double"==b.display?[0<a[0]?a[0]:0,a[1]<=b.totalPages?a[1]:0]:[0<a[0]&&a[0]<=b.totalPages?a[0]:0]},stop:function(){var a,b,c=this.data(),d=c.pageMv;c.pageMv=[];c.tpage&&
|
|
(c.page=c.tpage,delete c.tpage);for(a in d)p(a,d)&&(b=c.pages[d[a]].data().f.opts,h._moveFoldingPage.call(c.pages[d[a]],null),c.pages[d[a]].flip("hideFoldedPage"),c.pagePlace[b.next]=b.next,b.force&&(b.next=0===b.page%2?b.page-1:b.page+1,delete b.force));this.turn("update");return this},pages:function(a){var b=this.data();if(a){if(a<b.totalPages){for(var c=a+1;c<=b.totalPages;c++)this.turn("removePage",c);this.turn("page")>a&&this.turn("page",a)}b.totalPages=a;return this}return b.totalPages},_fitPage:function(a,
|
|
b){var c=this.data(),d=this.turn("view",a);c.page!=a&&(this.trigger("turning",[a,d]),-1!=i.inArray(1,d)&&this.trigger("first"),-1!=i.inArray(c.totalPages,d)&&this.trigger("last"));c.pageObjs[a]&&(c.tpage=a,this.turn("stop",b),g._removeFromDOM.call(this),g._makeRange.call(this),this.trigger("turned",[a,d]))},_turnPage:function(a){var b,c,d=this.data(),e=this.turn("view"),f=this.turn("view",a);d.page!=a&&(this.trigger("turning",[a,f]),-1!=i.inArray(1,f)&&this.trigger("first"),-1!=i.inArray(d.totalPages,
|
|
f)&&this.trigger("last"));d.pageObjs[a]&&(d.tpage=a,this.turn("stop"),g._makeRange.call(this),"single"==d.display?(b=e[0],c=f[0]):e[1]&&a>e[1]?(b=e[1],c=f[0]):e[0]&&a<e[0]&&(b=e[0],c=f[1]),d.pages[b]&&(a=d.pages[b].data().f.opts,d.tpage=c,a.next!=c&&(a.next=c,d.pagePlace[c]=a.page,a.force=!0),"single"==d.display?d.pages[b].flip("turnPage",f[0]>e[0]?"br":"bl"):d.pages[b].flip("turnPage")))},page:function(a){var a=parseInt(a,10),b=this.data();return 0<a&&a<=b.totalPages?(!b.done||-1!=i.inArray(a,this.turn("view"))?
|
|
g._fitPage.call(this,a):g._turnPage.call(this,a),this):b.page},next:function(){var a=this.data();return this.turn("page",g._view.call(this,a.tpage||a.page).pop()+1)},previous:function(){var a=this.data();return this.turn("page",g._view.call(this,a.tpage||a.page).shift()-1)},_addMotionPage:function(){var a=i(this).data().f.opts,b=a.turn,c=b.data();a.pageMv=a.page;g._addMv.call(b,a.pageMv);c.pagePlace[a.next]=a.page;b.turn("update")},_start:function(a,b,c){var d=b.turn.data(),e=i.Event("start");a.stopPropagation();
|
|
b.turn.trigger(e,[b,c]);e.isDefaultPrevented()?a.preventDefault():("single"==d.display&&(c="l"==c.charAt(1),1==b.page&&c||b.page==d.pages&&!c?a.preventDefault():c?(b.next=b.next<b.page?b.next:b.page-1,b.force=!0):b.next=b.next>b.page?b.next:b.page+1),g._addMotionPage.call(this))},_end:function(a,b){var c=i(this).data().f.opts,d=c.turn,e=d.data();a.stopPropagation();if(b||e.tpage){if(e.tpage==c.next||e.tpage==c.page)delete e.tpage,g._fitPage.call(d,e.tpage||c.next,!0)}else g._removeMv.call(d,c.pageMv),
|
|
d.turn("update")},_pressed:function(){var a,b=i(this).data().f,c=b.opts.turn.data().pages;for(a in c)a!=b.opts.page&&c[a].flip("disable",!0);return b.time=(new Date).getTime()},_released:function(a,b){var c=i(this),d=c.data().f;a.stopPropagation();if(200>(new Date).getTime()-d.time||0>b.x||b.x>i(this).width())a.preventDefault(),d.opts.turn.data().tpage=d.opts.next,d.opts.turn.turn("update"),i(c).flip("turnPage")},_flip:function(){var a=i(this).data().f.opts;a.turn.trigger("turn",[a.next])},calculateZ:function(a){var b,
|
|
c,d,e,f=this,h=this.data();b=this.turn("view");var i=b[0]||b[1],g={pageZ:{},partZ:{},pageV:{}},j=function(a){a=f.turn("view",a);a[0]&&(g.pageV[a[0]]=!0);a[1]&&(g.pageV[a[1]]=!0)};for(b=0;b<a.length;b++)c=a[b],d=h.pages[c].data().f.opts.next,e=h.pagePlace[c],j(c),j(d),c=h.pagePlace[d]==d?d:c,g.pageZ[c]=h.totalPages-Math.abs(i-c),g.partZ[e]=2*h.totalPages+Math.abs(i-c);return g},update:function(){var a,b=this.data();if(b.pageMv.length&&0!==b.pageMv[0]){var c=this.turn("calculateZ",b.pageMv);this.turn("view",
|
|
b.tpage);for(a in b.pageWrap)p(a,b.pageWrap)&&(b.pageWrap[a].css({display:c.pageV[a]?"":"none","z-index":c.pageZ[a]||0}),b.pages[a]&&(b.pages[a].flip("z",c.partZ[a]||null),c.pageV[a]&&b.pages[a].flip("resize"),b.tpage&&b.pages[a].flip("disable",!0)))}else for(a in b.pageWrap)p(a,b.pageWrap)&&(c=g._setPageLoc.call(this,a),b.pages[a]&&b.pages[a].flip("disable",b.disabled||1!=c).flip("z",null))},_setPageLoc:function(a){var b=this.data(),c=this.turn("view");if(a==c[0]||a==c[1])return b.pageWrap[a].css({"z-index":b.totalPages,
|
|
display:""}),1;if("single"==b.display&&a==c[0]+1||"double"==b.display&&a==c[0]-2||a==c[1]+2)return b.pageWrap[a].css({"z-index":b.totalPages-1,display:""}),2;b.pageWrap[a].css({"z-index":0,display:"none"});return 0}},h={init:function(a){a.gradients&&(a.frontGradient=!0,a.backGradient=!0);this.data({f:{}});this.flip("options",a);h._addPageWrapper.call(this);return this},setData:function(a){var b=this.data();b.f=i.extend(b.f,a);return this},options:function(a){var b=this.data().f;return a?(h.setData.call(this,
|
|
{opts:i.extend({},b.opts||Q,a)}),this):b.opts},z:function(a){var b=this.data().f;b.opts["z-index"]=a;b.fwrapper.css({"z-index":a||parseInt(b.parent.css("z-index"),10)||0});return this},_cAllowed:function(){return N[this.data().f.opts.corners]||this.data().f.opts.corners},_cornerActivated:function(a){var a=w?a.originalEvent.touches:[a],b=this.data().f,c=b.parent.offset(),d=this.width(),e=this.height(),a={x:Math.max(0,a[0].pageX-c.left),y:Math.max(0,a[0].pageY-c.top)},b=b.opts.cornerSize,c=h._cAllowed.call(this);
|
|
if(0>=a.x||0>=a.y||a.x>=d||a.y>=e)return!1;if(a.y<b)a.corner="t";else if(a.y>=e-b)a.corner="b";else return!1;if(a.x<=b)a.corner+="l";else if(a.x>=d-b)a.corner+="r";else return!1;return-1==i.inArray(a.corner,c)?!1:a},_c:function(a,b){b=b||0;return{tl:j(b,b),tr:j(this.width()-b,b),bl:j(b,this.height()-b),br:j(this.width()-b,this.height()-b)}[a]},_c2:function(a){return{tl:j(2*this.width(),0),tr:j(-this.width(),0),bl:j(2*this.width(),this.height()),br:j(-this.width(),this.height())}[a]},_foldingPage:function(){var a=
|
|
this.data().f.opts;if(a.folding)return a.folding;if(a.turn){var b=a.turn.data();return"single"==b.display?b.pageObjs[a.next]?b.pageObjs[0]:null:b.pageObjs[a.next]}},_backGradient:function(){var a=this.data().f,b=a.opts.turn;if((b=a.opts.backGradient&&(!b||"single"==b.data().display||2!=a.opts.page&&a.opts.page!=b.data().totalPages-1))&&!a.bshadow)a.bshadow=i("<div/>",m(0,0,1)).css({position:"",width:this.width(),height:this.height()}).appendTo(a.parent);return b},resize:function(a){var b=this.data().f,
|
|
c=this.width(),d=this.height(),e=Math.round(Math.sqrt(Math.pow(c,2)+Math.pow(d,2)));a&&(b.wrapper.css({width:e,height:e}),b.fwrapper.css({width:e,height:e}).children(":first-child").css({width:c,height:d}),b.fpage.css({width:d,height:c}),b.opts.frontGradient&&b.ashadow.css({width:d,height:c}),h._backGradient.call(this)&&b.bshadow.css({width:c,height:d}));b.parent.is(":visible")&&(b.fwrapper.css({top:b.parent.offset().top,left:b.parent.offset().left}),b.opts.turn&&b.fparent.css({top:-b.opts.turn.offset().top,
|
|
left:-b.opts.turn.offset().left}));this.flip("z",b.opts["z-index"])},_addPageWrapper:function(){var a=this.data().f,b=this.parent();if(!a.wrapper){this.css("left");this.css("top");var c=this.width(),d=this.height();Math.round(Math.sqrt(Math.pow(c,2)+Math.pow(d,2)));a.parent=b;a.fparent=a.opts.turn?a.opts.turn.data().fparent:i("#turn-fwrappers");a.fparent||(c=i("<div/>",{css:{"pointer-events":"none"}}).hide(),c.data().flips=0,a.opts.turn?(c.css(m(-a.opts.turn.offset().top,-a.opts.turn.offset().left,
|
|
"auto","visible").css).appendTo(a.opts.turn),a.opts.turn.data().fparent=c):c.css(m(0,0,"auto","visible").css).attr("id","turn-fwrappers").appendTo(i("body")),a.fparent=c);this.css({position:"absolute",top:0,left:0,bottom:"auto",right:"auto"});a.wrapper=i("<div/>",m(0,0,this.css("z-index"))).appendTo(b).prepend(this);a.fwrapper=i("<div/>",m(b.offset().top,b.offset().left)).hide().appendTo(a.fparent);a.fpage=i("<div/>",{css:{cursor:"default"}}).appendTo(i("<div/>",m(0,0,0,"visible")).appendTo(a.fwrapper));
|
|
a.opts.frontGradient&&(a.ashadow=i("<div/>",m(0,0,1)).appendTo(a.fpage));h.setData.call(this,a);h.resize.call(this,!0)}},_fold:function(a){var b=this,c=0,d=0,e,f,i,g,u,H,n=j(0,0),p=j(0,0),k=j(0,0),q=this.width(),t=this.height(),m=h._foldingPage.call(this);Math.tan(d);var o=this.data().f,v=o.opts.acceleration,y=o.wrapper.height(),w=h._c.call(this,a.corner),D="t"==a.corner.substr(0,1),A="l"==a.corner.substr(1,1),F=function(){var l=j(w.x?w.x-a.x:a.x,w.y?w.y-a.y:a.y),B=Math.atan2(l.y,l.x),z;d=E-B;c=180*
|
|
(d/G);z=j(A?q-l.x/2:a.x+l.x/2,l.y/2);var m=d-Math.atan2(z.y,z.x),m=Math.max(0,Math.sin(m)*Math.sqrt(Math.pow(z.x,2)+Math.pow(z.y,2)));k=j(m*Math.sin(d),m*Math.cos(d));if(d>E&&(k.x+=Math.abs(k.y*Math.tan(B)),k.y=0,Math.round(k.x*Math.tan(G-d))<t))return a.y=Math.sqrt(Math.pow(t,2)+2*z.x*l.x),D&&(a.y=t-a.y),F();d>E&&(l=G-d,B=y-t/Math.sin(l),n=j(Math.round(B*Math.cos(l)),Math.round(B*Math.sin(l))),A&&(n.x=-n.x),D&&(n.y=-n.y));e=Math.round(k.y/Math.tan(d)+k.x);l=q-e;B=l*Math.cos(2*d);z=l*Math.sin(2*d);
|
|
p=j(Math.round(A?l-B:e+B),Math.round(D?z:t-z));u=l*Math.sin(d);l=h._c2.call(b,a.corner);l=Math.sqrt(Math.pow(l.x-a.x,2)+Math.pow(l.y-a.y,2));H=l<q?l/q:1;o.opts.frontGradient&&(g=100<u?(u-100)/u:0,f=j(100*(u*Math.sin(E-d)/t),100*(u*Math.cos(E-d)/q)),D&&(f.y=100-f.y),A&&(f.x=100-f.x));h._backGradient.call(b)&&(i=j(100*(u*Math.sin(d)/q),100*(u*Math.cos(d)/t)),A||(i.x=100-i.x),D||(i.y=100-i.y));k.x=Math.round(k.x);k.y=Math.round(k.y);return!0},x=function(a,c,d,e){var k=["0","auto"],m=(q-y)*d[0]/100,u=
|
|
(t-y)*d[1]/100,c={left:k[c[0]],top:k[c[1]],right:k[c[2]],bottom:k[c[3]]},k=90!=e&&-90!=e?A?-1:1:0,d=d[0]+"% "+d[1]+"%";b.css(c).transform(s(e)+r(a.x+k,a.y,v),d);o.fpage.parent().css(c);o.wrapper.transform(r(-a.x+m-k,-a.y+u,v)+s(-e),d);o.fwrapper.transform(r(-a.x+n.x+m,-a.y+n.y+u,v)+s(-e),d);o.fpage.parent().transform(s(e)+r(a.x+p.x-n.x,a.y+p.y-n.y,v),d);o.opts.frontGradient&&L(o.ashadow,j(A?100:0,D?100:0),j(f.x,f.y),[[g,"rgba(0,0,0,0)"],[0.8*(1-g)+g,"rgba(0,0,0,"+0.2*H+")"],[1,"rgba(255,255,255,"+
|
|
0.2*H+")"]],3);h._backGradient.call(b)&&L(o.bshadow,j(A?0:100,D?0:100),j(i.x,i.y),[[0.8,"rgba(0,0,0,0)"],[1,"rgba(0,0,0,"+0.3*H+")"],[1,"rgba(0,0,0,0)"]],3)};switch(a.corner){case "tl":a.x=Math.max(a.x,1);F();x(k,[1,0,0,1],[100,0],c);o.fpage.transform(r(-t,-q,v)+s(90-2*c),"100% 100%");m.transform(s(90)+r(0,-t,v),"0% 0%");break;case "tr":a.x=Math.min(a.x,q-1);F();x(j(-k.x,k.y),[0,0,0,1],[0,0],-c);o.fpage.transform(r(0,-q,v)+s(-90+2*c),"0% 100%");m.transform(s(270)+r(-q,0,v),"0% 0%");break;case "bl":a.x=
|
|
Math.max(a.x,1);F();x(j(k.x,-k.y),[1,1,0,0],[100,100],-c);o.fpage.transform(r(-t,0,v)+s(-90+2*c),"100% 0%");m.transform(s(270)+r(-q,0,v),"0% 0%");break;case "br":a.x=Math.min(a.x,q-1),F(),x(j(-k.x,-k.y),[0,1,1,0],[0,100],c),o.fpage.transform(s(90-2*c),"0% 0%"),m.transform(s(90)+r(0,-t,v),"0% 0%")}o.point=a},_moveFoldingPage:function(a){var b=this.data().f,c=h._foldingPage.call(this);if(c)if(a){if(!b.fpage.children()[b.ashadow?"1":"0"])h.setData.call(this,{backParent:c.parent()}),b.fpage.prepend(c)}else b.backParent&&
|
|
b.backParent.prepend(c)},_showFoldedPage:function(a,b){var c=h._foldingPage.call(this),d=this.data(),e=d.f;if(!e.point||e.point.corner!=a.corner){var f=i.Event("start");this.trigger(f,[e.opts,a.corner]);if(f.isDefaultPrevented())return!1}if(c){if(b){var g=this,c=e.point&&e.point.corner==a.corner?e.point:h._c.call(this,a.corner,1);this.animatef({from:[c.x,c.y],to:[a.x,a.y],duration:500,frame:function(b){a.x=Math.round(b[0]);a.y=Math.round(b[1]);h._fold.call(g,a)}})}else h._fold.call(this,a),d.effect&&
|
|
!d.effect.turning&&this.animatef(!1);e.fwrapper.is(":visible")||(e.fparent.show().data().flips++,h._moveFoldingPage.call(this,!0),e.fwrapper.show(),e.bshadow&&e.bshadow.show());return!0}return!1},hide:function(){var a=this.data().f,b=h._foldingPage.call(this);0===--a.fparent.data().flips&&a.fparent.hide();this.css({left:0,top:0,right:"auto",bottom:"auto"}).transform("","0% 100%");a.wrapper.transform("","0% 100%");a.fwrapper.hide();a.bshadow&&a.bshadow.hide();b.transform("","0% 0%");return this},hideFoldedPage:function(a){var b=
|
|
this.data().f;if(b.point){var c=this,d=b.point,e=function(){b.point=null;c.flip("hide");c.trigger("end",[!1])};if(a){var f=h._c.call(this,d.corner),a="t"==d.corner.substr(0,1)?Math.min(0,d.y-f.y)/2:Math.max(0,d.y-f.y)/2,i=j(d.x,d.y+a),g=j(f.x,f.y-a);this.animatef({from:0,to:1,frame:function(a){a=K(d,i,g,f,a);d.x=a.x;d.y=a.y;h._fold.call(c,d)},complete:e,duration:800,hiding:!0})}else this.animatef(!1),e()}},turnPage:function(a){var b=this,c=this.data().f,a={corner:c.corner?c.corner.corner:a||h._cAllowed.call(this)[0]},
|
|
d=c.point||h._c.call(this,a.corner,c.opts.turn?c.opts.turn.data().opts.elevation:0),e=h._c2.call(this,a.corner);this.trigger("flip").animatef({from:0,to:1,frame:function(c){c=K(d,d,e,e,c);a.x=c.x;a.y=c.y;h._showFoldedPage.call(b,a)},complete:function(){b.trigger("end",[!0])},duration:c.opts.duration,turning:!0});c.corner=null},moving:function(){return"effect"in this.data()},isTurning:function(){return this.flip("moving")&&this.data().effect.turning},_eventStart:function(a){var b=this.data().f;if(!b.disabled&&
|
|
!this.flip("isTurning")){b.corner=h._cornerActivated.call(this,a);if(b.corner&&h._foldingPage.call(this,b.corner))return h._moveFoldingPage.call(this,!0),this.trigger("pressed",[b.point]),!1;b.corner=null}},_eventMove:function(a){var b=this.data().f;if(!b.disabled)if(a=w?a.originalEvent.touches:[a],b.corner){var c=b.parent.offset();b.corner.x=a[0].pageX-c.left;b.corner.y=a[0].pageY-c.top;h._showFoldedPage.call(this,b.corner)}else!this.data().effect&&this.is(":visible")&&((a=h._cornerActivated.call(this,
|
|
a[0]))?(b=h._c.call(this,a.corner,b.opts.cornerSize/2),a.x=b.x,a.y=b.y,h._showFoldedPage.call(this,a,!0)):h.hideFoldedPage.call(this,!0))},_eventEnd:function(){var a=this.data().f;if(!a.disabled&&a.point){var b=i.Event("released");this.trigger(b,[a.point]);b.isDefaultPrevented()||h.hideFoldedPage.call(this,!0)}a.corner=null},disable:function(a){h.setData.call(this,{disabled:a});return this}},M=function(a,b,c){if(!c[0]||"object"==typeof c[0])return b.init.apply(a,c);if(b[c[0]]&&"_"!=c[0].toString().substr(0,
|
|
1))return b[c[0]].apply(a,Array.prototype.slice.call(c,1));throw c[0]+" is an invalid value";};i.extend(i.fn,{flip:function(a,b){return M(this,h,arguments)},turn:function(a){return M(this,g,arguments)},transform:function(a,b){var c={};b&&(c[y+"transform-origin"]=b);c[y+"transform"]=a;return this.css(c)},animatef:function(a){var b=this.data();b.effect&&clearInterval(b.effect.handle);if(a){a.to.length||(a.to=[a.to]);a.from.length||(a.from=[a.from]);a.easing||(a.easing=function(a,b,c,d,e){return d*Math.sqrt(1-
|
|
(b=b/e-1)*b)+c});var c,d=[],e=a.to.length,f=this,i=a.fps||30,h=-i,g=function(){var c,g=[];h=Math.min(a.duration,h+i);for(c=0;c<e;c++)g.push(a.easing(1,h,a.from[c],d[c],a.duration));a.frame(1==e?g[0]:g);h==a.duration&&(clearInterval(b.effect.handle),delete b.effect,f.data(b),a.complete&&a.complete())};for(c=0;c<e;c++)d.push(a.to[c]-a.from[c]);b.effect=a;b.effect.handle=setInterval(g,i);this.data(b);g()}else delete b.effect}});i.isTouch=w})(jQuery);
|