This repository has been archived by the owner on May 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
/
jquery.flippy.min.js
1 lines (1 loc) · 14.6 KB
/
jquery.flippy.min.js
1
!function(a){function b(){a("document").ready(function(){var a,b=document.createElement("p"),c={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};document.body.appendChild(b);for(var d in c)void 0!==b.style[d]&&(b.style[d]="rotateX(1deg)",a=window.getComputedStyle(b).getPropertyValue(c[d]));document.body.removeChild(b),f=void 0!==a&&a.length>0&&"none"!==a})}var c={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgrey:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4","indianred ":"#cd5c5c","indigo ":"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},d="Microsoft Internet Explorer"==navigator.appName,e=window.HTMLCanvasElement,f=null;b();var g=Math.PI,h=function(b,h,i){this.animate=function(b){if(b?this._RBefore():this._Before(),typeof b!==i&&b){var c=this._Recto,d=this._Recto_color;switch(this._Recto=this._Verso,this._Color=this._Recto_color=this._Verso_color,this._Verso=c,this._Color_target=this._Verso_color=d,this._Reversing=!0,this._Direction){case"TOP":this._Direction="BOTTOM";break;case"BOTTOM":this._Direction="TOP";break;case"LEFT":this._Direction="RIGHT";break;case"RIGHT":this._Direction="LEFT"}}this._noCSS||!f?(this.initiateFlippy(),this.cvO=document.getElementById("flippy"+this._UID),this.jO.data("_oFlippy_",this),this._Int=setInterval(a.proxy(this.drawFlippy,this),this._Refresh_rate)):(this.jO.addClass("flippy_active"),this._noRemove||this.jO.parent().css({perspective:Math.floor(this._Depth*this._nW)+"px"}),this.jO.data("_oFlippy_",this),this._Int=setInterval(a.proxy(this.drawFlippyCSS,this),this._Refresh_rate))},this.drawFlippyCSS=function(){this._Ang="RIGHT"==this._Direction||"TOP"==this._Direction?this._Ang+this._Step_ang:this._Ang-this._Step_ang;var b="RIGHT"==this._Direction||"LEFT"==this._Direction?"Y":"X";return(("RIGHT"==this._Direction||"TOP"==this._Direction)&&this._Ang>90&&this._Ang<=90+this._Step_ang||("LEFT"==this._Direction||"BOTTOM"==this._Direction)&&this._Ang<-90&&this._Ang>=-90-this._Step_ang)&&(this._Reversing?this._RMidway():this._Midway(),this.jO.css({opacity:this._Color_target_alpha,background:this._Color_target}),this._noRemove?(a(this.jO.find(this._Recto)).css("display","none"),0===a(this._Verso).length?this.jO.append(this._Back_html):a(this._Verso).css("display","block")):this.jO.empty().append(this._Verso),this._Ang="RIGHT"==this._Direction||"TOP"==this._Direction?-90:90,this._Half=!0),this._Ang="RIGHT"==this._Direction||"TOP"==this._Direction?this._Ang>this._Step_ang&&this._Half?this._Ang-this._Step_ang:this._Ang:this._Ang<-this._Step_ang&&this._Half?this._Ang+this._Step_ang:this._Ang,("RIGHT"==this._Direction||"TOP"==this._Direction)&&this._Ang>0&&this._Half||("LEFT"==this._Direction||"BOTTOM"==this._Direction)&&this._Ang<0&&this._Half?(this.jO.removeClass("flippy_active").css({"-webkit-transform":"rotate"+b+"(0deg)","-moz-transform":"rotate"+b+"(0deg)","-o-transform":"rotate"+b+"(0deg)","-ms-transform":"rotate"+b+"(0deg)",transform:"rotate"+b+"(0deg)"}).find(".flippy_light").remove(),clearInterval(this._Int),this._Half=!1,void(this._Reversing?this._RAfter():this._After())):(this.jO.css({"-webkit-transform":"rotate"+b+"("+this._Ang+"deg)","-moz-transform":"rotate"+b+"("+this._Ang+"deg)","-o-transform":"rotate"+b+"("+this._Ang+"deg)","-ms-transform":"rotate"+b+"("+this._Ang+"deg)",transform:"rotate"+b+"("+this._Ang+"deg)"}),this.applyLight(),void(this._Reversing?this._RDuring():this._During()))},this.applyLight=function(){0===this.jO.find(".flippy_light").size()?this.jO.append('<div class="flippy_light"></div>').find(".flippy_light").css({position:"absolute",top:"0",left:"0","min-width":this._nW+"px","min-height":this._nH+"px",width:this._nW+"px",height:this._nH+"px","background-color":"LEFT"==this._Direction&&this._Half||"RIGHT"==this._Direction&&!this._Half||"TOP"==this._Direction&&this._Half||"BOTTOM"==this._Direction&&!this._Half?"#000":"#FFF",opacity:Math.abs(this._Ang)*this._Light/90/100}):this.jO.find(".flippy_light").css({"background-color":"LEFT"==this._Direction&&this._Half||"RIGHT"==this._Direction&&!this._Half||"TOP"==this._Direction&&this._Half||"BOTTOM"==this._Direction&&!this._Half?"#000":"#FFF",opacity:Math.abs(this._Ang)*this._Light/90/100})},this.initiateFlippy=function(){var b;switch(this.jO.addClass("flippy_active").css({opacity:this._Color_alpha,background:"none",position:"relative",overflow:"visible"}),this._noRemove?a(this.jO.find(this._Recto)).css("display","none"):this.jO.empty(),this._Direction){case"TOP":this._CenterX=Math.sin(g/2)*this._nW*this._Depth,this._CenterY=this._H/2,b='<canvas id="flippy'+this._UID+'" class="flippy" width="'+(this._W+2*this._CenterX)+'" height="'+this._H+'"></canvas>',this.new_flippy(b),this.jO.find("#flippy"+this._UID).css({position:"absolute",top:"0",left:"-"+this._CenterX+"px"});break;case"BOTTOM":this._CenterX=Math.sin(g/2)*this._nW*this._Depth,this._CenterY=this._H/2,b='<canvas id="flippy'+this._UID+'" class="flippy" width="'+(this._W+2*this._CenterX)+'" height="'+this._H+'"></canvas>',this.new_flippy(b),this.jO.find("#flippy"+this._UID).css({position:"absolute",top:"0",left:"-"+this._CenterX+"px"});break;case"LEFT":this._CenterY=Math.sin(g/2)*this._nH*this._Depth,this._CenterX=this._W/2,b='<canvas id="flippy'+this._UID+'" class="flippy" width="'+this._W+'" height="'+(this._H+2*this._CenterY)+'"></canvas>',this.new_flippy(b),this.jO.find("#flippy"+this._UID).css({position:"absolute",top:"-"+this._CenterY+"px",left:"0"});break;case"RIGHT":this._CenterY=Math.sin(g/2)*this._nH*this._Depth,this._CenterX=this._W/2,b='<canvas id="flippy'+this._UID+'" class="flippy" width="'+this._W+'" height="'+(this._H+2*this._CenterY)+'"></canvas>',this.new_flippy(b),this.jO.find("#flippy"+this._UID).css({position:"absolute",top:"-"+this._CenterY+"px",left:"0"})}},this.drawFlippy=function(){this._Ang+=this._Step_ang,this._Ang>90&&this._Ang<=90+this._Step_ang&&(this._Reversing?this._RMidway():this._Midway(),this.jO.css({opacity:this._Color_target_alpha})),this._Ang=this._Ang>180+this._Step_ang?this._Ang-(180+this._Step_ang):this._Ang;var b=this._Ang/180*g;if(null!==this.cvO){d&&!e&&G_vmlCanvasManager.initElement(this.cvO);var c=this.cvO.getContext("2d");c.clearRect(0,0,this._W+2*this._CenterX,this._H+2*this._CenterY),c.beginPath();var f,h,i=Math.sin(b)*this._H*this._Depth,j=Math.sin(b)*this._W*this._Depth;switch(this._Direction){case"LEFT":f=Math.cos(b)*(this._W/2),c.fillStyle=this._Ang>90?this.changeColor(this._Color_target,Math.floor(Math.sin(b)*this._Light)):this.changeColor(this._Color,-Math.floor(Math.sin(b)*this._Light)),c.moveTo(this._CenterX-f,this._CenterY+i),c.lineTo(this._CenterX+f,this._CenterY-i),c.lineTo(this._CenterX+f,this._CenterY+this._H+i),c.lineTo(this._CenterX-f,this._CenterY+this._H-i),c.lineTo(this._CenterX-f,this._CenterY),c.fill();break;case"RIGHT":f=Math.cos(b)*(this._W/2),c.fillStyle=this._Ang>90?this.changeColor(this._Color_target,-Math.floor(Math.sin(b)*this._Light)):this.changeColor(this._Color,Math.floor(Math.sin(b)*this._Light)),c.moveTo(this._CenterX+f,this._CenterY+i),c.lineTo(this._CenterX-f,this._CenterY-i),c.lineTo(this._CenterX-f,this._CenterY+this._H+i),c.lineTo(this._CenterX+f,this._CenterY+this._H-i),c.lineTo(this._CenterX+f,this._CenterY),c.fill();break;case"TOP":h=Math.cos(b)*(this._H/2),c.fillStyle=this._Ang>90?this.changeColor(this._Color_target,-Math.floor(Math.sin(b)*this._Light)):this.changeColor(this._Color,Math.floor(Math.sin(b)*this._Light)),c.moveTo(this._CenterX+j,this._CenterY-h),c.lineTo(this._CenterX-j,this._CenterY+h),c.lineTo(this._CenterX+this._W+j,this._CenterY+h),c.lineTo(this._CenterX+this._W-j,this._CenterY-h),c.lineTo(this._CenterX,this._CenterY-h),c.fill();break;case"BOTTOM":h=Math.cos(b)*(this._H/2),c.fillStyle=this._Ang>90?this.changeColor(this._Color_target,Math.floor(Math.sin(b)*this._Light)):this.changeColor(this._Color,-Math.floor(Math.sin(b)*this._Light)),c.moveTo(this._CenterX+j,this._CenterY+h),c.lineTo(this._CenterX-j,this._CenterY-h),c.lineTo(this._CenterX+this._W+j,this._CenterY-h),c.lineTo(this._CenterX+this._W-j,this._CenterY+h),c.lineTo(this._CenterX,this._CenterY+h),c.fill()}return this._Ang>180?(this.jO.removeClass("flippy_active").css({background:this._Color_target}).find(".flippy").remove(),this._noRemove?0===a(this._Verso).length?this.jO.append(this._Back_html):a(this._Verso).css("display","block"):this.jO.append(this._Verso).removeClass("flippy container"),clearInterval(this._Int),void(this._Reversing?this._RAfter():this._After())):void(this._Reversing?this._RDuring():this._During())}},this.new_flippy=function(a){if(d&&!e){this.jO.addClass("flippy_container").attr("id","flippy_container"+this._UID);var b=document.getElementById("flippy_container"+this._UID),c=document.createElement(a);b.appendChild(c)}else this.jO.append(a)},this.convertColor=function(a){var b=c.hasOwnProperty(a)?c[a]:a;return/^transparent$/i.test(b)?"#ffffff":"rgb("==b.substr(0,4)?["#",this.toHex(b.substr(4,b.length).split(",")[0]>>>0),this.toHex(b.substr(3,b.length).split(",")[1]>>>0),this.toHex(b.substr(3,b.length-4).split(",")[2]>>>0)].join(""):"rgba("==b.substr(0,5)?["#",this.toHex(b.substr(5,b.length).split(",")[0]>>>0),this.toHex(b.substr(3,b.length).split(",")[1]>>>0),this.toHex(b.substr(3,b.length-4).split(",")[2]>>>0)].join(""):b},this.toHex=function(a){for(var b=[];Math.floor(a)>16;)b.push(a%16),a=Math.floor(a/16);var c,d;switch(a){case 10:c="A";break;case 11:c="B";break;case 12:c="C";break;case 13:c="D";break;case 14:c="E";break;case 15:c="F";break;default:c=""+a}for(d=b.length-1;d>=0;d--)switch(b[d]){case 10:c+="A";break;case 11:c+="B";break;case 12:c+="C";break;case 13:c+="D";break;case 14:c+="E";break;case 15:c+="F";break;default:c+=""+b[d]}return 1==c.length?"0"+c:c},this.changeColor=function(a,b){var c=a.substr(1,2),d=a.substr(3,2),e=a.substr(5,2),f=parseInt(c,16)+b>255?255:parseInt(c,16)+b,g=parseInt(d,16)+b>255?255:parseInt(d,16)+b,h=parseInt(e,16)+b>255?255:parseInt(e,16)+b;return c=0>=f?"00":this.toHex(f),d=0>=g?"00":this.toHex(g),e=0>=h?"00":this.toHex(h),"#"+c+d+e},h=a.extend({step_ang:10,refresh_rate:15,duration:300,depth:.12,color_target:"white",light:60,content:"",direction:"LEFT",noCSS:!1,onStart:function(){},onMidway:function(){},onAnimation:function(){},onFinish:function(){},onReverseStart:function(){},onReverseMidway:function(){},onReverseAnimation:function(){},onReverseFinish:function(){}},h),this._Reversing=!1,this._Half=!1,this._UID=Math.floor(1e6*Math.random()),this.jO=b,this._noCSS=h.noCSS,this._Ang=0,this._Step_ang=h.refresh_rate/h.duration*200,this._Refresh_rate=h.refresh_rate,this._Duration=h.duration,this._Depth=h.depth,h.color_target&&(this._Color_target_is_rgba="rgba("==h.color_target.substr(0,5),this._Color=b.css("background-color"),this._Color_target_alpha=this._Color_target_is_rgba?h.color_target.substr(3,h.color_target.length-4).split(",")[3]>>>0:1,this._Color_alpha=/^transparent$/i.test(""+this._Color)?0:"rgba("==this._Color.substr(0,5)?this._Color.substr(3,this._Color.length-4).split(",")[3]>>>0:1,this._Color_target=this.convertColor(h.color_target),this._Color=this.convertColor(this._Color)),this._Direction=h.direction.toUpperCase(),this._Light=h.light,this._Content="object"==typeof h.content?h.content.html():h.content,this._Recto_color=this._Color,this._Verso_color=this._Color_target,this._Recto=h.recto!==i?h.recto:this.jO.html(),this._Verso=h.verso!==i?h.verso:this._Content,this._noRemove=h.recto!==i?h.noRemove:!1,this._Back_html=h.backhtml,this._Before=h.onStart,this._During=h.onAnimation,this._Midway=h.onMidway,this._After=h.onFinish,this._RBefore=h.onReverseStart,this._RDuring=h.onReverseAnimation,this._RMidway=h.onReverseMidway,this._RAfter=h.onReverseFinish,this._nW=this.jO.width(),this._nH=this.jO.height(),this._W=this.jO.outerWidth(),this._H=this.jO.outerHeight(),h=null};a.fn.flippy=function(b){return this.each(function(){if($t=a(this),!$t.hasClass("flippy_active")){var c=new h($t,b);c.animate()}})},a.fn.flippyReverse=function(){return this.each(function(){if($t=a(this),!$t.hasClass("flippy_active")){var b=$t.data("_oFlippy_");b.animate(!0)}})}}(jQuery);