/**
* Copyright (C) 2010-2015 Graham Breach
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
/**
* jQuery.tagcanvas 2.6.1
* For more information, please contact
*/
(function(am){var L,J,K=Math.abs,af=Math.sin,w=Math.cos,s=Math.max,aA=Math.min,an=Math.ceil,E=Math.sqrt,ap=Math.pow,h={},l={},m={0:"0,",1:"17,",2:"34,",3:"51,",4:"68,",5:"85,",6:"102,",7:"119,",8:"136,",9:"153,",a:"170,",A:"170,",b:"187,",B:"187,",c:"204,",C:"204,",d:"221,",D:"221,",e:"238,",E:"238,",f:"255,",F:"255,"},x,c,P,aC,G,aD,Z,C=document,p,b={};for(L=0;L<256;++L){J=L.toString(16);if(L<16){J="0"+J}l[J]=l[J.toUpperCase()]=L.toString()+","}function ag(i){return typeof i!="undefined"}function H(i){return typeof i=="object"&&i!=null}function ar(i,j,aE){return isNaN(i)?aE:aA(aE,s(j,i))}function ax(){return false}function F(){return new Date().valueOf()}function A(aE,aH){var j=[],aF=aE.length,aG;for(aG=0;aG=1){return 0}if(aE<=-1){return Math.PI}return Math.acos(aE)};G.unit=function(){var i=this.length();return new ac(this.x/i,this.y/i,this.z/i)};function ah(aE,j){j=j*Math.PI/180;aE=aE*Math.PI/180;var i=af(aE)*w(j),aG=-af(j),aF=-w(aE)*w(j);return new ac(i,aG,aF)}function Q(i){this[1]={1:i[0],2:i[1],3:i[2]};this[2]={1:i[3],2:i[4],3:i[5]};this[3]={1:i[6],2:i[7],3:i[8]}}aC=Q.prototype;Q.Identity=function(){return new Q([1,0,0,0,1,0,0,0,1])};Q.Rotation=function(aF,i){var j=af(aF),aE=w(aF),aG=1-aE;return new Q([aE+ap(i.x,2)*aG,i.x*i.y*aG-i.z*j,i.x*i.z*aG+i.y*j,i.y*i.x*aG+i.z*j,aE+ap(i.y,2)*aG,i.y*i.z*aG-i.x*j,i.z*i.x*aG-i.y*j,i.z*i.y*aG+i.x*j,aE+ap(i.z,2)*aG])};aC.mul=function(aE){var aF=[],aI,aH,aG=(aE.xform?1:0);for(aI=1;aI<=3;++aI){for(aH=1;aH<=3;++aH){if(aG){aF.push(this[aI][1]*aE[1][aH]+this[aI][2]*aE[2][aH]+this[aI][3]*aE[3][aH])}else{aF.push(this[aI][aH]*aE)}}}return new Q(aF)};aC.xform=function(aE){var j={},i=aE.x,aG=aE.y,aF=aE.z;j.x=i*this[1][1]+aG*this[2][1]+aF*this[3][1];j.y=i*this[1][2]+aG*this[2][2]+aF*this[3][2];j.z=i*this[1][3]+aG*this[2][3]+aF*this[3][3];return j};function q(aF,aH,aM,aJ){var aI,aL,j,aK,aN=[],aG=Math.PI*(3-E(5)),aE=2/aF;for(aI=0;aI0)}function ai(aI,j,aH,aG){var aF=aI.createLinearGradient(0,0,j,0),aE;for(aE in aG){aF.addColorStop(1-aE,aG[aE])}aI.fillStyle=aF;aI.fillRect(0,aH,j,1)}function k(aG,aE,j){var aF=1024,aK=1,aJ=aG.weightGradient,aI,aM,aH,aL;if(aG.gCanvas){aM=aG.gCanvas.getContext("2d");aK=aG.gCanvas.height}else{if(H(aJ[0])){aK=aJ.length}else{aJ=[aJ]}aG.gCanvas=aI=O(aF,aK);if(!aI){return null}aM=aI.getContext("2d");for(aH=0;aHaP?aR+aP:aP*2)*aG,j=aM+(aL>aP?aL+aP:aP*2)*aG,aJ=aG*((aP||0)+(aF[0]<0?aR:0)),aE=aG*((aP||0)+(aF[1]<0?aL:0)),aI,aN;aI=O(aH,j);if(!aI){return null}aN=aI.getContext("2d");aO&&(aN.shadowColor=aO);aP&&(aN.shadowBlur=aP*aG);aF&&(aN.shadowOffsetX=aF[0]*aG,aN.shadowOffsetY=aF[1]*aG);aN.drawImage(aK,aJ,aE,aQ,aM);return{image:aI,width:aH/aG,height:j/aG}}function t(aQ,aI,aO){var aP=parseInt(aQ.toString().length*aO),aH=parseInt(aO*2*aQ.length),aF=O(aP,aH),aL,j,aG,aK,aN,aM,aE,aJ;if(!aF){return null}aL=aF.getContext("2d");aL.fillStyle="#000";aL.fillRect(0,0,aP,aH);W(aL,aO+"px "+aI,"#fff",aQ,0,0,0,0,[],"centre");j=aL.getImageData(0,0,aP,aH);aG=j.width;aK=j.height;aJ={min:{x:aG,y:aK},max:{x:-1,y:-1}};for(aM=0;aM0){if(aNaJ.max.x){aJ.max.x=aN}if(aMaJ.max.y){aJ.max.y=aM}}}}if(aG!=aP){aJ.min.x*=(aP/aG);aJ.max.x*=(aP/aG)}if(aK!=aH){aJ.min.y*=(aP/aK);aJ.max.y*=(aP/aK)}aF=null;return aJ}function o(i){return"'"+i.replace(/(\'|\")/g,"").replace(/\s*,\s*/g,"', '")+"'"}function ab(i,j,aE){aE=aE||C;if(aE.addEventListener){aE.addEventListener(i,j,false)}else{aE.attachEvent("on"+i,j)}}function a(i,j,aE){aE=aE||C;if(aE.removeEventListener){aE.removeEventListener(i,j)}else{aE.detachEvent("on"+i,j)}}function at(aI,aE,aM,aH){var aN=aH.imageScale,aK,aF,aJ,j,aG,aL;if(!aE.complete){return ab("load",function(){at(aI,aE,aM,aH)},aE)}if(!aI.complete){return ab("load",function(){at(aI,aE,aM,aH)},aI)}aE.width=aE.width;aE.height=aE.height;if(aN){aI.width=aE.width*aN;aI.height=aE.height*aN}aM.iw=aI.width;aM.ih=aI.height;if(aH.txtOpt){aF=aI;aK=aH.zoomMax*aH.txtScale;aG=aM.iw*aK;aL=aM.ih*aK;if(aG0){aM.iw+=2*aH.outlineIncrease;aM.ih+=2*aH.outlineIncrease;aG=aK*aM.iw;aL=aK*aM.ih;aF=au(aM.fimage,aG,aL);aM.oimage=aF;aM.fimage=v(aM.fimage,aM.oimage.width,aM.oimage.height)}else{aG=aK*(aM.iw+(2*aH.outlineIncrease));aL=aK*(aM.ih+(2*aH.outlineIncrease));aF=au(aM.fimage,aG,aL);aM.oimage=v(aF,aM.fimage.width,aM.fimage.height)}}}}aM.Init()}function X(aF,aE){var j=C.defaultView,i=aE.replace(/\-([a-z])/g,function(aG){return aG.charAt(1).toUpperCase()});return(j&&j.getComputedStyle&&j.getComputedStyle(aF,null).getPropertyValue(aE))||(aF.currentStyle&&aF.currentStyle[i])}function u(j,aF,aE){var i=1,aG;if(aF){i=1*(j.getAttribute(aF)||aE)}else{if(aG=X(j,"font-size")){i=(aG.indexOf("px")>-1&&aG.replace("px","")*1)||(aG.indexOf("pt")>-1&&aG.replace("pt","")*1.25)||aG*3.3}}return i}function f(i){return i.target&&ag(i.target.id)?i.target.id:i.srcElement.parentNode.id}function R(aG,aH){var aF,aE,i=parseInt(X(aH,"width"))/aH.width,j=parseInt(X(aH,"height"))/aH.height;if(ag(aG.offsetX)){aF={x:aG.offsetX,y:aG.offsetY}}else{aE=aa(aH.id);if(ag(aG.changedTouches)){aG=aG.changedTouches[0]}if(aG.pageX){aF={x:aG.pageX-aE.x,y:aG.pageY-aE.y}}}if(aF&&i&&j){aF.x/=i;aF.y/=j}return aF}function B(aE){var j=aE.target||aE.fromElement.parentNode,i=y.tc[j.id];if(i){i.mx=i.my=-1;i.UnFreeze();i.EndDrag()}}function ad(aI){var aF,aE=y,j,aH,aG=f(aI);for(aF in aE.tc){j=aE.tc[aF];if(j.tttimer){clearTimeout(j.tttimer);j.tttimer=null}}if(aG&&aE.tc[aG]){j=aE.tc[aG];if(aH=R(aI,j.canvas)){j.mx=aH.x;j.my=aH.y;j.Drag(aI,aH)}j.drawn=0}}function z(aF){var j=y,i=C.addEventListener?0:1,aE=f(aF);if(aE&&aF.button==i&&j.tc[aE]){j.tc[aE].BeginDrag(aF)}}function aB(aG){var aE=y,j=C.addEventListener?0:1,aF=f(aG),i;if(aF&&aG.button==j&&aE.tc[aF]){i=aE.tc[aF];ad(aG);if(!i.EndDrag()&&!i.touched){i.Clicked(aG)}}}function S(aE){var i=y,j=f(aE);if(j&&aE.changedTouches&&i.tc[j]){i.tc[j].touched=1;i.tc[j].BeginDrag(aE)}}function r(aE){var i=y,j=f(aE);if(j&&aE.changedTouches&&i.tc[j]){aw(aE);if(!i.tc[j].EndDrag()){i.tc[j].Draw();i.tc[j].Clicked(aE)}}}function aw(aI){var aF,aE=y,j,aH,aG=f(aI);for(aF in aE.tc){j=aE.tc[aF];if(j.tttimer){clearTimeout(j.tttimer);j.tttimer=null}}if(aG&&aE.tc[aG]&&aI.changedTouches){j=aE.tc[aG];if(aH=R(aI,j.canvas)){j.mx=aH.x;j.my=aH.y;j.Drag(aI,aH)}j.drawn=0}}function ae(aE){var i=y,j=f(aE);if(j&&i.tc[j]){aE.cancelBubble=true;aE.returnValue=false;aE.preventDefault&&aE.preventDefault();i.tc[j].Wheel((aE.wheelDelta||aE.detail)>0)}}function N(){D(F())}function D(aF){var j=y.tc,aE;y.NextFrame(y.interval);aF=aF||F();for(aE in j){j[aE].Draw(aF)}}function aa(aE){var aH=C.getElementById(aE),i=aH.getBoundingClientRect(),aK=C.documentElement,aI=C.body,aJ=window,aF=aJ.pageXOffset||aK.scrollLeft,aL=aJ.pageYOffset||aK.scrollTop,aG=aK.clientLeft||aI.clientLeft,j=aK.clientTop||aI.clientTop;return{x:i.left+aF-aG,y:i.top+aL-j}}function U(j,aF,aG,aE){var i=j.radius*j.z1/(j.z1+j.z2+aF.z);return{x:aF.x*i*aG,y:aF.y*i*aE,z:aF.z,w:(j.z1-aF.z)/j.z2}}function ay(i){this.e=i;this.br=0;this.line=[];this.text=[];this.original=i.innerText||i.textContent}aD=ay.prototype;aD.Empty=function(){for(var j=0;jaE){aJ.push(this.line.join(" "));this.line=[aK[aF]]}else{this.line.push(aK[aF])}}aJ.push(this.line.join(" "))}return this.text=aJ};function I(i,j){this.ts=F();this.tc=i;this.tag=j;this.x=this.y=this.w=this.h=this.sc=1;this.z=0;this.Draw=i.pulsateTo<1&&i.outlineMethod!="colour"?this.DrawPulsate:this.DrawSimple;this.radius=i.outlineRadius|0;this.SetMethod(i.outlineMethod)}x=I.prototype;x.SetMethod=function(aE){var j={block:["PreDraw","DrawBlock"],colour:["PreDraw","DrawColour"],outline:["PostDraw","DrawOutline"],classic:["LastDraw","DrawOutline"],size:["PreDraw","DrawColour"],none:["LastDraw"]},i=j[aE]||j.outline;if(aE=="none"){this.Draw=function(){return 1}}else{this.drawFunc=this[i[1]]}this[i[0]]=this.Draw};x.Update=function(aK,aJ,aL,aG,aH,aI,aF,i){var j=this.tc.outlineOffset,aE=2*j;this.x=aH*aK+aF-j;this.y=aH*aJ+i-j;this.w=aH*aL+aE;this.h=aH*aG+aE;this.sc=aH;this.z=aI};x.DrawOutline=function(aH,i,aG,j,aE,aF){aH.strokeStyle=aF;ao(aH,i,aG,j,aE,this.radius,true)};x.DrawColour=function(aF,aI,aG,aJ,aE,i,aK,j,aH){if(aK.oimage){aK.alpha=1;aK.Draw(aF,j,aH,aK.oimage);return 1}return this[aK.image?"DrawColourImage":"DrawColourText"](aF,aI,aG,aJ,aE,i,aK,j,aH)};x.DrawColourText=function(aG,aJ,aH,aK,aE,i,aL,j,aI){var aF=aL.colour;aL.colour=i;aL.alpha=1;aL.Draw(aG,j,aI);aL.colour=aF;return 1};x.DrawColourImage=function(aJ,aM,aK,aN,aI,i,aQ,j,aL){var aO=aJ.canvas,aG=~~s(aM,0),aF=~~s(aK,0),aH=aA(aO.width-aG,aN)+0.5|0,aP=aA(aO.height-aF,aI)+0.5|0,aE;if(p){p.width=aH,p.height=aP}else{p=O(aH,aP)}if(!p){return this.SetMethod("outline")}aE=p.getContext("2d");aE.drawImage(aO,aG,aF,aH,aP,0,0,aH,aP);aJ.clearRect(aG,aF,aH,aP);aQ.alpha=1;aQ.Draw(aJ,j,aL);aJ.setTransform(1,0,0,1,0,0);aJ.save();aJ.beginPath();aJ.rect(aG,aF,aH,aP);aJ.clip();aJ.globalCompositeOperation="source-in";aJ.fillStyle=i;aJ.fillRect(aG,aF,aH,aP);aJ.restore();aJ.globalCompositeOperation="destination-over";aJ.drawImage(p,0,0,aH,aP,aG,aF,aH,aP);aJ.globalCompositeOperation="source-over";return 1};x.DrawBlock=function(aH,i,aG,j,aE,aF){aH.fillStyle=aF;ao(aH,i,aG,j,aE,this.radius)};x.DrawSimple=function(aG,i,j,aF){var aE=this.tc;aG.setTransform(1,0,0,1,0,0);aG.strokeStyle=aE.outlineColour;aG.lineWidth=aE.outlineThickness;aG.shadowBlur=aG.shadowOffsetX=aG.shadowOffsetY=0;aG.globalAlpha=1;return this.drawFunc(aG,this.x,this.y,this.w,this.h,aE.outlineColour,i,j,aF)};x.DrawPulsate=function(aH,i,j,aF){var aG=F()-this.ts,aE=this.tc;aH.setTransform(1,0,0,1,0,0);aH.strokeStyle=aE.outlineColour;aH.lineWidth=aE.outlineThickness;aH.shadowBlur=aH.shadowOffsetX=aH.shadowOffsetY=0;aH.globalAlpha=aE.pulsateTo+((1-aE.pulsateTo)*(0.5+(w(2*Math.PI*aG/(1000*aE.pulsateTime))/2)));return this.drawFunc(aH,this.x,this.y,this.w,this.h,aE.outlineColour,i,j,aF)};x.Active=function(aE,i,j){return(i>=this.x&&j>=this.y&&i<=this.x+this.w&&j<=this.y+this.h)};x.PreDraw=x.PostDraw=x.LastDraw=ax;function e(aF,aP,aL,aO,aM,aG,aE,aI,aN,aH,aK,j,aJ,i){this.tc=aF;this.image=null;this.text=aP;this.text_original=i;this.line_widths=[];this.title=aL.title||null;this.a=aL;this.position=new ac(aO[0],aO[1],aO[2]);this.x=this.y=this.z=0;this.w=aM;this.h=aG;this.colour=aE||aF.textColour;this.bgColour=aI||aF.bgColour;this.bgRadius=aN|0;this.bgOutline=aH||this.colour;this.bgOutlineThickness=aK|0;this.textFont=j||aF.textFont;this.padding=aJ|0;this.sc=this.alpha=1;this.weighted=!aF.weight}c=e.prototype;c.Init=function(j){var i=this.tc;this.outline=new I(i,this);this.textHeight=i.textHeight;if(this.HasText()){this.Measure(i.ctxt,i)}else{this.w=this.iw;this.h=this.ih}this.SetShadowColour=i.shadowAlpha?this.SetShadowColourAlpha:this.SetShadowColourFixed;this.SetDraw(i)};c.Draw=ax;c.HasText=function(){return this.text&&this.text[0].length>0};c.EqualTo=function(aE){var j=aE.getElementsByTagName("img");if(this.a.href!=aE.href){return 0}if(j.length){return this.image.src==j[0].src}return(aE.innerText||aE.textContent)==this.text_original};c.SetImage=function(j){this.image=this.fimage=j};c.SetDraw=function(i){this.Draw=this.fimage?(i.ie>7?this.DrawImageIE:this.DrawImage):this.DrawText;i.noSelect&&(this.CheckActive=ax)};c.MeasureText=function(aH){var aF,aE=this.text.length,j=0,aG;for(aF=0;aF0){aF=v(aF,this.oimage.width,this.oimage.height)}else{this.oimage=v(this.oimage,aF.width,aF.height)}}}if(aF){this.fimage=aF;aI=this.fimage.width/aN;aL=this.fimage.height/aN}this.SetDraw(aM);aM.txtOpt=!!this.fimage}this.h=aL;this.w=aI};c.SetFont=function(j,aF,aE,i){this.textFont=j;this.colour=aF;this.bgColour=aE;this.bgOutline=i;this.Measure(this.tc.ctxt,this.tc)};c.SetWeight=function(aE){var j=this.tc,aG=j.weightMode.split(/[, ]/),i,aF,aH=aE.length;if(!this.HasText()){return}this.weighted=true;for(aF=0;aF0&&aF.weightSizeMax>aF.weightSizeMin){this.textHeight=aF.weightSize*(aF.weightSizeMin+(aF.weightSizeMax-aF.weightSizeMin)*i)}else{this.textHeight=s(1,aE*aF.weightSize)}}}}}};c.SetShadowColourFixed=function(aE,j,i){aE.shadowColor=j};c.SetShadowColourAlpha=function(aE,j,i){aE.shadowColor=T(j,i)};c.DrawText=function(aG,aJ,aF){var aK=this.tc,aI=this.x,aH=this.y,aL=this.sc,j,aE;aG.globalAlpha=this.alpha;aG.fillStyle=this.colour;aK.shadow&&this.SetShadowColour(aG,aK.shadow,this.alpha);aG.font=this.font;aI+=aJ/aL;aH+=(aF/aL)-(this.h/2);for(j=0;jthis.max_weight[aL]){this.max_weight[aL]=aI}if(!this.min_weight[aL]||aIthis.min_weight[aL]){j=1}}if(j){for(aE=0;aE=0&&this.my>=0&&this.taglist[aS].CheckActive(aU,aM,aL);if(aV&&aV.sc>aQ&&(!j||aV.z<=0)){aK=aV;aE=aS;aK.tag=this.taglist[aS];aQ=aV.sc}}this.active=aK}this.txtOpt||(this.shadow&&this.SetShadow(aU));aU.clearRect(0,0,aG,aN);for(aS=0;aS=this.fadeIn){this.fadeIn=0;this.fixedAlpha=1}else{this.fixedAlpha=j/this.fadeIn}}if(this.fixedAnim){if(!this.fixedAnim.transform){this.fixedAnim.transform=this.transform}aE=this.fixedAnim,j=F()-aE.t0,aG=aE.angle,i,aF=this.animTiming(aE.t,j);this.transform=aE.transform;if(j>=aE.t){this.fixedCallbackTag=aE.tag;this.fixedCallback=aE.cb;this.fixedAnim=this.yaw=this.pitch=0}else{aG*=aF}i=Q.Rotation(aG,aE.axis);this.transform=this.transform.mul(i);return(this.fixedAnim!=0)}return false};P.AnimatePosition=function(aE,aH,aF){var j=this,i=j.mx,aJ=j.my,aG,aI;if(!j.frozen&&i>=0&&aJ>=0&&iaE){i.yaw=aF>i.z0?i.yaw*i.decel:0}if(!i.ly&&j>aE){i.pitch=j>i.z0?i.pitch*i.decel:0}};P.Zoom=function(i){this.z2=this.z1*(1/i);this.drawn=0};P.Clicked=function(aE){var i=this.active;try{if(i&&i.tag){if(this.clickToFront===false||this.clickToFront===null){i.tag.Clicked(aE)}else{this.TagToFront(i.tag,this.clickToFront,function(){i.tag.Clicked(aE)},true)}}}catch(j){}};P.Wheel=function(j){var aE=this.zoom+this.zoomStep*(j?1:-1);this.zoom=aA(this.zoomMax,s(this.zoomMin,aE));this.Zoom(this.zoom)};P.BeginDrag=function(i){this.down=R(i,this.canvas);i.cancelBubble=true;i.returnValue=false;i.preventDefault&&i.preventDefault()};P.Drag=function(aG,aF){if(this.dragControl&&this.down){var aE=this.dragThreshold*this.dragThreshold,j=aF.x-this.down.x,i=aF.y-this.down.y;if(this.dragging||j*j+i*i>aE){this.dx=j;this.dy=i;this.dragging=1;this.down=aF}}};P.EndDrag=function(){var i=this.dragging;this.dragging=this.down=null;return i};P.Pause=function(){this.paused=true};P.Resume=function(){this.paused=false};P.SetSpeed=function(j){this.initial=j;this.yaw=j[0]*this.maxSpeed;this.pitch=j[1]*this.maxSpeed};P.FindTag=function(aE){if(!ag(aE)){return null}ag(aE.index)&&(aE=aE.index);if(!H(aE)){return this.taglist[aE]}var aF,aG,j;if(ag(aE.id)){aF="id",aG=aE.id}else{if(ag(aE.text)){aF="innerText",aG=aE.text}}for(j=0;j