Team:UESTC Life/js/biot jquery.booklet.1.1.0.min.js
From 2013.igem.org
Revision as of 06:58, 26 August 2013 by Neptune Yu (Talk | contribs)
/*
* jQuery Booklet Plugin * Copyright (c) 2010 W. Grauvogel (http://builtbywill.com/) * * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. * * Version : 1.1.0 * * Originally based on the work of: * 1) Charles Mangin (http://clickheredammit.com/pageflip/) */(function(b){b.fn.booklet=function(c){var d=b.extend({},b.fn.booklet.defaults,c);return b(this).each(function(){var j,e,h,k,f,g;if(typeof c=="string"){if(b(this).data("booklet")){j=c.toLowerCase();h=b.fn.booklet.interfaces[b(this).data("id")];if(j=="next"){h.next()}else{if(j=="prev"){h.prev()}}}}else{if(typeof c=="number"){if(b(this).data("booklet")){g=c;h=b.fn.booklet.interfaces[b(this).data("id")];if(g%2!=0){g-=1}h.gotoPage(g)}}else{e=b.extend(true,{},d);k=b.fn.booklet.interfaces.length;for(f=0;f<k;f++){if(typeof b.fn.booklet.interfaces[f]=="undefined"){k=f;break}}h=new a(b(this),e,k);b.fn.booklet.interfaces[k]=h}}})};function a(ac,ae,G){var ao,av,S,A,O,L,I,E,o,ad,ah,C,N,aw=new Array(),K=new Array(),F,ab,Z,Y,W,U,ay,ag,J,s,c,aq,am,ax,az,T,al,ak,R,aj,ai,m,D,B,af,y,e,d,l,X,q,v,r,an,w,k,u,P,n,au,t,g,ap='',at='';ad=false;ah=false;C=N=false;ao=this;ao.options=ae;ao.id=G;ao.hash="";av=ao.options;S=ac.addClass("booklet");A=S.children(".b-load");h();S.data("booklet",true);S.data("id",G);S.data("total",A.children().length);if(!av.width){av.width=S.width()}if(!av.height){av.height=S.height()}S.width(av.width);S.height(av.height);av.pWidth=av.width/2;av.pWidthN="-"+(av.width/2)+"px";av.pWidthH=av.width/4;av.pHeight=av.height;av.pTotal=A.children().length;av.speedH=av.speed/2;if(av.direction=="LTR"){av.curr=0}else{if(av.direction=="RTL"){av.curr=av.pTotal-2}}if(!isNaN(av.startingPage)&&av.startingPage<=av.pTotal&&av.startingPage>0){if((av.startingPage%2)!=0){av.startingPage--}av.curr=av.startingPage}if(av.name){document.title=av.name}else{av.name=document.title}if(av.shadows){av.shadowTopFwdWidth="-"+av.shadowTopFwdWidth+"px";av.shadowTopBackWidth="-"+av.shadowTopBackWidth+"px"}if(av.menu){l=b(av.menu).addClass("b-menu");E=av.curr;if(av.pageSelector){q=b('
'+(E+1)+" - "+(E+2)+"
").appendTo(l);v=b("'+X+"
").appendTo(l);P=b("Previous
').appendTo(S);aj=b('Next
').appendTo(S);R=S.find(".b-tab");if(av.tabWidth){R.width(av.tabWidth)}if(av.tabHeight){R.height(av.tabHeight)}R.css({top:"-"+aj.outerHeight()+"px"});S.css({marginTop:aj.outerHeight()});if(av.direction=="RTL"){aj.html("Previous").attr("title","Previous Page");ai.html("Next").attr("title","Next Page")}}else{S.css({marginTop:0})}if(av.arrows){B=b('Previous
Next
Previous
").attr("title","Previous Page");B.html("Next
").attr("title","Next Page")}}e=S.find(".b-next");d=S.find(".b-prev");e.click(function(i){i.preventDefault();ao.next()});d.click(function(i){i.preventDefault();ao.prev()});if(av.hovers){e.hover(function(){if(!ad&&av.curr+2<=av.pTotal-2){Y.stop().animate({width:av.pWidth-40},500,av.easing);W.stop().animate({left:av.width-40,width:20,paddingLeft:10},500,av.easing);C=true}},function(){if(!ad&&av.curr+2<=av.pTotal-2){Y.stop().animate({width:av.pWidth},500,av.easing);W.stop().animate({left:av.width,width:0,paddingLeft:0},500,av.easing);C=false}});d.hover(function(){if(!ad&&av.curr-2>=0){Z.stop().animate({left:10,width:av.pWidth-10},400,av.easing);J.stop().animate({left:"-10px"},400,av.easing);ab.stop().animate({left:10,width:40},400,av.easing);ag.stop().animate({right:10},400,av.easing);N=true}},function(){if(!ad&&av.curr-2>=0){Z.stop().animate({left:0,width:av.pWidth},400,av.easing);J.stop().animate({left:0},400,av.easing);ab.stop().animate({left:0,width:0},400,av.easing);ag.stop().animate({right:0},400,av.easing);N=false}})}if(av.arrows){if(b.support.opacity){e.hover(function(){D.find("div").stop().fadeTo("fast",1)},function(){D.find("div").stop().fadeTo("fast",0)});d.hover(function(){B.find("div").stop().fadeTo("fast",1)},function(){B.find("div").stop().fadeTo("fast",0)})}else{e.hover(function(){D.find("div").show()},function(){D.find("div").hide()});d.hover(function(){B.find("div").show()},function(){B.find("div").hide()})}}if(av.keyboard){b(document).keyup(function(i){if(i.keyCode==37){ao.prev()}else{if(i.keyCode==39){ao.next()}}})}if(av.hash){f();clearInterval();setInterval(function(){V()},250)}aa();function h(){if((A.children().length%2)!=0){if(av.closed&&av.covers){A.children().last().before(at)}else{A.children().last().after(at)}}if(av.closed){b(ap).attr({title:av.closedFrontTitle||"Beginning",rel:av.closedFrontChapter||"Beginning of Book"}).prependTo(A);A.children().last().attr({title:av.closedBackTitle||"End",rel:av.closedBackChapter||"End of Book"});A.append(ap)}if(av.direction=="LTR"){I=0}else{I=A.children().length;if(av.closed){I-=2}if(av.covers){I-=2}b(A.children().get().reverse()).each(function(){b(this).appendTo(A)})}A.children().each(function(j){if(b(this).attr("rel")){K[j]=b(this).attr("rel")}else{K[j]=""}aw[j]=b(this).attr("title");if(b(this).hasClass("b-page-empty")){b(this).wrap('')}else{if(av.closed&&av.covers&&(j==1||j==A.children().length-2)){b(this).wrap('
')}else{if(j%2!=0){b(this).wrap('
')}else{b(this).wrap('
')}}}b(this).parents(".b-page").addClass("b-page-"+j);if(av.pageNumbers&&!b(this).hasClass("b-page-empty")&&(!av.closed||(av.closed&&!av.covers)||(av.closed&&av.covers&&j!=1&&j!=A.children().length-2))){if(av.direction=="LTR"){I++}b(this).parent().append('
'+(I)+"
");if(av.direction=="RTL"){I--}}})}function aa(){S.find(".b-page").removeClass("b-pN b-p0 b-p1 b-p2 b-p3 b-p4").hide();if(ah){I=av.pTotal-1;for(L=0;L<av.pTotal;L++){S.find(".b-page-"+L).detach().appendTo(A)}}if(av.curr-2>=0){S.find(".b-page-"+(av.curr-2)).addClass("b-pN").show();S.find(".b-page-"+(av.curr-1)).addClass("b-p0").show()}S.find(".b-page-"+(av.curr)).addClass("b-p1").show();S.find(".b-page-"+(av.curr+1)).addClass("b-p2").show();if(av.curr+3<=av.pTotal){S.find(".b-page-"+(av.curr+2)).addClass("b-p3").show();S.find(".b-page-"+(av.curr+3)).addClass("b-p4").show()}F=S.find(".b-pN");ab=S.find(".b-p0");Z=S.find(".b-p1");Y=S.find(".b-p2");W=S.find(".b-p3");U=S.find(".b-p4");ay=S.find(".b-pN .b-wrap");ag=S.find(".b-p0 .b-wrap");J=S.find(".b-p1 .b-wrap");s=S.find(".b-p2 .b-wrap");c=S.find(".b-p3 .b-wrap");aq=S.find(".b-p4 .b-wrap");am=S.find(".b-wrap");am.attr("style","");am.css({width:av.pWidth-(av.pagePadding*2),height:av.pHeight-(av.pagePadding*2),padding:av.pagePadding});Z.css({left:0,width:av.pWidth,height:av.pHeight});Y.css({left:av.pWidth,width:av.pWidth,opacity:1,height:av.pHeight});F.css({left:0,width:av.pWidth,height:av.pHeight});ab.css({left:0,width:0,height:av.pHeight});W.stop().css({left:av.pWidth*2,width:0,height:av.pHeight,paddingLeft:0});c.stop().css({left:0});U.css({left:av.pWidth,width:av.pWidth,height:av.pHeight});if(av.curr+3<=av.pTotal){W.after(ab.detach());Z.after(U.detach())}else{ab.detach().appendTo(A)}ah=true;ax=az=null;S.find(".b-shadow-b, .b-shadow-f").remove();if(av.shadows){ax=b('').appendTo(W).css({right:0,width:av.pWidth,height:av.pHeight});az=b('').appendTo(ab).css({left:0,width:av.pWidth,height:av.pHeight})}}function Q(j,i,p){if(i&&j>2){S.find(".b-p3, .b-p4").removeClass("b-p3 b-p4").hide();S.find(".b-page-"+av.curr).addClass("b-p3").show().stop().css({left:av.pWidth*2,width:0,height:av.pHeight,paddingLeft:0});S.find(".b-page-"+(av.curr+1)).addClass("b-p4").show().css({left:av.pWidth,width:av.pWidth,height:av.pHeight});S.find(".b-page-"+av.curr+" .b-wrap").show().css({width:av.pWidth-(av.pagePadding*2),height:av.pHeight-(av.pagePadding*2),padding:av.pagePadding});S.find(".b-page-"+(av.curr+1)+" .b-wrap").show().css({width:av.pWidth-(av.pagePadding*2),height:av.pHeight-(av.pagePadding*2),padding:av.pagePadding});W=S.find(".b-p3");U=S.find(".b-p4");c=S.find(".b-p3 .b-wrap");aq=S.find(".b-p4 .b-wrap");if(C){W.css({left:av.width-40,width:20,"padding-left":10})}p.appendTo(W);Z.after(U.detach());Y.after(W.detach())}else{if(!i&&j>2){S.find(".b-pN, .b-p0").removeClass("b-pN b-p0").hide();S.find(".b-page-"+av.curr).addClass("b-pN").show().css({left:0,width:av.pWidth,height:av.pHeight});S.find(".b-page-"+(av.curr+1)).addClass("b-p0").show().css({left:0,width:0,height:av.pHeight});S.find(".b-page-"+av.curr+" .b-wrap").show().css({width:av.pWidth-(av.pagePadding*2),height:av.pHeight-(av.pagePadding*2),padding:av.pagePadding});S.find(".b-page-"+(av.curr+1)+" .b-wrap").show().css({width:av.pWidth-(av.pagePadding*2),height:av.pHeight-(av.pagePadding*2),padding:av.pagePadding});F=S.find(".b-pN");ab=S.find(".b-p0");ay=S.find(".b-pN .b-wrap");ag=S.find(".b-p0 .b-wrap");if(N){ab.css({left:10,width:40});ag.css({right:10})}p.appendTo(ab);ab.detach().appendTo(A)}}if(av.closed){if(!i&&av.curr==0){F.hide()}else{if(!i){F.show()}}if(i&&av.curr>=av.pTotal-2){U.hide()}else{if(i){U.show()}}}if(av.shadows){if(b.support.opacity){p.animate({opacity:1},av.speedH,av.easeIn).animate({opacity:0},av.speedH,av.easeOut)}else{if(i){p.animate({right:av.shadowTopFwdWidth},av.speed,av.easeIn)}else{p.animate({left:av.shadowTopBackWidth},av.speed,av.easeIn)}}}}function H(){aa();ar();z();av.after.call(ao,av);ad=false}function z(){if(av.overlays||av.tabs||av.arrows){if(av.curr<av.pTotal-2){e.fadeIn("fast").css("cursor",av.cursor)}else{e.fadeOut("fast").css("cursor","default")}if(av.curr>=2&&av.curr!=0){d.fadeIn("fast").css("cursor",av.cursor)}else{d.fadeOut("fast").css("cursor","default")}}}function ar(){if(av.pageSelector){if(av.direction=="RTL"){nums=(Math.abs(av.curr-av.pTotal)-1)+" - "+((Math.abs(av.curr-av.pTotal)));if(av.closed){if(av.curr==av.pTotal-2){nums="1"}else{if(av.curr==0){nums=av.pTotal-2}else{nums=(Math.abs(av.curr-av.pTotal)-2)+" - "+((Math.abs(av.curr-av.pTotal)-1))}}if(av.covers){if(av.curr==av.pTotal-2){nums=""}else{if(av.curr==0){nums=""}else{nums=(Math.abs(av.curr-av.pTotal)-3)+" - "+((Math.abs(av.curr-av.pTotal)-2))}}}}b(av.menu+" .b-selector-page .b-current").text(nums)}else{nums=(av.curr+1)+" - "+(av.curr+2);if(av.closed){if(av.curr==0){nums="1"}else{if(av.curr==av.pTotal-2){nums=av.pTotal-2}else{nums=(av.curr)+"-"+(av.curr+1)}}if(av.covers){if(av.curr==0){nums=""}else{if(av.curr==av.pTotal-2){nums=""}else{nums=(av.curr-1)+"-"+(av.curr)}}}}b(av.menu+" .b-selector-page .b-current").text(nums)}}if(av.chapterSelector){if(K[av.curr]!=""){b(av.menu+" .b-selector-chapter .b-current").text(K[av.curr])}else{if(K[av.curr+1]!=""){b(av.menu+" .b-selector-chapter .b-current").text(K[av.curr+1])}}if(av.direction=="RTL"&&K[av.curr+1]!=""){b(av.menu+" .b-selector-chapter .b-current").text(K[av.curr+1])}else{if(K[av.curr]!=""){b(av.menu+" .b-selector-chapter .b-current").text(K[av.curr])}}}}function f(){O=x();if(!isNaN(O)&&O<=av.pTotal-1&&O>=0&&O!=""){if((O%2)!=0){O--}av.curr=O}else{M(av.curr+1,av)}ao.hash=O}function V(){O=x();if(!isNaN(O)&&O<=av.pTotal-1&&O>=0){if(O!=av.curr&&O.toString()!=ao.hash){if((O%2)!=0){O--}document.title=av.name+" - Page "+(O+1);if(!ad){ao.gotoPage(O);ao.hash=O}}}}function x(){var i=window.location.hash.split("/");if(i.length>1){return parseInt(i[2])-1}else{return""}}function M(j,i){if(i.hash){window.location.hash="/page/"+j}}}b.fn.booklet.interfaces=[];b.fn.booklet.defaults={name:null,width:600,height:400,speed:1000,direction:"LTR",startingPage:0,easing:"easeInOutQuad",easeIn:"easeInQuad",easeOut:"easeOutQuad",closed:false,closedFrontTitle:null,closedFrontChapter:null,closedBackTitle:null,closedBackChapter:null,covers:false,pagePadding:10,pageNumbers:true,hovers:true,overlays:true,tabs:false,tabWidth:60,tabHeight:20,arrows:false,cursor:"pointer",hash:false,keyboard:true,next:null,prev:null,menu:null,pageSelector:false,chapterSelector:false,shadows:true,shadowTopFwdWidth:166,shadowTopBackWidth:166,shadowBtmWidth:50,before:function(){},after:function(){}}})(jQuery);