-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
js-cumulus.min.js
25 lines (20 loc) · 8.54 KB
/
js-cumulus.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*\
JS-Cumulus - WP-Cumulus in JavaScript (codenamed jscumulus)
Based on Stratus plugin by Dawid Fatyga ([email protected])
Based on WP-Cumulus by Roy Tanck (http://www.roytanck.com)
@author Jeroen van Warmerdam (aka jerone or jeronevw) (http://www.jeroenvanwarmerdam.nl)
@date 24-05-2012 02:15
@version 0.2.5
Copyright 2010 - 2012, Jeroen van Warmerdam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
\*/
(function(i,e,g){var n={ID:"tagCloud",Class:"tagCloud",Width:400,Heigth:400,Consistent:true,Rank:30,Url:"#",OpenInNewWindow:false,FontMin:10,FontMax:24,Depth:150,AnimationTime:1,HoverStop:15,HoverTagStop:95,OverWrite:false};var b=i.TagCloud,m=i.Tag,j=i.Vector,s=i.Surface,f=1,r=Object.prototype.toString,c="[object Object]",l=function(y){return r.call(y)===c},q=function(y){return !!y.nodeType},k=Math.PI/180,o=[],d=[],t=(function(){var y=0,z=3600;while(y<z){o[y]=Math.sin(y/10*k);y++}return function A(B){while(B<0){B+=360}return o[Math.round(B*10)%z]}})(),p=(function(){var y=0,z=3600;while(y<z){d[y]=Math.cos(y/10*k);y++}return function A(B){return d[Math.round(Math.abs(B)*10)%z]}})(),x={Add:(function(){if(e.addEventListener){return function(C,B,A){A=x.Fix.call(this,B==="mouseenter"||B==="mouseleave"?x.mouseEnter(A):A);B=B==="mouseenter"&&"mouseover"||B==="mouseleave"&&"mouseout"||B;C.addEventListener(B,A,false);return function z(){C.removeEventListener(B,A,false);return true}}}else{if(e.attachEvent){return function(C,B,A){A=x.Fix.call(this,A);C.attachEvent("on"+B,A);return function z(){C.detachEvent("on"+B,A);return true}}}}return function y(){}})(),Fix:function(y){return function(B){if(!B.target){B.target=B.srcElement||e}if(B.target.nodeType===3){B.target=B.target.parentNode}if(!B.relatedTarget&&B.fromElement){B.relatedTarget=B.fromElement===B.target?B.toElement:B.fromElement}if(B.pageX===null&&B.clientX!==null){var A=e.documentElement,z=e.body;B.pageX=B.clientX+(A&&A.scrollLeft||z&&z.scrollLeft||0)-(A&&A.clientLeft||z&&z.clientLeft||0);B.pageY=B.clientY+(A&&A.scrollTop||z&&z.scrollTop||0)-(A&&A.clientTop||z&&z.clientTop||0)}y.call(this,B)}},mouseEnter:function(z){var A=function(B,C){if(B===C){return false}while(C&&C!==B){C=C.parentNode}return C===B};return function y(B){var C=B.relatedTarget;if(this===C||A(this,C)){return}z.call(this,B)}}};var a=function(A,C,B){this.set=function(D,F,E){this.x=D||0;this.y=F||0;this.z=E||0};if(A!==g&&l(A)){this.set(A.x,A.y,A.z)}else{this.set(A,C,B)}this.Multiply=function(y){this.x*=y;this.y*=y;this.z*=y;return this};this.Done=function(){return Math.abs(this.x)>0.01||Math.abs(this.y)>0.01||Math.abs(this.z)>0.01}};var u=function(z,y){this.set=function(B,A){this.width=B||0;this.height=A||0};if(z!==g&&l(z)){this.set(z.width,z.height)}else{this.set(z,y)}};var w=function(z,A,y){this.id=A;this.className=y;this.active=false;this.activeTag=false;this.mouse=new a();this.position=new a();this.size=new u({width:z.size.width||n.Width/2,height:z.size.height||n.Heigth/2});this.element=e.createElement("div");this.element.setAttribute("id",this.id);this.element.setAttribute("class",this.className);this.element.style.width=this.size.width+"px";this.element.style.height=this.size.height+"px";this.element.style.display="block";this.Activate=function(){var B=this;x.Add(this.element,"mousemove",function(C){return function(D){if(!z.active){z.Animate()}if(this.active&&!this.activeTag){this.Update();this.mouse.set(((-D.pageY+this.position.y)*2/this.size.height+1)*1.8,((D.pageX-this.position.x)*2/this.size.width-1)*1.8)}}.call(B,C)});x.Add(this.element,"mouseenter",function(){B.active=true});x.Add(this.element,"mouseleave",function(){B.active=false});return this};this.Update=function(){this.position=new a({x:this.element.offsetLeft,y:this.element.offsetTop});return this}};var h=function(F,E,z,D,B){this.id=f++;this.title=F;this.rank=((!isNaN(E)&&E>=0&&E<=100)?E:n.Rank)/100;this.url=z||(isNaN(E)?E:false)||n.Url;this.position=new a();D=arguments[4]&&D||(D===true?true:false)||(arguments[2]===true?true:false)||n.OpenInNewWindow;B=B||l(arguments[3])&&arguments[3]||l(arguments[2])&&arguments[2]||l(arguments[1])&&arguments[1]||{};var C=e.createElement("a");C.setAttribute("id","jsCumulus"+this.id);C.setAttribute("href",this.url);if(D){C.setAttribute("target","_blank")}C.innerHTML=this.title;for(var A in B){C.style[A]=B[A]}var y=e.createElement("li");y.setAttribute("class","tagClass");y.style.position="absolute";y.appendChild(C);this.element=y;this.Activate=function(G){x.Add(this.element,"mouseenter",function(){G.active=false;G.activeTag=true});x.Add(this.element,"mouseleave",function(){G.active=true;G.activeTag=false});return this};this.Update=function(U,K,W,J){U=U||new a();K=K||new a();var Q=this.position,I=U.x||0,G=U.y||0,R=t(I),M=p(I),O=t(G),L=p(G),V=Q.y*R+Q.z*M,T=Q.x*L+V*O,P=Q.y*M+Q.z*(-R),N=Q.x*(-O)+V*L,H=n.Depth/(n.Depth+N),S=J-W;Q.set(T,P,N);C.style.opacity=Math.max(H-0.7,0)/0.5+0.2;C.style.fontSize=this.rank*H*S+W+"px";y.style.left=(K.x+T*H)-(y.clientWidth/2)+"px";y.style.top=(K.y+P*H)-(y.clientHeight/2)+"px";Q=I=G=R=M=O=L=V=T=P=N=H=S=null;return this}};var v=function(A,B,y,z){if(q(arguments[0])){this.element=arguments[0];A=arguments[1];B=arguments[2];y=arguments[3];z=arguments[4]}z=z||l(y)&&y||l(B)&&B||{};this.fps={timer:null,elm:null,i:0};this.active=false;this.delta=new a(-2,-2);this.size=new u({width:parseFloat(!!parseFloat(B)&&B||!!parseFloat(z.width)&&z.width||n.Width),height:parseFloat(!!parseFloat(y)&&y||!!parseFloat(z.height)&&z.height||B||n.Height)});this.font={min:parseFloat(z.fontMin)||n.FontMin,max:parseFloat(z.fontMax)||n.FontMax};this.radius=z.radius||Math.min(this.size.width,this.size.height)/4;this.consistent=z.consistent!==g?!!z.consistent:n.Consistent;this.overwrite=z.overwrite!==g?!!z.overwrite:n.OverWrite;this.items=A&&A.length&&A.slice(0)||(function(){var D=50,E=0,C=[];for(;D>=E;--D){C[D]=new C("+",100)}return C})();this.attractor=new w(this,z.id||n.ID+Math.floor(Math.random()*10000+1),z.className||n.Class);z=null;this.Distribute=function(F){F=F||this.element||e.body;var C=e.createElement("ul"),G=this.items.length-1,E=0,K;if(this.overwrite){while(F.firstChild){F.removeChild(F.firstChild)}}for(;G>=E;--G){K=this.items[G];if(K instanceof h&&K.title){C.appendChild(K.element);K.Activate(this.attractor)}else{this.items.splice(G,1)}}this.attractor.element.appendChild(C);F.appendChild(this.attractor.element);this.attractor.Activate();C=G=E=null;var D,L,J=0,I=this.items.length,H=this.radius;for(;J<I;J++){D=this.consistent?Math.acos(-1+(2*J)/I):Math.random()*(Math.PI);L=this.consistent?Math.sqrt(I*Math.PI)*D:Math.random()*(2*Math.PI);this.items[J].position.set(H*Math.sin(D)*Math.cos(L),H*Math.sin(D)*Math.sin(L),H*Math.cos(D))}D=L=J=I=H=null;this.fps.elm=e.getElementById(this.attractor.id+"_fps");this.Update();return this};this.Update=function(F){this.fps.timer=new Date()*1;F=F||new a();var D=this.attractor.Update(),E=0,C=this.items.length;this.position=new a({x:this.size.width/2+D.position.x,y:this.size.height/2+D.position.y});for(;E<C;E++){this.items[E].Update(F,this.position,this.font.min,this.font.max)}F=D=E=C=null;if(this.fps.elm){this.fps.elm.innerHTML=parseInt(++this.fps.i/((new Date()*1)-this.fps.timer),10)+" fps"}return this};this.Pause=function(){if(this.animation){this.active=false;i.clearInterval(this.animation);this.animation=null;this.fps.timer=null;this.fps.i=0;if(this.fps.elm){this.fps.elm.innerHTML="# fps"}}return this};this.Stop=function(){this.delta=new a();this.Pause();return this};this.Animate=function(D){if(D){this.Stop()}this.active=true;this.delta=D||this.delta||new a();var C=this;this.animation=i.setInterval(function(){return function E(){if(this.attractor.active){this.delta=this.attractor.mouse}else{this.delta.Multiply(((100-Math.min(this.attractor.activeTag?n.HoverTagStop:n.HoverStop,99))/10+90)/100)}if(this.delta.Done()){this.Update(this.delta)}else{this.Stop()}}.call(C)},n.AnimationTime);return this};if(this.element){this.Distribute(this.element)}};i.TagCloud=v;i.Tag=h;i.Vector=a;i.Surface=u;i.JSCumulus={TagCloud:v,Tag:h,Vector:a,Surface:u,noConflict:function(){i.TagCloud=b;i.Tag=m;i.Vector=j;i.Surface=s;return{TagCloud:v,Tag:h,Vector:a,Surface:u}}}})(window,window.document);