diff --git a/src/static/js/basic.js b/src/static/js/basic.js deleted file mode 100644 index 12a3690..0000000 --- a/src/static/js/basic.js +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Basic sample -*/ - -function addPage(page, book) { - - var id, pages = book.turn('pages'); - - // Create a new element for this page - var element = $('
', {}); - - // Add the page to the flipbook - if (book.turn('addPage', element, page)) { - - // Add the initial HTML - // It will contain a loader indicator and a gradient - element.html('
'); - - // Load the page - loadPage(page, element); - } - -} - -function loadPage(page, pageElement) { - - // Create an image element - - var img = $(''); - - img.mousedown(function(e) { - e.preventDefault(); - }); - - img.load(function() { - - // Set the size - $(this).css({width: '100%', height: '100%'}); - - // Add the image to the page after loaded - - $(this).appendTo(pageElement); - - // Remove the loader indicator - - pageElement.find('.loader').remove(); - }); - - // Load the page - - img.attr('src', 'pages/' + page + '.jpg'); - -} - - -function loadLargePage(page, pageElement) { - - var img = $(''); - - img.load(function() { - - var prevImg = pageElement.find('img'); - $(this).css({width: '100%', height: '100%'}); - $(this).appendTo(pageElement); - prevImg.remove(); - - }); - - // Loadnew page - - img.attr('src', 'pages/' + page + '-large.jpg'); -} - - -function loadSmallPage(page, pageElement) { - - var img = pageElement.find('img'); - - img.css({width: '100%', height: '100%'}); - - img.unbind('load'); - // Loadnew page - - img.attr('src', 'pages/' + page + '.jpg'); -} - - - -// http://code.google.com/p/chromium/issues/detail?id=128488 -function isChrome() { - - return navigator.userAgent.indexOf('Chrome')!=-1; - -} \ No newline at end of file diff --git a/src/static/js/modernizr.2.5.3.min.js b/src/static/js/modernizr.2.5.3.min.js deleted file mode 100644 index 6716720..0000000 --- a/src/static/js/modernizr.2.5.3.min.js +++ /dev/null @@ -1,4 +0,0 @@ -/* Modernizr 2.5.3 (Custom Build) | MIT & BSD - * Build: http://www.modernizr.com/download/#-csstransforms-csstransforms3d-shiv-cssclasses-teststyles-testprop-testallprops-prefixes-domprefixes-load - */ -;window.Modernizr=function(a,b,c){function z(a){j.cssText=a}function A(a,b){return z(m.join(a+";")+(b||""))}function B(a,b){return typeof a===b}function C(a,b){return!!~(""+a).indexOf(b)}function D(a,b){for(var d in a)if(j[a[d]]!==c)return b=="pfx"?a[d]:!0;return!1}function E(a,b,d){for(var e in a){var f=b[a[e]];if(f!==c)return d===!1?a[e]:B(f,"function")?f.bind(d||b):f}return!1}function F(a,b,c){var d=a.charAt(0).toUpperCase()+a.substr(1),e=(a+" "+o.join(d+" ")+d).split(" ");return B(b,"string")||B(b,"undefined")?D(e,b):(e=(a+" "+p.join(d+" ")+d).split(" "),E(e,b,c))}var d="2.5.3",e={},f=!0,g=b.documentElement,h="modernizr",i=b.createElement(h),j=i.style,k,l={}.toString,m=" -webkit- -moz- -o- -ms- ".split(" "),n="Webkit Moz O ms",o=n.split(" "),p=n.toLowerCase().split(" "),q={},r={},s={},t=[],u=t.slice,v,w=function(a,c,d,e){var f,i,j,k=b.createElement("div"),l=b.body,m=l?l:b.createElement("body");if(parseInt(d,10))while(d--)j=b.createElement("div"),j.id=e?e[d]:h+(d+1),k.appendChild(j);return f=["­",""].join(""),k.id=h,(l?k:m).innerHTML+=f,m.appendChild(k),l||(m.style.background="",g.appendChild(m)),i=c(k,a),l?k.parentNode.removeChild(k):m.parentNode.removeChild(m),!!i},x={}.hasOwnProperty,y;!B(x,"undefined")&&!B(x.call,"undefined")?y=function(a,b){return x.call(a,b)}:y=function(a,b){return b in a&&B(a.constructor.prototype[b],"undefined")},Function.prototype.bind||(Function.prototype.bind=function(b){var c=this;if(typeof c!="function")throw new TypeError;var d=u.call(arguments,1),e=function(){if(this instanceof e){var a=function(){};a.prototype=c.prototype;var f=new a,g=c.apply(f,d.concat(u.call(arguments)));return Object(g)===g?g:f}return c.apply(b,d.concat(u.call(arguments)))};return e});var G=function(a,c){var d=a.join(""),f=c.length;w(d,function(a,c){var d=b.styleSheets[b.styleSheets.length-1],g=d?d.cssRules&&d.cssRules[0]?d.cssRules[0].cssText:d.cssText||"":"",h=a.childNodes,i={};while(f--)i[h[f].id]=h[f];e.csstransforms3d=(i.csstransforms3d&&i.csstransforms3d.offsetLeft)===9&&i.csstransforms3d.offsetHeight===3},f,c)}([,["@media (",m.join("transform-3d),("),h,")","{#csstransforms3d{left:9px;position:absolute;height:3px;}}"].join("")],[,"csstransforms3d"]);q.csstransforms=function(){return!!F("transform")},q.csstransforms3d=function(){var a=!!F("perspective");return a&&"webkitPerspective"in g.style&&(a=e.csstransforms3d),a};for(var H in q)y(q,H)&&(v=H.toLowerCase(),e[v]=q[H](),t.push((e[v]?"":"no-")+v));return z(""),i=k=null,function(a,b){function g(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function h(){var a=k.elements;return typeof a=="string"?a.split(" "):a}function i(a){var b={},c=a.createElement,e=a.createDocumentFragment,f=e();a.createElement=function(a){var e=(b[a]||(b[a]=c(a))).cloneNode();return k.shivMethods&&e.canHaveChildren&&!d.test(a)?f.appendChild(e):e},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+h().join().replace(/\w+/g,function(a){return b[a]=c(a),f.createElement(a),'c("'+a+'")'})+");return n}")(k,f)}function j(a){var b;return a.documentShived?a:(k.shivCSS&&!e&&(b=!!g(a,"article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block}audio{display:none}canvas,video{display:inline-block;*display:inline;*zoom:1}[hidden]{display:none}audio[controls]{display:inline-block;*display:inline;*zoom:1}mark{background:#FF0;color:#000}")),f||(b=!i(a)),b&&(a.documentShived=b),a)}var c=a.html5||{},d=/^<|^(?:button|form|map|select|textarea)$/i,e,f;(function(){var a=b.createElement("a");a.innerHTML="",e="hidden"in a,f=a.childNodes.length==1||function(){try{b.createElement("a")}catch(a){return!0}var c=b.createDocumentFragment();return typeof c.cloneNode=="undefined"||typeof c.createDocumentFragment=="undefined"||typeof c.createElement=="undefined"}()})();var k={elements:c.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video",shivCSS:c.shivCSS!==!1,shivMethods:c.shivMethods!==!1,type:"default",shivDocument:j};a.html5=k,j(b)}(this,b),e._version=d,e._prefixes=m,e._domPrefixes=p,e._cssomPrefixes=o,e.testProp=function(a){return D([a])},e.testAllProps=F,e.testStyles=w,g.className=g.className.replace(/(^|\s)no-js(\s|$)/,"$1$2")+(f?" js "+t.join(" "):""),e}(this,this.document),function(a,b,c){function d(a){return o.call(a)=="[object Function]"}function e(a){return typeof a=="string"}function f(){}function g(a){return!a||a=="loaded"||a=="complete"||a=="uninitialized"}function h(){var a=p.shift();q=1,a?a.t?m(function(){(a.t=="c"?B.injectCss:B.injectJs)(a.s,0,a.a,a.x,a.e,1)},0):(a(),h()):q=0}function i(a,c,d,e,f,i,j){function k(b){if(!o&&g(l.readyState)&&(u.r=o=1,!q&&h(),l.onload=l.onreadystatechange=null,b)){a!="img"&&m(function(){t.removeChild(l)},50);for(var d in y[c])y[c].hasOwnProperty(d)&&y[c][d].onload()}}var j=j||B.errorTimeout,l={},o=0,r=0,u={t:d,s:c,e:f,a:i,x:j};y[c]===1&&(r=1,y[c]=[],l=b.createElement(a)),a=="object"?l.data=c:(l.src=c,l.type=a),l.width=l.height="0",l.onerror=l.onload=l.onreadystatechange=function(){k.call(this,r)},p.splice(e,0,u),a!="img"&&(r||y[c]===2?(t.insertBefore(l,s?null:n),m(k,j)):y[c].push(l))}function j(a,b,c,d,f){return q=0,b=b||"j",e(a)?i(b=="c"?v:u,a,b,this.i++,c,d,f):(p.splice(this.i++,0,a),p.length==1&&h()),this}function k(){var a=B;return a.loader={load:j,i:0},a}var l=b.documentElement,m=a.setTimeout,n=b.getElementsByTagName("script")[0],o={}.toString,p=[],q=0,r="MozAppearance"in l.style,s=r&&!!b.createRange().compareNode,t=s?l:n.parentNode,l=a.opera&&o.call(a.opera)=="[object Opera]",l=!!b.attachEvent&&!l,u=r?"object":l?"script":"img",v=l?"script":u,w=Array.isArray||function(a){return o.call(a)=="[object Array]"},x=[],y={},z={timeout:function(a,b){return b.length&&(a.timeout=b[0]),a}},A,B;B=function(a){function b(a){var a=a.split("!"),b=x.length,c=a.pop(),d=a.length,c={url:c,origUrl:c,prefixes:a},e,f,g;for(f=0;fg)throw k('Page "'+ -b+'" cannot be inserted');}else b=g,d=!0;1<=b&&b<=g&&(c="double"==e.display?b%2?" odd":" even":"",e.done&&this.turn("stop"),b in e.pageObjs&&i._movePages.call(this,b,1),d&&(e.totalPages=g),e.pageObjs[b]=f(a).css({"float":"left"}).addClass("page p"+b+c),i._addPage.call(this,b),e.done&&this.turn("update"),i._removeFromDOM.call(this));return this},_addPage:function(a){var b=this.data(),c=b.pageObjs[a];if(c)if(i._necessPage.call(this,a)){if(!b.pageWrap[a]){var d=i._pageSize.call(this,a,!0);c.css({width:d.width, -height:d.height});b.pagePlace[a]=a;b.pageWrap[a]=f("
",{"class":"turn-page-wrapper",page:a,css:{position:"absolute",overflow:"hidden"}}).css(d);this.append(b.pageWrap[a]);b.pageWrap[a].prepend(b.pageObjs[a])}(!a||1==i._setPageLoc.call(this,a))&&i._makeFlip.call(this,a)}else b.pagePlace[a]=0,b.pageObjs[a]&&b.pageObjs[a].remove()},hasPage:function(a){return j(a,this.data().pageObjs)},center:function(a){var b=this.data(),c=f(this).turn("size"),d=c.width/(2*b.zoom)-c.width/2;"double"==b.display&& -(a=this.turn("view",a||b.tpage||b.page),"ltr"==b.direction?a[0]?a[1]||(d+=c.width/4):d-=c.width/4:a[0]?a[1]||(d-=c.width/4):d+=c.width/4);f(this).css({marginLeft:d});return this},destroy:function(){var a=this.data();a.destroying=!0;f(this).unbind(n.down).unbind("end").unbind("first").unbind("flip").unbind("last").unbind("pressed").unbind("released").unbind("start").unbind("turning").unbind("turned").unbind("zooming");for(f(document).unbind(n.move,a.docEvents.mouseMove).unbind(n.up,a.docEvents.mouseEnd);0!== -a.totalPages;)this.turn("removePage",a.totalPages);a.fparent&&a.fparent.remove();a.shadow&&a.shadow.remove();this.removeData();return this},is:function(){return"object"==typeof this.data().pages},zoom:function(a){var b=this.data();if("number"==typeof a){if(0.0010>a||100this.data().totalPages)){b=this.turn("range");for(a=b[0];a<=b[1];a++)i._addPage.call(this,a)}},range:function(a){var b,c,d,e=this.data(),a=a||e.tpage||e.page||1;d=i._view.call(this,a);if(1>a||a>e.totalPages)throw k('"'+a+'" is not a page for range');d[1]=d[1]||d[0];1<=d[0]&&d[1]<=e.totalPages?(a=Math.floor(2),e.totalPages-d[1]>d[0]?(b=Math.min(d[0]-1,a),c=2*a-b):(c=Math.min(e.totalPages-d[1],a),b=2*a-c)):c=b=5;return[Math.max(1,d[0]- -b),Math.min(e.totalPages,d[1]+c)]},_necessPage:function(a){if(0===a)return!0;var b=this.data(),c=this.turn("range");return b.pageObjs[a].hasClass("fixed")||a>=c[0]&&a<=c[1]},_removeFromDOM:function(){var a,b=this.data();for(a in b.pageWrap)j(a,b.pageWrap)&&!i._necessPage.call(this,a)&&i._removePageFromDOM.call(this,a)},_removePageFromDOM:function(a){var b=this.data();if(b.pages[a]){var c=b.pages[a].data();h._moveFoldingPage.call(b.pages[a],!1);c.f&&c.f.fwrapper&&c.f.fwrapper.remove();b.pages[a].removeData(); -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();if(1>a||a>b.totalPages)throw k("The page "+a+" doesn't exist");b.pageObjs[a]&&(this.turn("stop"),i._removePageFromDOM.call(this,a),delete b.pageObjs[a]);i._movePages.call(this,a,-1);b.totalPages-=1;b.page>b.totalPages?this.turn("page",b.totalPages):i._makeRange.call(this);return this},_movePages:function(a, -b){var c,d=this,e=this.data(),g="single"==e.display,f=function(a){var c=a+b,f=c%2,h=f?" odd ":" even ";e.pageObjs[a]&&(e.pageObjs[c]=e.pageObjs[a].removeClass("p"+a+" odd even").addClass("p"+c+h));e.pagePlace[a]&&e.pageWrap[a]&&(e.pagePlace[c]=c,e.pageWrap[c]=e.pageObjs[c].hasClass("fixed")?e.pageWrap[a].attr("page",c):e.pageWrap[a].css(i._pageSize.call(d,c,!0)).attr("page",c),e.pages[a]&&(e.pages[c]=e.pages[a].flip("options",{page:c,next:g||f?c+1:c-1,corners:g?"all":f?"forward":"backward"})),b&& -(delete e.pages[a],delete e.pagePlace[a],delete e.pageObjs[a],delete e.pageWrap[a],delete e.pageObjs[a]))};if(0=a;c--)f(c);else for(c=a;c<=e.totalPages;c++)f(c)},display:function(a){var b=this.data(),c=b.display;if(a){if(-1==f.inArray(a,x))throw k('"'+a+'" is not a value for display');"single"==a?b.pageObjs[0]||(this.turn("stop").css({overflow:"hidden"}),b.pageObjs[0]=f("
",{"class":"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"),i._movePages.call(this,1,0),this.turn("size",a.width,a.height).turn("update"));return this}return c},direction:function(a){var b=this.data();if("undefined"==typeof a)return b.direction;a=a.toLowerCase();if(-1==f.inArray(a,y))throw k('"'+a+'" is not a value for direction');"rtl"==a&&f(this).attr("dir","ltr").css({direction:"ltr"});b.direction=a;b.done&&this.turn("size",f(this).width(), -f(this).height());return this},animating:function(){return 0a&&this.turn("page",a)}b.totalPages=a;return this}return b.totalPages}, -_missing:function(a){for(var b=this.data(),c=this.turn("range",a),d=[],a=c[0];a<=c[1];a++)b.pageObjs[a]||d.push(a);0h[1]?(c=h[1],d=l[0]):h[0]&&ah[0]?"r":"l"):e.pages[c].flip("turnPage",l[0]>h[0]?"l":"r"):e.pages[c].flip("turnPage"))},page:function(a){var a=parseInt(a,10),b=this.data();return 0b.page?b.next:b.page+1),i._addMotionPage.call(a.target));i._updateShadow.call(b.turn)}, -_end:function(a,b,c){f(a.target).data();var a=b.turn,d=a.data();if(c||d.tpage){if(d.tpage==b.next||d.tpage==b.page)delete d.tpage,i._fitPage.call(a,d.tpage||b.next,!0)}else i._removeMv.call(a,b.page),i._updateShadow.call(a),a.turn("update")},_pressed:function(a){a.stopPropagation();var b,a=f(a.target).data().f,c=a.opts.turn.data().pages;for(b in c)b!=a.opts.page&&c[b].flip("disable",!0);return a.time=(new Date).getTime()},_released:function(a,b){a.stopPropagation();var c,d=f(a.target),e=d.data().f, -g=e.opts.turn,u=g.data();c="single"==u.display?"r"==b.corner?b.xd.width()/2:0>b.x||b.x>d.width();if(200>(new Date).getTime()-e.time||c)a.preventDefault(),i._turnPage.call(g,e.opts.next,!1===h._cornerActivated.call(d,b,1));u.mouseAction=!1},_flip:function(a){a.stopPropagation();a=f(a.target).data().f.opts;a.turn.trigger("turn",[a.next]);a.turn.data().opts.autoCenter&&a.turn.turn("center",a.next)},calculateZ:function(a){var b,c,d,e,g=this,f=this.data();b=this.turn("view");var h=b[0]|| -b[1],i={pageZ:{},partZ:{},pageV:{}},j=function(a){a=g.turn("view",a);a[0]&&(i.pageV[a[0]]=!0);a[1]&&(i.pageV[a[1]]=!0)};for(b=0;b",{"class":"shadow",css:q(0,0,0).css}).appendTo(this));for(var h=0;h=a.x||0>=a.y||a.x>=d||a.y>=e)return!1;e=h._cAllowed.call(this);if(a.x>d-b)a.corner="r";else if(a.x",q(0,0,2)).css(c).appendTo(b).prepend(this);a.fpage=f("
",q(0,0,1)).css(c).appendTo(b)}h.resize.call(this,!0)},_fold:function(a){var b=this.data().f,c=h._c.call(this,a.corner),c=c.x?c.x-a.x:a.x,d=this.width();this.height();c=Math.min(2*d,Math.max(0,c));switch(a.corner){case "r":b.wrapper.css({width:Math.max(0,d-c)});this.css({position:"relative", -left:-c});b.fpage.css({left:-c+d,width:Math.max(0,c-d)});break;case "l":b.wrapper.css({width:d}),this.css({position:"relative",left:c}),b.fpage.css({left:d,width:Math.max(0,c-d)}),b.folding&&b.folding.css({position:"relative",left:2*-d+c})}b.parent.css({overflow:"visible"});b.point=a},_moveFoldingPage:function(a){var b=this.data().f;if(a){var a=h._foldingPage.call(this),c=b.opts.turn;if(a){if(b.folding){if(b.folding===a)return;h._moveFoldingPage.call(this,!1)}h.setData.call(this,{backParent:a.parent(), -folding:a});b.fpage.prepend(a)}c.turn("update")}else b.backParent&&(b.backParent.prepend(b.folding),delete b.backParent,delete b.folding)},_showFoldedPage:function(a,b){var c=h._foldingPage.call(this),d=this.data(),e=d.f,g=e.visible;if(!g||!e.point||e.point.corner!=a.corner){e.opts.turn.data();var i=f.Event("start");this.trigger(i,[e.opts,a.corner]);g=!1;if(i.isDefaultPrevented())return!1}if(c){if(b){var l=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(l,a)}})}else h._fold.call(this,a),d.effect&&!d.effect.turning&&this.animatef(!1);g||(e.visible=!0,h._moveFoldingPage.call(this,!0),e.fpage.show());return!0}return!1},hide:function(){var a=this.data().f;h._foldingPage.call(this);this.css({position:"",left:"auto"});a.wrapper.css({width:this.width()});a.fpage.css({width:this.width()});a.folding&&a.folding.css({position:"",left:"auto"});a.fpage.hide(); -a.visible=!1;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",[b.opts,!1])};if(a){var g=h._c.call(this,d.corner),a="t"==d.corner.substr(0,1)?Math.min(0,d.y-g.y)/2:Math.max(0,d.y-g.y)/2,f=m(d.x,d.y+a),i=m(g.x,g.y-a);this.animatef({from:0,to:1,frame:function(a){a=t(d,f,i,g,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=t(d,d,e,e,c);a.x=c.x;a.y=c.y;h._showFoldedPage.call(b,a)},complete:function(){b.trigger("end",[c.opts,!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._showFoldedPage.call(this,b.corner)&&this.trigger("pressed",[b.point]),!1;b.corner=null}},_eventMove:function(a){var b=this.data().f;if(!b.disabled)if(a=[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=f.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}};window.requestAnim=function(a){window.setTimeout(a,1E3/ -60)};f.extend(f.fn,{flip:function(a,b){return s(this,h,arguments)},turn:function(a){return s(this,i,arguments)},transform:function(a,b){var c={};b&&(c[r+"transform-origin"]=b);c[r+"transform"]=a;return this.css(c)},animatef:function(a){var b=this.data();b.effect&&b.effect.stop();if(a){a.to.length||(a.to=[a.to]);a.from.length||(a.from=[a.from]);for(var c=[],d=a.to.length,e=!0,g=this,h=(new Date).getTime(),i=function(){if(b.effect&&e){for(var f=[],j=Math.min(a.duration,(new Date).getTime()-h),k=0;k< -d;k++)f.push(b.effect.easing(1,j,a.from[k],c[k],a.duration));a.frame(1==d?f[0]:f);j==a.duration?(delete b.effect,g.data(b),a.complete&&a.complete()):window.requestAnim(i)}},j=0;jlastPage) - throw turnError('Page "'+page+'" cannot be inserted'); - - } else { - - page = lastPage; - incPages = true; - - } - - if (page>=1 && page<=lastPage) { - - if (data.display=='double') - className = (page%2) ? ' odd' : ' even'; - else - className = ''; - - // Stop animations - if (data.done) - this.turn('stop'); - - // Move pages if it's necessary - if (page in data.pageObjs) - turnMethods._movePages.call(this, page, 1); - - // Increase the number of pages - if (incPages) - data.totalPages = lastPage; - - // Add element - data.pageObjs[page] = $(element). - css({'float': 'left'}). - addClass('page p' + page + className); - - if (!hasHardPage() && data.pageObjs[page].hasClass('hard')) { - data.pageObjs[page].removeClass('hard'); - } - - // Add page - turnMethods._addPage.call(this, page); - - // Remove pages out of range - turnMethods._removeFromDOM.call(this); - } - - return this; - }, - - // Adds a page - - _addPage: function(page) { - - var data = this.data(), - element = data.pageObjs[page]; - - if (element) - if (turnMethods._necessPage.call(this, page)) { - - if (!data.pageWrap[page]) { - - // Wrapper - data.pageWrap[page] = $('
', - {'class': 'page-wrapper', - page: page, - css: {position: 'absolute', - overflow: 'hidden'}}); - - // Append to this flipbook - this.append(data.pageWrap[page]); - - if (!data.pagePlace[page]) { - - data.pagePlace[page] = page; - // Move `pageObjs[page]` to wrapper - data.pageObjs[page].appendTo(data.pageWrap[page]); - - } - - // Set the size of the page - var prop = turnMethods._pageSize.call(this, page, true); - element.css({width: prop.width, height: prop.height}); - data.pageWrap[page].css(prop); - - } - - if (data.pagePlace[page] == page) { - - // If the page isn't in another place, create the flip effect - turnMethods._makeFlip.call(this, page); - - } - - } else { - - // Place - data.pagePlace[page] = 0; - - // Remove element from the DOM - if (data.pageObjs[page]) - data.pageObjs[page].remove(); - - } - - }, - - // Checks if a page is in memory - - hasPage: function(page) { - - return has(page, this.data().pageObjs); - - }, - - // Centers the flipbook - - center: function(page) { - - var data = this.data(), - size = $(this).turn('size'), - left = 0; - - if (!data.noCenter) { - if (data.display=='double') { - var view = this.turn('view', page || data.tpage || data.page); - - if (data.direction=='ltr') { - if (!view[0]) - left -= size.width/4; - else if (!view[1]) - left += size.width/4; - } else { - if (!view[0]) - left += size.width/4; - else if (!view[1]) - left -= size.width/4; - } - - } - - $(this).css({marginLeft: left}); - } - - return this; - - }, - - // Destroys the flipbook - - destroy: function () { - - var page, - flipbook = this, - data = this.data(), - events = [ - 'end', 'first', 'flip', 'last', 'pressed', - 'released', 'start', 'turning', 'turned', - 'zooming', 'missing']; - - if (trigger('destroying', this)=='prevented') - return; - - data.destroying = true; - - $.each(events, function(index, eventName) { - flipbook.unbind(eventName); - }); - - this.parent().unbind('start', data.eventHandlers.start); - - $(document).unbind(mouseEvents.move, data.eventHandlers.touchMove). - unbind(mouseEvents.up, data.eventHandlers.touchEnd); - - while (data.totalPages!==0) { - this.turn('removePage', data.totalPages); - } - - if (data.fparent) - data.fparent.remove(); - - if (data.shadow) - data.shadow.remove(); - - this.removeData(); - data = null; - - return this; - - }, - - // Checks if this element is a flipbook - - is: function() { - - return typeof(this.data().pages)=='object'; - - }, - - // Sets and gets the zoom value - - zoom: function(newZoom) { - - var data = this.data(); - - if (typeof(newZoom)=='number') { - - if (newZoom<0.001 || newZoom>100) - throw turnError(newZoom+ ' is not a value for zoom'); - - if (trigger('zooming', this, [newZoom, data.zoom])=='prevented') - return this; - - var size = this.turn('size'), - currentView = this.turn('view'), - iz = 1/data.zoom, - newWidth = Math.round(size.width * iz * newZoom), - newHeight = Math.round(size.height * iz * newZoom); - - data.zoom = newZoom; - - $(this).turn('stop'). - turn('size', newWidth, newHeight); - /*. - css({marginTop: size.height * iz / 2 - newHeight / 2});*/ - - if (data.opts.autoCenter) - this.turn('center'); - /*else - $(this).css({marginLeft: size.width * iz / 2 - newWidth / 2});*/ - - turnMethods._updateShadow.call(this); - - for (var i = 0; idata.totalPages) - throw turnError('"'+page+'" is not a valid page'); - - - view[1] = view[1] || view[0]; - - if (view[0]>=1 && view[1]<=data.totalPages) { - - remainingPages = Math.floor((pagesInDOM-2)/2); - - if (data.totalPages-view[1] > view[0]) { - left = Math.min(view[0]-1, remainingPages); - right = 2*remainingPages-left; - } else { - right = Math.min(data.totalPages-view[1], remainingPages); - left = 2*remainingPages-right; - } - - } else { - left = pagesInDOM-1; - right = pagesInDOM-1; - } - - return [Math.max(1, view[0]-left), - Math.min(data.totalPages, view[1]+right)]; - - }, - - // Detects if a page is within the range of `pagesInDOM` from the current view - - _necessPage: function(page) { - - if (page===0) - return true; - - var range = this.turn('range'); - - return this.data().pageObjs[page].hasClass('fixed') || - (page>=range[0] && page<=range[1]); - - }, - - // Releases memory by removing pages from the DOM - - _removeFromDOM: function() { - - var page, data = this.data(); - - for (page in data.pageWrap) - if (has(page, data.pageWrap) && - !turnMethods._necessPage.call(this, page)) - turnMethods._removePageFromDOM.call(this, page); - - }, - - // Removes a page from DOM and its internal references - - _removePageFromDOM: function(page) { - - var data = this.data(); - - if (data.pages[page]) { - var dd = data.pages[page].data(); - - flipMethods._moveFoldingPage.call(data.pages[page], false); - - if (dd.f && dd.f.fwrapper) - dd.f.fwrapper.remove(); - - data.pages[page].removeData(); - data.pages[page].remove(); - delete data.pages[page]; - } - - if (data.pageObjs[page]) - data.pageObjs[page].remove(); - - if (data.pageWrap[page]) { - data.pageWrap[page].remove(); - delete data.pageWrap[page]; - } - - turnMethods._removeMv.call(this, page); - - delete data.pagePlace[page]; - delete data.pageZoom[page]; - - }, - - // Removes a page - - removePage: function(page) { - - var data = this.data(); - - // Delete all the pages - if (page=='*') { - - while (data.totalPages!==0) { - this.turn('removePage', data.totalPages); - } - - } else { - - if (page<1 || page>data.totalPages) - throw turnError('The page '+ page + ' doesn\'t exist'); - - if (data.pageObjs[page]) { - - // Stop animations - this.turn('stop'); - - // Remove `page` - turnMethods._removePageFromDOM.call(this, page); - - delete data.pageObjs[page]; - - } - - // Move the pages - turnMethods._movePages.call(this, page, -1); - - // Resize the size of this flipbook - data.totalPages = data.totalPages-1; - - // Check the current view - - if (data.page>data.totalPages) { - - data.page = null; - turnMethods._fitPage.call(this, data.totalPages); - - } else { - - turnMethods._makeRange.call(this); - this.turn('update'); - - } - } - - return this; - - }, - - // Moves pages - - _movePages: function(from, change) { - - var page, - that = this, - data = this.data(), - single = data.display=='single', - move = function(page) { - - var next = page + change, - odd = next%2, - className = (odd) ? ' odd ' : ' even '; - - if (data.pageObjs[page]) - data.pageObjs[next] = data.pageObjs[page]. - removeClass('p' + page + ' odd even'). - addClass('p' + next + className); - - if (data.pagePlace[page] && data.pageWrap[page]) { - - data.pagePlace[next] = next; - - if (data.pageObjs[next].hasClass('fixed')) - data.pageWrap[next] = data.pageWrap[page]. - attr('page', next); - else - data.pageWrap[next] = data.pageWrap[page]. - css(turnMethods._pageSize.call(that, next, true)). - attr('page', next); - - if (data.pages[page]) - data.pages[next] = data.pages[page]. - flip('options', { - page: next, - next: (single || odd) ? next+1 : next-1 - }); - - if (change) { - delete data.pages[page]; - delete data.pagePlace[page]; - delete data.pageZoom[page]; - delete data.pageObjs[page]; - delete data.pageWrap[page]; - } - - } - - }; - - if (change>0) - for (page=data.totalPages; page>=from; page--) - move(page); - else - for (page=from; page<=data.totalPages; page++) - move(page); - - }, - - // Sets or Gets the display mode - - display: function(display) { - - var data = this.data(), - currentDisplay = data.display; - - if (display===undefined) { - - return currentDisplay; - - } else { - - if ($.inArray(display, displays)==-1) - throw turnError('"'+display + '" is not a value for display'); - - switch(display) { - case 'single': - - // Create a temporal page to use as folded page - - if (!data.pageObjs[0]) { - this.turn('stop'). - css({'overflow': 'hidden'}); - - data.pageObjs[0] = $('
', - {'class': 'page p-temporal'}). - css({width: this.width(), height: this.height()}). - appendTo(this); - } - - this.addClass('shadow'); - - break; - case 'double': - - // Remove the temporal page - - if (data.pageObjs[0]) { - this.turn('stop').css({'overflow': ''}); - data.pageObjs[0].remove(); - delete data.pageObjs[0]; - } - - this.removeClass('shadow'); - - break; - } - - - data.display = display; - - if (currentDisplay) { - var size = this.turn('size'); - turnMethods._movePages.call(this, 1, 0); - this.turn('size', size.width, size.height). - turn('update'); - } - - return this; - - } - - }, - - // Gets and sets the direction of the flipbook - - direction: function(dir) { - - var data = this.data(); - - if (dir===undefined) { - - return data.direction; - - } else { - - dir = dir.toLowerCase(); - - if ($.inArray(dir, directions)==-1) - throw turnError('"' + dir + '" is not a value for direction'); - - if (dir=='rtl') { - $(this).attr('dir', 'ltr'). - css({direction: 'ltr'}); - } - - data.direction = dir; - - if (data.done) - this.turn('size', $(this).width(), $(this).height()); - - return this; - } - - }, - - // Detects animation - - animating: function() { - - return this.data().pageMv.length>0; - - }, - - // Gets the current activated corner - - corner: function() { - - var corner, - page, - data = this.data(); - - for (page in data.pages) { - if (has(page, data.pages)) - if ((corner = data.pages[page].flip('corner'))) { - return corner; - } - } - - return false; - }, - - // Gets the data stored in the flipbook - - data: function() { - - return this.data(); - - }, - - // Disables and enables the effect - - disable: function(disable) { - - var page, - data = this.data(), - view = this.turn('view'); - - data.disabled = disable===undefined || disable===true; - - for (page in data.pages) { - if (has(page, data.pages)) - data.pages[page].flip('disable', - (data.disabled) ? true : $.inArray(parseInt(page, 10), view)==-1); - } - - return this; - - }, - - // Disables and enables the effect - - disabled: function(disable) { - - if (disable===undefined) { - return this.data().disabled===true; - } else { - return this.turn('disable', disable); - } - - }, - - // Gets and sets the size - - size: function(width, height) { - - if (width===undefined || height===undefined) { - - return {width: this.width(), height: this.height()}; - - } else { - - this.turn('stop'); - - var page, prop, - data = this.data(), - pageWidth = (data.display=='double') ? width/2 : width; - - this.css({width: width, height: height}); - - if (data.pageObjs[0]) - data.pageObjs[0].css({width: pageWidth, height: height}); - - for (page in data.pageWrap) { - if (!has(page, data.pageWrap)) continue; - - prop = turnMethods._pageSize.call(this, page, true); - - data.pageObjs[page].css({width: prop.width, height: prop.height}); - data.pageWrap[page].css(prop); - - if (data.pages[page]) - data.pages[page].css({width: prop.width, height: prop.height}); - } - - this.turn('resize'); - - return this; - - } - }, - - // Resizes each page - - resize: function() { - - var page, data = this.data(); - - if (data.pages[0]) { - data.pageWrap[0].css({left: -this.width()}); - data.pages[0].flip('resize', true); - } - - for (page = 1; page <= data.totalPages; page++) - if (data.pages[page]) - data.pages[page].flip('resize', true); - - turnMethods._updateShadow.call(this); - - if (data.opts.autoCenter) - this.turn('center'); - - }, - - // Removes an animation from the cache - - _removeMv: function(page) { - - var i, data = this.data(); - - for (i=0; i0) ? view[0] : 0, - (view[1]<=data.totalPages) ? view[1] : 0]; - else - return [(view[0]>0 && view[0]<=data.totalPages) ? view[0] : 0]; - - }, - - // Stops animations - - stop: function(ignore, animate) { - - if (this.turn('animating')) { - - var i, opts, page, - data = this.data(); - - if (data.tpage) { - data.page = data.tpage; - delete data['tpage']; - } - - for (i = 0; ipages; page--) - this.turn('removePage', page); - - } - - data.totalPages = pages; - turnMethods._fitPage.call(this, data.page); - - return this; - - } else - return data.totalPages; - - }, - - // Checks missing pages - - _missing : function(page) { - - var data = this.data(); - - if (data.totalPages<1) - return; - - var p, - range = this.turn('range', page), - missing = []; - - for (p = range[0]; p<=range[1]; p++) { - if (!data.pageObjs[p]) - missing.push(p); - } - - if (missing.length>0) - this.trigger('missing', [missing]); - - }, - - // Sets a page without effect - - _fitPage: function(page) { - - var data = this.data(), - newView = this.turn('view', page); - - turnMethods._missing.call(this, page); - - if (!data.pageObjs[page]) - return; - - data.page = page; - - this.turn('stop'); - - for (var i = 0; iview[1]) { - current = view[1]; - next = newView[0]; - } else if (view[0] && pagecurrent) ? 'r' : 'l'); - else - data.pages[current].flip('turnPage', - (page>current) ? 'l' : 'r'); - else { - if (data.direction=='ltr') - data.pages[current].flip('turnPage', - optsCorners[(page>current) ? 1 : 0]); - else - data.pages[current].flip('turnPage', - optsCorners[(page>current) ? 0 : 1]); - } - - }, - - // Gets and sets a page - - page: function(page) { - - var data = this.data(); - - if (page===undefined) { - - return data.page; - - } else { - - if (!data.disabled && !data.destroying) { - - page = parseInt(page, 10); - - if (page>0 && page<=data.totalPages) { - - if (page!=data.page) { - if (!data.done || $.inArray(page, this.turn('view'))!=-1) - turnMethods._fitPage.call(this, page); - else - turnMethods._turnPage.call(this, page); - } - - return this; - - } else { - - throw turnError('The page ' + page + ' does not exist'); - - } - - } - - } - - }, - - // Turns to the next view - - next: function() { - - return this.turn('page', Math.min(this.data().totalPages, - turnMethods._view.call(this, this.data().page).pop() + 1)); - - }, - - // Turns to the previous view - - previous: function() { - - return this.turn('page', Math.max(1, - turnMethods._view.call(this, this.data().page).shift() - 1)); - - }, - - // Shows a peeling corner - - peel: function(corner, animate) { - - var data = this.data(), - view = this.turn('view'); - - animate = (animate===undefined) ? true : animate===true; - - if (corner===false) { - - this.turn('stop', null, animate); - - } else { - - if (data.display=='single') { - - data.pages[data.page].flip('peel', corner, animate); - - } else { - - var page; - - if (data.direction=='ltr') { - - page = (corner.indexOf('l')!=-1) ? view[0] : view[1]; - - } else { - - page = (corner.indexOf('l')!=-1) ? view[1] : view[0]; - - } - - if (data.pages[page]) - data.pages[page].flip('peel', corner, animate); - - } - } - - return this; - - }, - - // Adds a motion to the internal list - // This event is called in context of flip - - _addMotionPage: function() { - - var opts = $(this).data().f.opts, - turn = opts.turn, - dd = turn.data(); - - turnMethods._addMv.call(turn, opts.page); - - }, - - // This event is called in context of flip - - _eventStart: function(e, opts, corner) { - - var data = opts.turn.data(), - actualZoom = data.pageZoom[opts.page]; - - if (e.isDefaultPrevented()) { - turnMethods._updateShadow.call(opts.turn); - return; - } - - if (actualZoom && actualZoom!=data.zoom) { - - opts.turn.trigger('zoomed',[ - opts.page, - opts.turn.turn('view', opts.page), - actualZoom, - data.zoom]); - - data.pageZoom[opts.page] = data.zoom; - - } - - if (data.display=='single' && corner) { - - if ((corner.charAt(1)=='l' && data.direction=='ltr') || - (corner.charAt(1)=='r' && data.direction=='rtl')) - { - - opts.next = (opts.nextopts.page) ? opts.next : opts.page+1; - - } - - } - - turnMethods._addMotionPage.call(e.target); - turnMethods._updateShadow.call(opts.turn); - }, - - // This event is called in context of flip - - _eventEnd: function(e, opts, turned) { - - var that = $(e.target), - data = that.data().f, - turn = opts.turn, - dd = turn.data(); - - if (turned) { - - var tpage = dd.tpage || dd.page; - - if (tpage==opts.next || tpage==opts.page) { - delete dd.tpage; - - turnMethods._fitPage.call(turn, tpage || opts.next, true); - } - - } else { - - turnMethods._removeMv.call(turn, opts.page); - turnMethods._updateShadow.call(turn); - turn.turn('update'); - - } - - }, - - // This event is called in context of flip - - _eventPressed: function(e) { - - var page, - data = $(e.target).data().f, - turn = data.opts.turn, - turnData = turn.data(), - pages = turnData.pages; - - turnData.mouseAction = true; - - turn.turn('update'); - - return data.time = new Date().getTime(); - - }, - - // This event is called in context of flip - - _eventReleased: function(e, point) { - - var outArea, - page = $(e.target), - data = page.data().f, - turn = data.opts.turn, - turnData = turn.data(); - - if (turnData.display=='single') { - outArea = (point.corner=='br' || point.corner=='tr') ? - point.xpage.width()/2; - } else { - outArea = point.x<0 || point.x>page.width(); - } - - if ((new Date()).getTime()-data.time<200 || outArea) { - - e.preventDefault(); - turnMethods._turnPage.call(turn, data.opts.next); - - } - - turnData.mouseAction = false; - - }, - - // This event is called in context of flip - - _flip: function(e) { - - e.stopPropagation(); - - var opts = $(e.target).data().f.opts; - - opts.turn.trigger('turn', [opts.next]); - - if (opts.turn.data().opts.autoCenter) { - opts.turn.turn('center', opts.next); - } - - }, - - // - _touchStart: function() { - var data = this.data(); - for (var page in data.pages) { - if (has(page, data.pages) && - flipMethods._eventStart.apply(data.pages[page], arguments)===false) { - return false; - } - } - }, - - // - _touchMove: function() { - var data = this.data(); - for (var page in data.pages) { - if (has(page, data.pages)) { - flipMethods._eventMove.apply(data.pages[page], arguments); - } - } - }, - - // - _touchEnd: function() { - var data = this.data(); - for (var page in data.pages) { - if (has(page, data.pages)) { - flipMethods._eventEnd.apply(data.pages[page], arguments); - } - } - }, - - // Calculate the z-index value for pages during the animation - - calculateZ: function(mv) { - - var i, page, nextPage, placePage, dpage, - that = this, - data = this.data(), - view = this.turn('view'), - currentPage = view[0] || view[1], - total = mv.length-1, - r = {pageZ: {}, partZ: {}, pageV: {}}, - - addView = function(page) { - var view = that.turn('view', page); - if (view[0]) r.pageV[view[0]] = true; - if (view[1]) r.pageV[view[1]] = true; - }; - - for (i = 0; i<=total; i++) { - page = mv[i]; - nextPage = data.pages[page].data().f.opts.next; - placePage = data.pagePlace[page]; - addView(page); - addView(nextPage); - dpage = (data.pagePlace[nextPage]==nextPage) ? nextPage : page; - r.pageZ[dpage] = data.totalPages - Math.abs(currentPage-dpage); - r.partZ[placePage] = data.totalPages*2 - total + i; - } - - return r; - }, - - // Updates the z-index and display property of every page - - update: function() { - - var page, - data = this.data(); - - if (this.turn('animating') && data.pageMv[0]!==0) { - - // Update motion - - var p, apage, fixed, - pos = this.turn('calculateZ', data.pageMv), - corner = this.turn('corner'), - actualView = this.turn('view'), - newView = this.turn('view', data.tpage); - - for (page in data.pageWrap) { - - if (!has(page, data.pageWrap)) - continue; - - fixed = data.pageObjs[page].hasClass('fixed'); - - data.pageWrap[page].css({ - display: (pos.pageV[page] || fixed) ? '' : 'none', - zIndex: - (data.pageObjs[page].hasClass('hard') ? - pos.partZ[page] - : - pos.pageZ[page] - ) || (fixed ? -1 : 0) - }); - - if ((p = data.pages[page])) { - - p.flip('z', pos.partZ[page] || null); - - if (pos.pageV[page]) - p.flip('resize'); - - if (data.tpage) { // Is it turning the page to `tpage`? - - p.flip('hover', false). - flip('disable', - $.inArray(parseInt(page, 10), data.pageMv)==-1 && - page!=newView[0] && - page!=newView[1]); - - } else { - - p.flip('hover', corner===false). - flip('disable', page!=actualView[0] && page!=actualView[1]); - - } - - } - - } - - } else { - - // Update static pages - - for (page in data.pageWrap) { - - if (!has(page, data.pageWrap)) - continue; - - var pageLocation = turnMethods._setPageLoc.call(this, page); - - if (data.pages[page]) { - data.pages[page]. - flip('disable', data.disabled || pageLocation!=1). - flip('hover', true). - flip('z', null); - } - } - } - - return this; - }, - - // Updates the position and size of the flipbook's shadow - - _updateShadow: function() { - - var view, view2, shadow, - data = this.data(), - width = this.width(), - height = this.height(), - pageWidth = (data.display=='single') ? width : width/2; - - view = this.turn('view'); - - if (!data.shadow) { - data.shadow = $('
', { - 'class': 'shadow', - 'css': divAtt(0, 0, 0).css - }). - appendTo(this); - } - - for (var i = 0; i=width || point.y>=height) - return false; - - var allowedCorners = flipMethods._cAllowed.call(this); - - switch (data.effect) { - case 'hard': - - if (point.x>width-csz) - point.corner = 'r'; - else if (point.x=height-csz) - point.corner+= 'b'; - else - return false; - - if (point.x<=csz) - point.corner+= 'l'; - else if (point.x>=width-csz) - point.corner+= 'r'; - else - return false; - - break; - } - - return (!point.corner || $.inArray(point.corner, allowedCorners)==-1) ? - false : point; - - }, - - _isIArea: function(e) { - - var pos = this.data().f.parent.offset(); - - e = (isTouch && e.originalEvent) ? e.originalEvent.touches[0] : e; - - return flipMethods._cornerActivated.call(this, - { - x: e.pageX-pos.left, - y: e.pageY-pos.top - }); - - }, - - _c: function(corner, opts) { - - opts = opts || 0; - - switch (corner) { - case 'tl': - return point2D(opts, opts); - case 'tr': - return point2D(this.width()-opts, opts); - case 'bl': - return point2D(opts, this.height()-opts); - case 'br': - return point2D(this.width()-opts, this.height()-opts); - case 'l': - return point2D(opts, 0); - case 'r': - return point2D(this.width()-opts, 0); - } - - }, - - _c2: function(corner) { - - switch (corner) { - case 'tl': - return point2D(this.width()*2, 0); - case 'tr': - return point2D(-this.width(), 0); - case 'bl': - return point2D(this.width()*2, this.height()); - case 'br': - return point2D(-this.width(), this.height()); - case 'l': - return point2D(this.width()*2, 0); - case 'r': - return point2D(-this.width(), 0); - } - - }, - - _foldingPage: function() { - - var data = this.data().f; - - if (!data) - return; - - var opts = data.opts; - - if (opts.turn) { - data = opts.turn.data(); - if (data.display == 'single') - return (opts.next>1 || opts.page>1) ? data.pageObjs[0] : null; - else - return data.pageObjs[opts.next]; - } - - }, - - _backGradient: function() { - - var data = this.data().f, - turnData = data.opts.turn.data(), - gradient = turnData.opts.gradients && (turnData.display=='single' || - (data.opts.page!=2 && data.opts.page!=turnData.totalPages-1)); - - if (gradient && !data.bshadow) - data.bshadow = $('
', divAtt(0, 0, 1)). - css({'position': '', width: this.width(), height: this.height()}). - appendTo(data.parent); - - return gradient; - - }, - - type: function () { - - return this.data().f.effect; - - }, - - resize: function(full) { - - var data = this.data().f, - turnData = data.opts.turn.data(), - width = this.width(), - height = this.height(); - - switch (data.effect) { - case 'hard': - - if (full) { - data.wrapper.css({width: width, height: height}); - data.fpage.css({width: width, height: height}); - if (turnData.opts.gradients) { - data.ashadow.css({width: width, height: height}); - data.bshadow.css({width: width, height: height}); - } - } - - break; - case 'sheet': - - if (full) { - var size = Math.round(Math.sqrt(Math.pow(width, 2)+Math.pow(height, 2))); - - data.wrapper.css({width: size, height: size}); - data.fwrapper.css({width: size, height: size}). - children(':first-child'). - css({width: width, height: height}); - - data.fpage.css({width: width, height: height}); - - if (turnData.opts.gradients) - data.ashadow.css({width: width, height: height}); - - if (flipMethods._backGradient.call(this)) - data.bshadow.css({width: width, height: height}); - } - - if (data.parent.is(':visible')) { - var offset = findPos(data.parent[0]); - - data.fwrapper.css({top: offset.top, - left: offset.left}); - - //if (data.opts.turn) { - offset = findPos(data.opts.turn[0]); - data.fparent.css({top: -offset.top, left: -offset.left}); - //} - } - - this.flip('z', data.opts['z-index']); - - break; - } - - }, - - // Prepares the page by adding a general wrapper and another objects - - _addPageWrapper: function() { - - var att, - data = this.data().f, - turnData = data.opts.turn.data(), - parent = this.parent(); - - data.parent = parent; - - if (!data.wrapper) - switch (data.effect) { - case 'hard': - - var cssProperties = {}; - cssProperties[vendor + 'transform-style'] = 'preserve-3d'; - cssProperties[vendor + 'backface-visibility'] = 'hidden'; - - data.wrapper = $('
', divAtt(0, 0, 2)). - css(cssProperties). - appendTo(parent). - prepend(this); - - data.fpage = $('
', divAtt(0, 0, 1)). - css(cssProperties). - appendTo(parent); - - if (turnData.opts.gradients) { - data.ashadow = $('
', divAtt(0, 0, 0)). - hide(). - appendTo(parent); - - data.bshadow = $('
', divAtt(0, 0, 0)); - } - - break; - case 'sheet': - - var width = this.width(), - height = this.height(), - size = Math.round(Math.sqrt(Math.pow(width, 2)+Math.pow(height, 2))); - - data.fparent = data.opts.turn.data().fparent; - - if (!data.fparent) { - var fparent = $('
', {css: {'pointer-events': 'none'}}).hide(); - fparent.data().flips = 0; - fparent.css(divAtt(0, 0, 'auto', 'visible').css). - appendTo(data.opts.turn); - - data.opts.turn.data().fparent = fparent; - data.fparent = fparent; - } - - this.css({position: 'absolute', top: 0, left: 0, bottom: 'auto', right: 'auto'}); - - data.wrapper = $('
', divAtt(0, 0, this.css('z-index'))). - appendTo(parent). - prepend(this); - - data.fwrapper = $('
', divAtt(parent.offset().top, parent.offset().left)). - hide(). - appendTo(data.fparent); - - data.fpage = $('
', divAtt(0, 0, 0, 'visible')). - css({cursor: 'default'}). - appendTo(data.fwrapper); - - if (turnData.opts.gradients) - data.ashadow = $('
', divAtt(0, 0, 1)). - appendTo(data.fpage); - - flipMethods.setData.call(this, data); - - break; - } - - // Set size - flipMethods.resize.call(this, true); - - }, - - // Takes a 2P point from the screen and applies the transformation - - _fold: function(point) { - - var data = this.data().f, - turnData = data.opts.turn.data(), - o = flipMethods._c.call(this, point.corner), - width = this.width(), - height = this.height(); - - switch (data.effect) { - - case 'hard': - - if (point.corner=='l') - point.x = Math.min(Math.max(point.x, 0), width*2); - else - point.x = Math.max(Math.min(point.x, width), -width); - - var leftPos, - shadow, - gradientX, - fpageOrigin, - parentOrigin, - totalPages = turnData.totalPages, - zIndex = data.opts['z-index'] || totalPages, - parentCss = {'overflow': 'visible'}, - relX = (o.x) ? (o.x - point.x)/width : point.x/width, - angle = relX * 90, - half = angle<90; - - switch (point.corner) { - case 'l': - - fpageOrigin = '0% 50%'; - parentOrigin = '100% 50%'; - - if (half) { - leftPos = 0; - shadow = data.opts.next-1>0; - gradientX = 1; - } else { - leftPos = '100%'; - shadow = data.opts.page+1 A90) { - tr.x = tr.x + Math.abs(tr.y * rel.y/rel.x); - tr.y = 0; - if (Math.round(tr.x*Math.tan(PI-alpha)) < height) { - point.y = Math.sqrt(Math.pow(height, 2)+2 * middle.x * rel.x); - if (top) point.y = height - point.y; - return compute(); - } - } - - if (alpha>A90) { - var beta = PI-alpha, dd = h - height/Math.sin(beta); - mv = point2D(Math.round(dd*Math.cos(beta)), Math.round(dd*Math.sin(beta))); - if (left) mv.x = - mv.x; - if (top) mv.y = - mv.y; - } - - px = Math.round(tr.y/Math.tan(alpha) + tr.x); - - var side = width - px, - sideX = side*Math.cos(alpha*2), - sideY = side*Math.sin(alpha*2); - df = point2D( - Math.round((left ? side -sideX : px+sideX)), - Math.round((top) ? sideY : height - sideY)); - - // Gradients - if (turnData.opts.gradients) { - - gradientSize = side*Math.sin(alpha); - - var endingPoint = flipMethods._c2.call(that, point.corner), - far = Math.sqrt(Math.pow(endingPoint.x-point.x, 2)+Math.pow(endingPoint.y-point.y, 2))/width; - - shadowVal = Math.sin(A90*((far>1) ? 2 - far : far)); - - gradientOpacity = Math.min(far, 1); - - - gradientStartVal = gradientSize>100 ? (gradientSize-100)/gradientSize : 0; - - gradientEndPointA = point2D( - gradientSize*Math.sin(alpha)/width*100, - gradientSize*Math.cos(alpha)/height*100); - - - if (flipMethods._backGradient.call(that)) { - - gradientEndPointB = point2D( - gradientSize*1.2*Math.sin(alpha)/width*100, - gradientSize*1.2*Math.cos(alpha)/height*100); - - if (!left) gradientEndPointB.x = 100-gradientEndPointB.x; - if (!top) gradientEndPointB.y = 100-gradientEndPointB.y; - - } - - } - - tr.x = Math.round(tr.x); - tr.y = Math.round(tr.y); - - return true; - }, - - transform = function(tr, c, x, a) { - - var f = ['0', 'auto'], mvW = (width-h)*x[0]/100, mvH = (height-h)*x[1]/100, - cssA = {left: f[c[0]], top: f[c[1]], right: f[c[2]], bottom: f[c[3]]}, - cssB = {}, - aliasingFk = (a!=90 && a!=-90) ? (left ? -1 : 1) : 0, - origin = x[0] + '% ' + x[1] + '%'; - - that.css(cssA). - transform(rotate(a) + translate(tr.x + aliasingFk, tr.y, ac), origin); - - data.fpage.css(cssA).transform( - rotate(a) + - translate(tr.x + df.x - mv.x - width*x[0]/100, tr.y + df.y - mv.y - height*x[1]/100, ac) + - rotate((180/a - 2)*a), - origin); - - data.wrapper.transform(translate(-tr.x + mvW-aliasingFk, -tr.y + mvH, ac) + rotate(-a), origin); - - data.fwrapper.transform(translate(-tr.x + mv.x + mvW, -tr.y + mv.y + mvH, ac) + rotate(-a), origin); - - if (turnData.opts.gradients) { - - if (x[0]) - gradientEndPointA.x = 100-gradientEndPointA.x; - - if (x[1]) - gradientEndPointA.y = (100-gradientEndPointA.y); - - cssB['box-shadow'] = '0 0 20px rgba(0,0,0,'+(0.5*shadowVal)+')'; - folding.css(cssB); - - gradient(data.ashadow, - point2D(left?100:0, top?0:100), - point2D(gradientEndPointA.x, gradientEndPointA.y), - [[gradientStartVal, 'rgba(0,0,0,0)'], - [((1-gradientStartVal)*0.8)+gradientStartVal, 'rgba(0,0,0,'+(0.2*gradientOpacity)+')'], - [1, 'rgba(255,255,255,'+(0.2*gradientOpacity)+')']], - 3, - alpha); - - if (flipMethods._backGradient.call(that)) - gradient(data.bshadow, - point2D(left?0:100, top?0:100), - point2D(gradientEndPointB.x, gradientEndPointB.y), - [[0.6, 'rgba(0,0,0,0)'], - [0.8, 'rgba(0,0,0,'+(0.3*gradientOpacity)+')'], - [1, 'rgba(0,0,0,0)'] - ], - 3); - } - - }; - - switch (point.corner) { - case 'l' : - - - break; - case 'r' : - - - break; - case 'tl' : - point.x = Math.max(point.x, 1); - compute(); - transform(tr, [1,0,0,1], [100, 0], a); - break; - case 'tr' : - point.x = Math.min(point.x, width-1); - compute(); - transform(point2D(-tr.x, tr.y), [0,0,0,1], [0, 0], -a); - break; - case 'bl' : - point.x = Math.max(point.x, 1); - compute(); - transform(point2D(tr.x, -tr.y), [1,1,0,0], [100, 100], -a); - break; - case 'br' : - point.x = Math.min(point.x, width-1); - compute(); - transform(point2D(-tr.x, -tr.y), [0,1,1,0], [0, 100], a); - break; - } - - break; - } - - data.point = point; - - }, - - _moveFoldingPage: function(move) { - - var data = this.data().f; - - if (!data) - return; - - var turn = data.opts.turn, - turnData = turn.data(), - place = turnData.pagePlace; - - if (move) { - - var nextPage = data.opts.next; - - if (place[nextPage]!=data.opts.page) { - - if (data.folding) - flipMethods._moveFoldingPage.call(this, false); - - var folding = flipMethods._foldingPage.call(this); - - folding.appendTo(data.fpage); - place[nextPage] = data.opts.page; - data.folding = nextPage; - } - - turn.turn('update'); - - } else { - - if (data.folding) { - - if (turnData.pages[data.folding]) { - - // If we have flip available - - var flipData = turnData.pages[data.folding].data().f; - - turnData.pageObjs[data.folding]. - appendTo(flipData.wrapper); - - } else if (turnData.pageWrap[data.folding]) { - - // If we have the pageWrapper - - turnData.pageObjs[data.folding]. - appendTo(turnData.pageWrap[data.folding]); - - } - - if (data.folding in place) { - place[data.folding] = data.folding; - } - - delete data.folding; - - } - } - }, - - _showFoldedPage: function(c, animate) { - - var folding = flipMethods._foldingPage.call(this), - dd = this.data(), - data = dd.f, - visible = data.visible; - - if (folding) { - - if (!visible || !data.point || data.point.corner!=c.corner) { - - var corner = ( - data.status=='hover' || - data.status=='peel' || - data.opts.turn.data().mouseAction) ? - c.corner : null; - - visible = false; - - if (trigger('start', this, [data.opts, corner])=='prevented') - return false; - - } - - if (animate) { - - var that = this, - point = (data.point && data.point.corner==c.corner) ? - data.point : flipMethods._c.call(this, c.corner, 1); - - this.animatef({ - from: [point.x, point.y], - to: [c.x, c.y], - duration: 500, - frame: function(v) { - c.x = Math.round(v[0]); - c.y = Math.round(v[1]); - flipMethods._fold.call(that, c); - } - }); - - } else { - - flipMethods._fold.call(this, c); - - if (dd.effect && !dd.effect.turning) - this.animatef(false); - - } - - if (!visible) { - - switch(data.effect) { - case 'hard': - - data.visible = true; - flipMethods._moveFoldingPage.call(this, true); - data.fpage.show(); - if (data.opts.shadows) - data.bshadow.show(); - - break; - case 'sheet': - - data.visible = true; - data.fparent.show().data().flips++; - flipMethods._moveFoldingPage.call(this, true); - data.fwrapper.show(); - if (data.bshadow) - data.bshadow.show(); - - break; - } - - } - - return true; - - } - - return false; - }, - - hide: function() { - - var data = this.data().f, - turnData = data.opts.turn.data(), - folding = flipMethods._foldingPage.call(this); - - switch (data.effect) { - case 'hard': - - if (turnData.opts.gradients) { - data.bshadowLoc = 0; - data.bshadow.remove(); - data.ashadow.hide(); - } - - data.wrapper.transform(''); - data.fpage.hide(); - - break; - case 'sheet': - - if ((--data.fparent.data().flips)===0) - data.fparent.hide(); - - this.css({left: 0, top: 0, right: 'auto', bottom: 'auto'}). - transform(''); - - data.wrapper.transform(''); - - data.fwrapper.hide(); - - if (data.bshadow) - data.bshadow.hide(); - - folding.transform(''); - - break; - } - - data.visible = false; - - return this; - }, - - hideFoldedPage: function(animate) { - - var data = this.data().f; - - if (!data.point) return; - - var that = this, - p1 = data.point, - hide = function() { - data.point = null; - data.status = ''; - that.flip('hide'); - that.trigger('end', [data.opts, false]); - }; - - if (animate) { - - var p4 = flipMethods._c.call(this, p1.corner), - top = (p1.corner.substr(0,1)=='t'), - delta = (top) ? Math.min(0, p1.y-p4.y)/2 : Math.max(0, p1.y-p4.y)/2, - p2 = point2D(p1.x, p1.y+delta), - p3 = point2D(p4.x, p4.y-delta); - - this.animatef({ - from: 0, - to: 1, - frame: function(v) { - var np = bezier(p1, p2, p3, p4, v); - p1.x = np.x; - p1.y = np.y; - flipMethods._fold.call(that, p1); - }, - complete: hide, - duration: 800, - hiding: true - }); - - } else { - - this.animatef(false); - hide(); - - } - }, - - turnPage: function(corner) { - - var that = this, - data = this.data().f, - turnData = data.opts.turn.data(); - - corner = {corner: (data.corner) ? - data.corner.corner : - corner || flipMethods._cAllowed.call(this)[0]}; - - var p1 = data.point || - flipMethods._c.call(this, - corner.corner, - (data.opts.turn) ? turnData.opts.elevation : 0), - p4 = flipMethods._c2.call(this, corner.corner); - - this.trigger('flip'). - animatef({ - from: 0, - to: 1, - frame: function(v) { - - var np = bezier(p1, p1, p4, p4, v); - corner.x = np.x; - corner.y = np.y; - flipMethods._showFoldedPage.call(that, corner); - - }, - complete: function() { - - that.trigger('end', [data.opts, true]); - - }, - duration: turnData.opts.duration, - turning: true - }); - - data.corner = null; - }, - - moving: function() { - - return 'effect' in this.data(); - - }, - - isTurning: function() { - - return this.flip('moving') && this.data().effect.turning; - - }, - - corner: function() { - - return this.data().f.corner; - - }, - - _eventStart: function(e) { - - var data = this.data().f, - turn = data.opts.turn; - - if (!data.corner && !data.disabled && !this.flip('isTurning') && - data.opts.page==turn.data().pagePlace[data.opts.page]) - { - - data.corner = flipMethods._isIArea.call(this, e); - - if (data.corner && flipMethods._foldingPage.call(this)) { - - this.trigger('pressed', [data.point]); - flipMethods._showFoldedPage.call(this, data.corner); - - return false; - - } else - data.corner = null; - - } - - }, - - _eventMove: function(e) { - - var data = this.data().f; - - if (!data.disabled) { - - e = (isTouch) ? e.originalEvent.touches : [e]; - - if (data.corner) { - - var pos = data.parent.offset(); - data.corner.x = e[0].pageX-pos.left; - data.corner.y = e[0].pageY-pos.top; - flipMethods._showFoldedPage.call(this, data.corner); - - } else if (data.hover && !this.data().effect && this.is(':visible')) { - - var point = flipMethods._isIArea.call(this, e[0]); - - if (point) { - - if ((data.effect=='sheet' && point.corner.length==2) || data.effect=='hard') { - data.status = 'hover'; - var origin = flipMethods._c.call(this, point.corner, data.opts.cornerSize/2); - point.x = origin.x; - point.y = origin.y; - flipMethods._showFoldedPage.call(this, point, true); - } - - } else { - - if (data.status=='hover') { - data.status = ''; - flipMethods.hideFoldedPage.call(this, true); - } - - } - - } - - } - - }, - - _eventEnd: function() { - - var data = this.data().f, - corner = data.corner; - - if (!data.disabled && corner) { - if (trigger('released', this, [data.point || corner])!='prevented') { - flipMethods.hideFoldedPage.call(this, true); - } - } - - data.corner = null; - - }, - - disable: function(disable) { - - flipMethods.setData.call(this, {'disabled': disable}); - return this; - - }, - - hover: function(hover) { - - flipMethods.setData.call(this, {'hover': hover}); - return this; - - }, - - peel: function (corner, animate) { - - var data = this.data().f; - - if (corner) { - - if ($.inArray(corner, corners.all)==-1) - throw turnError('Corner '+corner+' is not permitted'); - - if ($.inArray(corner, flipMethods._cAllowed.call(this))!=-1) { - - var point = flipMethods._c.call(this, corner, data.opts.cornerSize/2); - - data.status = 'peel'; - - flipMethods._showFoldedPage.call(this, - { - corner: corner, - x: point.x, - y: point.y - }, animate); - - } - - - } else { - - data.status = ''; - - flipMethods.hideFoldedPage.call(this, animate); - - } - - return this; - } -}; - - -// Processes classes - -function dec(that, methods, args) { - - if (!args[0] || typeof(args[0])=='object') - return methods.init.apply(that, args); - - else if (methods[args[0]]) - return methods[args[0]].apply(that, Array.prototype.slice.call(args, 1)); - - else - throw turnError(args[0] + ' is not a method or property'); - -} - - -// Attributes for a layer - -function divAtt(top, left, zIndex, overf) { - - return {'css': { - position: 'absolute', - top: top, - left: left, - 'overflow': overf || 'hidden', - zIndex: zIndex || 'auto' - } -}; - -} - -// Gets a 2D point from a bezier curve of four points - -function bezier(p1, p2, p3, p4, t) { - - var a = 1 - t, - b = a * a * a, - c = t * t * t; - - return point2D(Math.round(b*p1.x + 3*t*a*a*p2.x + 3*t*t*a*p3.x + c*p4.x), - Math.round(b*p1.y + 3*t*a*a*p2.y + 3*t*t*a*p3.y + c*p4.y)); - -} - -// Converts an angle from degrees to radians - -function rad(degrees) { - - return degrees/180*PI; - -} - -// Converts an angle from radians to degrees - -function deg(radians) { - - return radians/PI*180; - -} - -// Gets a 2D point - -function point2D(x, y) { - - return {x: x, y: y}; - -} - -// Webkit 534.3 on Android wrongly repaints elements that use overflow:hidden + rotation - -function rotationAvailable() { - var parts; - - if ((parts = /AppleWebkit\/([0-9\.]+)/i.exec(navigator.userAgent))) { - var webkitVersion = parseFloat(parts[1]); - return (webkitVersion>534.3); - } else { - return true; - } -} - -// Returns the traslate value - -function translate(x, y, use3d) { - - return (has3d && use3d) ? ' translate3d(' + x + 'px,' + y + 'px, 0px) ' - : ' translate(' + x + 'px, ' + y + 'px) '; - -} - -// Returns the rotation value - -function rotate(degrees) { - - return ' rotate(' + degrees + 'deg) '; - -} - -// Checks if a property belongs to an object - -function has(property, object) { - - return Object.prototype.hasOwnProperty.call(object, property); - -} - -// Gets the CSS3 vendor prefix - -function getPrefix() { - - var vendorPrefixes = ['Moz','Webkit','Khtml','O','ms'], - len = vendorPrefixes.length, - vendor = ''; - - while (len--) - if ((vendorPrefixes[len] + 'Transform') in document.body.style) - vendor='-'+vendorPrefixes[len].toLowerCase()+'-'; - - return vendor; - -} - -// Detects the transitionEnd Event - -function getTransitionEnd() { - - var t, - el = document.createElement('fakeelement'), - transitions = { - 'transition':'transitionend', - 'OTransition':'oTransitionEnd', - 'MSTransition':'transitionend', - 'MozTransition':'transitionend', - 'WebkitTransition':'webkitTransitionEnd' - }; - - for (t in transitions) { - if (el.style[t] !== undefined) { - return transitions[t]; - } - } -} - -// Gradients - -function gradient(obj, p0, p1, colors, numColors) { - - var j, cols = []; - - if (vendor=='-webkit-') { - - for (j = 0; j