Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jquery.tagcanvas.min.js 74KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280
  1. /**
  2. * Copyright (C) 2010-2015 Graham Breach
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * jQuery.tagcanvas 2.9
  19. * For more information, please contact <graham@goat1000.com>
  20. */
  21. (function($){
  22. "use strict";
  23. var i, j, abs = Math.abs, sin = Math.sin, cos = Math.cos, max = Math.max,
  24. min = Math.min, ceil = Math.ceil, sqrt = Math.sqrt, pow = Math.pow,
  25. hexlookup3 = {}, hexlookup2 = {}, hexlookup1 = {
  26. 0:"0,", 1:"17,", 2:"34,", 3:"51,", 4:"68,", 5:"85,",
  27. 6:"102,", 7:"119,", 8:"136,", 9:"153,", a:"170,", A:"170,",
  28. b:"187,", B:"187,", c:"204,", C:"204,", d:"221,", D:"221,",
  29. e:"238,", E:"238,", f:"255,", F:"255,"
  30. }, Oproto, Tproto, TCproto, Mproto, Vproto, TSproto, TCVproto,
  31. doc = document, ocanvas, handlers = {};
  32. for(i = 0; i < 256; ++i) {
  33. j = i.toString(16);
  34. if(i < 16)
  35. j = '0' + j;
  36. hexlookup2[j] = hexlookup2[j.toUpperCase()] = i.toString() + ',';
  37. }
  38. function Defined(d) {
  39. return typeof d != 'undefined';
  40. }
  41. function IsObject(o) {
  42. return typeof o == 'object' && o != null;
  43. }
  44. function Clamp(v, mn, mx) {
  45. return isNaN(v) ? mx : min(mx, max(mn, v));
  46. }
  47. function Nop() {
  48. return false;
  49. }
  50. function TimeNow() {
  51. return new Date().valueOf();
  52. }
  53. function SortList(l, f) {
  54. var nl = [], tl = l.length, i;
  55. for(i = 0; i < tl; ++i)
  56. nl.push(l[i]);
  57. nl.sort(f);
  58. return nl;
  59. }
  60. function Shuffle(a) {
  61. var i = a.length-1, t, p;
  62. while(i) {
  63. p = ~~(Math.random()*i);
  64. t = a[i];
  65. a[i] = a[p];
  66. a[p] = t;
  67. --i;
  68. }
  69. }
  70. function Vector(x, y, z) {
  71. this.x = x;
  72. this.y = y;
  73. this.z = z;
  74. }
  75. Vproto = Vector.prototype;
  76. Vproto.length = function() {
  77. return sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  78. };
  79. Vproto.dot = function(v) {
  80. return this.x * v.x + this.y * v.y + this.z * v.z;
  81. };
  82. Vproto.cross = function(v) {
  83. var x = this.y * v.z - this.z * v.y,
  84. y = this.z * v.x - this.x * v.z,
  85. z = this.x * v.y - this.y * v.x;
  86. return new Vector(x, y, z);
  87. };
  88. Vproto.angle = function(v) {
  89. var dot = this.dot(v), ac;
  90. if(dot == 0)
  91. return Math.PI / 2.0;
  92. ac = dot / (this.length() * v.length());
  93. if(ac >= 1)
  94. return 0;
  95. if(ac <= -1)
  96. return Math.PI;
  97. return Math.acos(ac);
  98. };
  99. Vproto.unit = function() {
  100. var l = this.length();
  101. return new Vector(this.x / l, this.y / l, this.z / l);
  102. };
  103. function MakeVector(lg, lt) {
  104. lt = lt * Math.PI / 180;
  105. lg = lg * Math.PI / 180;
  106. var x = sin(lg) * cos(lt), y = -sin(lt), z = -cos(lg) * cos(lt);
  107. return new Vector(x, y, z);
  108. }
  109. function Matrix(a) {
  110. this[1] = {1: a[0], 2: a[1], 3: a[2]};
  111. this[2] = {1: a[3], 2: a[4], 3: a[5]};
  112. this[3] = {1: a[6], 2: a[7], 3: a[8]};
  113. }
  114. Mproto = Matrix.prototype;
  115. Matrix.Identity = function() {
  116. return new Matrix([1,0,0, 0,1,0, 0,0,1]);
  117. };
  118. Matrix.Rotation = function(angle, u) {
  119. var sina = sin(angle), cosa = cos(angle), mcos = 1 - cosa;
  120. return new Matrix([
  121. cosa + pow(u.x, 2) * mcos, u.x * u.y * mcos - u.z * sina, u.x * u.z * mcos + u.y * sina,
  122. u.y * u.x * mcos + u.z * sina, cosa + pow(u.y, 2) * mcos, u.y * u.z * mcos - u.x * sina,
  123. u.z * u.x * mcos - u.y * sina, u.z * u.y * mcos + u.x * sina, cosa + pow(u.z, 2) * mcos
  124. ]);
  125. }
  126. Mproto.mul = function(m) {
  127. var a = [], i, j, mmatrix = (m.xform ? 1 : 0);
  128. for(i = 1; i <= 3; ++i)
  129. for(j = 1; j <= 3; ++j) {
  130. if(mmatrix)
  131. a.push(this[i][1] * m[1][j] +
  132. this[i][2] * m[2][j] +
  133. this[i][3] * m[3][j]);
  134. else
  135. a.push(this[i][j] * m);
  136. }
  137. return new Matrix(a);
  138. };
  139. Mproto.xform = function(p) {
  140. var a = {}, x = p.x, y = p.y, z = p.z;
  141. a.x = x * this[1][1] + y * this[2][1] + z * this[3][1];
  142. a.y = x * this[1][2] + y * this[2][2] + z * this[3][2];
  143. a.z = x * this[1][3] + y * this[2][3] + z * this[3][3];
  144. return a;
  145. };
  146. function PointsOnSphere(n,xr,yr,zr,magic) {
  147. var i, y, r, phi, pts = [], off = 2/n, inc;
  148. inc = Math.PI * (3 - sqrt(5) + (parseFloat(magic) ? parseFloat(magic) : 0));
  149. for(i = 0; i < n; ++i) {
  150. y = i * off - 1 + (off / 2);
  151. r = sqrt(1 - y*y);
  152. phi = i * inc;
  153. pts.push([cos(phi) * r * xr, y * yr, sin(phi) * r * zr]);
  154. }
  155. return pts;
  156. }
  157. function Cylinder(n,o,xr,yr,zr,magic) {
  158. var phi, pts = [], off = 2/n, inc, i, j, k, l;
  159. inc = Math.PI * (3 - sqrt(5) + (parseFloat(magic) ? parseFloat(magic) : 0));
  160. for(i = 0; i < n; ++i) {
  161. j = i * off - 1 + (off / 2);
  162. phi = i * inc;
  163. k = cos(phi);
  164. l = sin(phi);
  165. pts.push(o ? [j * xr, k * yr, l * zr] : [k * xr, j * yr, l * zr]);
  166. }
  167. return pts;
  168. }
  169. function Ring(o, n, xr, yr, zr, j) {
  170. var phi, pts = [], inc = Math.PI * 2 / n, i, k, l;
  171. for(i = 0; i < n; ++i) {
  172. phi = i * inc;
  173. k = cos(phi);
  174. l = sin(phi);
  175. pts.push(o ? [j * xr, k * yr, l * zr] : [k * xr, j * yr, l * zr]);
  176. }
  177. return pts;
  178. }
  179. function PointsOnCylinderV(n,xr,yr,zr,m) { return Cylinder(n, 0, xr, yr, zr, m) }
  180. function PointsOnCylinderH(n,xr,yr,zr,m) { return Cylinder(n, 1, xr, yr, zr, m) }
  181. function PointsOnRingV(n, xr, yr, zr, offset) {
  182. offset = isNaN(offset) ? 0 : offset * 1;
  183. return Ring(0, n, xr, yr, zr, offset);
  184. }
  185. function PointsOnRingH(n, xr, yr, zr, offset) {
  186. offset = isNaN(offset) ? 0 : offset * 1;
  187. return Ring(1, n, xr, yr, zr, offset);
  188. }
  189. function CentreImage(t) {
  190. var i = new Image;
  191. i.onload = function() {
  192. var dx = i.width / 2, dy = i.height / 2;
  193. t.centreFunc = function(c, w, h, cx, cy) {
  194. c.setTransform(1, 0, 0, 1, 0, 0);
  195. c.globalAlpha = 1;
  196. c.drawImage(i, cx - dx, cy - dy);
  197. };
  198. };
  199. i.src = t.centreImage;
  200. }
  201. function SetAlpha(c,a) {
  202. var d = c, p1, p2, ae = (a*1).toPrecision(3) + ')';
  203. if(c[0] === '#') {
  204. if(!hexlookup3[c])
  205. if(c.length === 4)
  206. hexlookup3[c] = 'rgba(' + hexlookup1[c[1]] + hexlookup1[c[2]] + hexlookup1[c[3]];
  207. else
  208. hexlookup3[c] = 'rgba(' + hexlookup2[c.substr(1,2)] + hexlookup2[c.substr(3,2)] + hexlookup2[c.substr(5,2)];
  209. d = hexlookup3[c] + ae;
  210. } else if(c.substr(0,4) === 'rgb(' || c.substr(0,4) === 'hsl(') {
  211. d = (c.replace('(','a(').replace(')', ',' + ae));
  212. } else if(c.substr(0,5) === 'rgba(' || c.substr(0,5) === 'hsla(') {
  213. p1 = c.lastIndexOf(',') + 1, p2 = c.indexOf(')');
  214. a *= parseFloat(c.substring(p1,p2));
  215. d = c.substr(0,p1) + a.toPrecision(3) + ')';
  216. }
  217. return d;
  218. }
  219. function NewCanvas(w,h) {
  220. // if using excanvas, give up now
  221. if(window.G_vmlCanvasManager)
  222. return null;
  223. var c = doc.createElement('canvas');
  224. c.width = w;
  225. c.height = h;
  226. return c;
  227. }
  228. // I think all browsers pass this test now...
  229. function ShadowAlphaBroken() {
  230. var cv = NewCanvas(3,3), c, i;
  231. if(!cv)
  232. return false;
  233. c = cv.getContext('2d');
  234. c.strokeStyle = '#000';
  235. c.shadowColor = '#fff';
  236. c.shadowBlur = 3;
  237. c.globalAlpha = 0;
  238. c.strokeRect(2,2,2,2);
  239. c.globalAlpha = 1;
  240. i = c.getImageData(2,2,1,1);
  241. cv = null;
  242. return (i.data[0] > 0);
  243. }
  244. function SetGradient(c, l, o, g) {
  245. var gd = c.createLinearGradient(0, 0, l, 0), i;
  246. for(i in g)
  247. gd.addColorStop(1 - i, g[i]);
  248. c.fillStyle = gd;
  249. c.fillRect(0, o, l, 1);
  250. }
  251. function FindGradientColour(tc, p, r) {
  252. var l = 1024, h = 1, gl = tc.weightGradient, cv, c, i, d;
  253. if(tc.gCanvas) {
  254. c = tc.gCanvas.getContext('2d');
  255. h = tc.gCanvas.height;
  256. } else {
  257. if(IsObject(gl[0]))
  258. h = gl.length;
  259. else
  260. gl = [gl];
  261. tc.gCanvas = cv = NewCanvas(l, h);
  262. if(!cv)
  263. return null;
  264. c = cv.getContext('2d');
  265. for(i = 0; i < h; ++i)
  266. SetGradient(c, l, i, gl[i]);
  267. }
  268. r = max(min(r || 0, h - 1), 0);
  269. d = c.getImageData(~~((l - 1) * p), r, 1, 1).data;
  270. return 'rgba(' + d[0] + ',' + d[1] + ',' + d[2] + ',' + (d[3]/255) + ')';
  271. }
  272. function TextSet(ctxt, font, colour, strings, padx, pady, shadowColour,
  273. shadowBlur, shadowOffsets, maxWidth, widths, align) {
  274. var xo = padx + (shadowBlur || 0) +
  275. (shadowOffsets.length && shadowOffsets[0] < 0 ? abs(shadowOffsets[0]) : 0),
  276. yo = pady + (shadowBlur || 0) +
  277. (shadowOffsets.length && shadowOffsets[1] < 0 ? abs(shadowOffsets[1]) : 0), i, xc;
  278. ctxt.font = font;
  279. ctxt.textBaseline = 'top';
  280. ctxt.fillStyle = colour;
  281. shadowColour && (ctxt.shadowColor = shadowColour);
  282. shadowBlur && (ctxt.shadowBlur = shadowBlur);
  283. shadowOffsets.length && (ctxt.shadowOffsetX = shadowOffsets[0],
  284. ctxt.shadowOffsetY = shadowOffsets[1]);
  285. for(i = 0; i < strings.length; ++i) {
  286. xc = 0;
  287. if(widths) {
  288. if('right' == align) {
  289. xc = maxWidth - widths[i];
  290. } else if('centre' == align) {
  291. xc = (maxWidth - widths[i]) / 2;
  292. }
  293. }
  294. ctxt.fillText(strings[i], xo + xc, yo);
  295. yo += parseInt(font);
  296. }
  297. }
  298. function RRect(c, x, y, w, h, r, s) {
  299. if(r) {
  300. c.beginPath();
  301. c.moveTo(x, y + h - r);
  302. c.arcTo(x, y, x + r, y, r);
  303. c.arcTo(x + w, y, x + w, y + r, r);
  304. c.arcTo(x + w, y + h, x + w - r, y + h, r);
  305. c.arcTo(x, y + h, x, y + h - r, r);
  306. c.closePath();
  307. c[s ? 'stroke' : 'fill']();
  308. } else {
  309. c[s ? 'strokeRect' : 'fillRect'](x, y, w, h);
  310. }
  311. }
  312. function TextCanvas(strings, font, w, h, maxWidth, stringWidths, align, valign,
  313. scale) {
  314. this.strings = strings;
  315. this.font = font;
  316. this.width = w;
  317. this.height = h;
  318. this.maxWidth = maxWidth;
  319. this.stringWidths = stringWidths;
  320. this.align = align;
  321. this.valign = valign;
  322. this.scale = scale;
  323. }
  324. TCVproto = TextCanvas.prototype;
  325. TCVproto.SetImage = function(image, w, h, position, padding, align, valign,
  326. scale) {
  327. this.image = image;
  328. this.iwidth = w * this.scale;
  329. this.iheight = h * this.scale;
  330. this.ipos = position;
  331. this.ipad = padding * this.scale;
  332. this.iscale = scale;
  333. this.ialign = align;
  334. this.ivalign = valign;
  335. };
  336. TCVproto.Align = function(size, space, a) {
  337. var pos = 0;
  338. if(a == 'right' || a == 'bottom')
  339. pos = space - size;
  340. else if(a != 'left' && a != 'top')
  341. pos = (space - size) / 2;
  342. return pos;
  343. };
  344. TCVproto.Create = function(colour, bgColour, bgOutline, bgOutlineThickness,
  345. shadowColour, shadowBlur, shadowOffsets, padding, radius) {
  346. var cv, cw, ch, c, x1, x2, y1, y2, offx, offy, ix, iy, iw, ih, rr,
  347. sox = abs(shadowOffsets[0]), soy = abs(shadowOffsets[1]), shadowcv, shadowc;
  348. padding = max(padding, sox + shadowBlur, soy + shadowBlur);
  349. x1 = 2 * (padding + bgOutlineThickness);
  350. y1 = 2 * (padding + bgOutlineThickness);
  351. cw = this.width + x1;
  352. ch = this.height + y1;
  353. offx = offy = padding + bgOutlineThickness;
  354. if(this.image) {
  355. ix = iy = padding + bgOutlineThickness;
  356. iw = this.iwidth;
  357. ih = this.iheight;
  358. if(this.ipos == 'top' || this.ipos == 'bottom') {
  359. if(iw < this.width)
  360. ix += this.Align(iw, this.width, this.ialign);
  361. else
  362. offx += this.Align(this.width, iw, this.align);
  363. if(this.ipos == 'top')
  364. offy += ih + this.ipad;
  365. else
  366. iy += this.height + this.ipad;
  367. cw = max(cw, iw + x1);
  368. ch += ih + this.ipad;
  369. } else {
  370. if(ih < this.height)
  371. iy += this.Align(ih, this.height, this.ivalign);
  372. else
  373. offy += this.Align(this.height, ih, this.valign);
  374. if(this.ipos == 'right')
  375. ix += this.width + this.ipad;
  376. else
  377. offx += iw + this.ipad;
  378. cw += iw + this.ipad;
  379. ch = max(ch, ih + y1);
  380. }
  381. }
  382. cv = NewCanvas(cw, ch);
  383. if(!cv)
  384. return null;
  385. x1 = y1 = bgOutlineThickness / 2;
  386. x2 = cw - bgOutlineThickness;
  387. y2 = ch - bgOutlineThickness;
  388. rr = min(radius, x2 / 2, y2 / 2);
  389. c = cv.getContext('2d');
  390. if(bgColour) {
  391. c.fillStyle = bgColour;
  392. RRect(c, x1, y1, x2, y2, rr);
  393. }
  394. if(bgOutlineThickness) {
  395. c.strokeStyle = bgOutline;
  396. c.lineWidth = bgOutlineThickness;
  397. RRect(c, x1, y1, x2, y2, rr, true);
  398. }
  399. if(shadowBlur || sox || soy) {
  400. // use a transparent canvas to draw on
  401. shadowcv = NewCanvas(cw, ch);
  402. if(shadowcv) {
  403. shadowc = c;
  404. c = shadowcv.getContext('2d');
  405. }
  406. }
  407. // don't use TextSet shadow support because it adds space for shadow
  408. TextSet(c, this.font, colour, this.strings, offx, offy, 0, 0, [],
  409. this.maxWidth, this.stringWidths, this.align);
  410. if(this.image)
  411. c.drawImage(this.image, ix, iy, iw, ih);
  412. if(shadowc) {
  413. // draw the text and image with the added shadow
  414. c = shadowc;
  415. shadowColour && (c.shadowColor = shadowColour);
  416. shadowBlur && (c.shadowBlur = shadowBlur);
  417. c.shadowOffsetX = shadowOffsets[0];
  418. c.shadowOffsetY = shadowOffsets[1];
  419. c.drawImage(shadowcv, 0, 0);
  420. }
  421. return cv;
  422. };
  423. function ExpandImage(i, w, h) {
  424. var cv = NewCanvas(w, h), c;
  425. if(!cv)
  426. return null;
  427. c = cv.getContext('2d');
  428. c.drawImage(i, (w - i.width) / 2, (h - i.height) / 2);
  429. return cv;
  430. }
  431. function ScaleImage(i, w, h) {
  432. var cv = NewCanvas(w, h), c;
  433. if(!cv)
  434. return null;
  435. c = cv.getContext('2d');
  436. c.drawImage(i, 0, 0, w, h);
  437. return cv;
  438. }
  439. function AddBackgroundToImage(i, w, h, scale, colour, othickness, ocolour,
  440. padding, radius, ofill) {
  441. var cw = w + ((2 * padding) + othickness) * scale,
  442. ch = h + ((2 * padding) + othickness) * scale,
  443. cv = NewCanvas(cw, ch), c, x1, y1, x2, y2, ocanvas, cc, rr;
  444. if(!cv)
  445. return null;
  446. othickness *= scale;
  447. radius *= scale;
  448. x1 = y1 = othickness / 2;
  449. x2 = cw - othickness;
  450. y2 = ch - othickness;
  451. padding = (padding * scale) + x1; // add space for outline
  452. c = cv.getContext('2d');
  453. rr = min(radius, x2 / 2, y2 / 2);
  454. if(colour) {
  455. c.fillStyle = colour;
  456. RRect(c, x1, y1, x2, y2, rr);
  457. }
  458. if(othickness) {
  459. c.strokeStyle = ocolour;
  460. c.lineWidth = othickness;
  461. RRect(c, x1, y1, x2, y2, rr, true);
  462. }
  463. if(ofill) {
  464. // use compositing to colour in the image and border
  465. ocanvas = NewCanvas(cw, ch);
  466. cc = ocanvas.getContext('2d');
  467. cc.drawImage(i, padding, padding, w, h);
  468. cc.globalCompositeOperation = 'source-in';
  469. cc.fillStyle = ocolour;
  470. cc.fillRect(0, 0, cw, ch);
  471. cc.globalCompositeOperation = 'destination-over';
  472. cc.drawImage(cv, 0, 0);
  473. cc.globalCompositeOperation = 'source-over';
  474. c.drawImage(ocanvas, 0, 0);
  475. } else {
  476. c.drawImage(i, padding, padding, i.width, i.height);
  477. }
  478. return {image: cv, width: cw / scale, height: ch / scale};
  479. }
  480. /**
  481. * Rounds off the corners of an image
  482. */
  483. function RoundImage(i, r, iw, ih, s) {
  484. var cv, c, r1 = parseFloat(r), l = max(iw, ih);
  485. cv = NewCanvas(iw, ih);
  486. if(!cv)
  487. return null;
  488. if(r.indexOf('%') > 0)
  489. r1 = l * r1 / 100;
  490. else
  491. r1 = r1 * s;
  492. c = cv.getContext('2d');
  493. c.globalCompositeOperation = 'source-over';
  494. c.fillStyle = '#fff';
  495. if(r1 >= l/2) {
  496. r1 = min(iw,ih) / 2;
  497. c.beginPath();
  498. c.moveTo(iw/2,ih/2);
  499. c.arc(iw/2,ih/2,r1,0,2*Math.PI,false);
  500. c.fill();
  501. c.closePath();
  502. } else {
  503. r1 = min(iw/2,ih/2,r1);
  504. RRect(c, 0, 0, iw, ih, r1, true);
  505. c.fill();
  506. }
  507. c.globalCompositeOperation = 'source-in';
  508. c.drawImage(i, 0, 0, iw, ih);
  509. return cv;
  510. }
  511. /**
  512. * Creates a new canvas containing the image and its shadow
  513. * Returns an object containing the image and its dimensions at z=0
  514. */
  515. function AddShadowToImage(i, w, h, scale, sc, sb, so) {
  516. var sw = abs(so[0]), sh = abs(so[1]),
  517. cw = w + (sw > sb ? sw + sb : sb * 2) * scale,
  518. ch = h + (sh > sb ? sh + sb : sb * 2) * scale,
  519. xo = scale * ((sb || 0) + (so[0] < 0 ? sw : 0)),
  520. yo = scale * ((sb || 0) + (so[1] < 0 ? sh : 0)), cv, c;
  521. cv = NewCanvas(cw, ch);
  522. if(!cv)
  523. return null;
  524. c = cv.getContext('2d');
  525. sc && (c.shadowColor = sc);
  526. sb && (c.shadowBlur = sb * scale);
  527. so && (c.shadowOffsetX = so[0] * scale, c.shadowOffsetY = so[1] * scale);
  528. c.drawImage(i, xo, yo, w, h);
  529. return {image: cv, width: cw / scale, height: ch / scale};
  530. }
  531. function FindTextBoundingBox(s,f,ht) {
  532. var w = parseInt(s.toString().length * ht), h = parseInt(ht * 2 * s.length),
  533. cv = NewCanvas(w,h), c, idata, w1, h1, x, y, i, ex;
  534. if(!cv)
  535. return null;
  536. c = cv.getContext('2d');
  537. c.fillStyle = '#000';
  538. c.fillRect(0,0,w,h);
  539. TextSet(c,ht + 'px ' + f,'#fff',s,0,0,0,0,[],'centre')
  540. idata = c.getImageData(0,0,w,h);
  541. w1 = idata.width; h1 = idata.height;
  542. ex = {
  543. min: { x: w1, y: h1 },
  544. max: { x: -1, y: -1 }
  545. };
  546. for(y = 0; y < h1; ++y) {
  547. for(x = 0; x < w1; ++x) {
  548. i = (y * w1 + x) * 4;
  549. if(idata.data[i+1] > 0) {
  550. if(x < ex.min.x) ex.min.x = x;
  551. if(x > ex.max.x) ex.max.x = x;
  552. if(y < ex.min.y) ex.min.y = y;
  553. if(y > ex.max.y) ex.max.y = y;
  554. }
  555. }
  556. }
  557. // device pixels might not be css pixels
  558. if(w1 != w) {
  559. ex.min.x *= (w / w1);
  560. ex.max.x *= (w / w1);
  561. }
  562. if(h1 != h) {
  563. ex.min.y *= (w / h1);
  564. ex.max.y *= (w / h1);
  565. }
  566. cv = null;
  567. return ex;
  568. }
  569. function FixFont(f) {
  570. return "'" + f.replace(/(\'|\")/g,'').replace(/\s*,\s*/g, "', '") + "'";
  571. }
  572. function AddHandler(h,f,e) {
  573. e = e || doc;
  574. if(e.addEventListener)
  575. e.addEventListener(h,f,false);
  576. else
  577. e.attachEvent('on' + h, f);
  578. }
  579. function RemoveHandler(h,f,e) {
  580. e = e || doc;
  581. if(e.removeEventListener)
  582. e.removeEventListener(h, f);
  583. else
  584. e.detachEvent('on' + h, f);
  585. }
  586. function AddImage(i, o, t, tc) {
  587. var s = tc.imageScale, mscale, ic, bc, oc, iw, ih;
  588. // image not loaded, wait for image onload
  589. if(!o.complete)
  590. return AddHandler('load',function() { AddImage(i,o,t,tc); }, o);
  591. if(!i.complete)
  592. return AddHandler('load',function() { AddImage(i,o,t,tc); }, i);
  593. // Yes, this does look like nonsense, but it makes sure that both the
  594. // width and height are actually set and not just calculated. This is
  595. // required to keep proportional sizes when the images are hidden, so
  596. // the images can be used again for another cloud.
  597. o.width = o.width;
  598. o.height = o.height;
  599. if(s) {
  600. i.width = o.width * s;
  601. i.height = o.height * s;
  602. }
  603. // the standard width of the image, with imageScale applied
  604. t.iw = i.width;
  605. t.ih = i.height;
  606. if(tc.txtOpt) {
  607. ic = i;
  608. mscale = tc.zoomMax * tc.txtScale;
  609. iw = t.iw * mscale;
  610. ih = t.ih * mscale;
  611. if(iw < o.naturalWidth || ih < o.naturalHeight) {
  612. ic = ScaleImage(i, iw, ih);
  613. if(ic)
  614. t.fimage = ic;
  615. } else {
  616. iw = t.iw;
  617. ih = t.ih;
  618. mscale = 1;
  619. }
  620. if(parseFloat(tc.imageRadius))
  621. t.image = t.fimage = i = RoundImage(t.image, tc.imageRadius, iw, ih, mscale);
  622. if(!t.HasText()) {
  623. if(tc.shadow) {
  624. ic = AddShadowToImage(t.image, iw, ih, mscale, tc.shadow, tc.shadowBlur,
  625. tc.shadowOffset);
  626. if(ic) {
  627. t.fimage = ic.image;
  628. t.w = ic.width;
  629. t.h = ic.height;
  630. }
  631. }
  632. if(tc.bgColour || tc.bgOutlineThickness) {
  633. bc = tc.bgColour == 'tag' ? GetProperty(t.a, 'background-color') :
  634. tc.bgColour;
  635. oc = tc.bgOutline == 'tag' ? GetProperty(t.a, 'color') :
  636. (tc.bgOutline || tc.textColour);
  637. iw = t.fimage.width;
  638. ih = t.fimage.height;
  639. if(tc.outlineMethod == 'colour') {
  640. // create the outline version first, using the current image state
  641. ic = AddBackgroundToImage(t.fimage, iw, ih, mscale, bc,
  642. tc.bgOutlineThickness, t.outline.colour, tc.padding, tc.bgRadius, 1);
  643. if(ic)
  644. t.oimage = ic.image;
  645. }
  646. ic = AddBackgroundToImage(t.fimage, iw, ih, mscale, bc,
  647. tc.bgOutlineThickness, oc, tc.padding, tc.bgRadius);
  648. if(ic) {
  649. t.fimage = ic.image;
  650. t.w = ic.width;
  651. t.h = ic.height;
  652. }
  653. }
  654. if(tc.outlineMethod == 'size') {
  655. if(tc.outlineIncrease > 0) {
  656. t.iw += 2 * tc.outlineIncrease;
  657. t.ih += 2 * tc.outlineIncrease;
  658. iw = mscale * t.iw;
  659. ih = mscale * t.ih;
  660. ic = ScaleImage(t.fimage, iw, ih);
  661. t.oimage = ic;
  662. t.fimage = ExpandImage(t.fimage, t.oimage.width, t.oimage.height);
  663. } else {
  664. iw = mscale * (t.iw + (2 * tc.outlineIncrease));
  665. ih = mscale * (t.ih + (2 * tc.outlineIncrease));
  666. ic = ScaleImage(t.fimage, iw, ih);
  667. t.oimage = ExpandImage(ic, t.fimage.width, t.fimage.height);
  668. }
  669. }
  670. }
  671. }
  672. t.Init();
  673. }
  674. function GetProperty(e,p) {
  675. var dv = doc.defaultView, pc = p.replace(/\-([a-z])/g,function(a){return a.charAt(1).toUpperCase()});
  676. return (dv && dv.getComputedStyle && dv.getComputedStyle(e,null).getPropertyValue(p)) ||
  677. (e.currentStyle && e.currentStyle[pc]);
  678. }
  679. function FindWeight(a, wFrom, tHeight) {
  680. var w = 1, p;
  681. if(wFrom) {
  682. w = 1 * (a.getAttribute(wFrom) || tHeight);
  683. } else if(p = GetProperty(a,'font-size')) {
  684. w = (p.indexOf('px') > -1 && p.replace('px','') * 1) ||
  685. (p.indexOf('pt') > -1 && p.replace('pt','') * 1.25) ||
  686. p * 3.3;
  687. }
  688. return w;
  689. }
  690. function EventToCanvasId(e) {
  691. return e.target && Defined(e.target.id) ? e.target.id :
  692. e.srcElement.parentNode.id;
  693. }
  694. function EventXY(e, c) {
  695. var xy, p, xmul = parseInt(GetProperty(c, 'width')) / c.width,
  696. ymul = parseInt(GetProperty(c, 'height')) / c.height;
  697. if(Defined(e.offsetX)) {
  698. xy = {x: e.offsetX, y: e.offsetY};
  699. } else {
  700. p = AbsPos(c.id);
  701. if(Defined(e.changedTouches))
  702. e = e.changedTouches[0];
  703. if(e.pageX)
  704. xy = {x: e.pageX - p.x, y: e.pageY - p.y};
  705. }
  706. if(xy && xmul && ymul) {
  707. xy.x /= xmul;
  708. xy.y /= ymul;
  709. }
  710. return xy;
  711. }
  712. function MouseOut(e) {
  713. var cv = e.target || e.fromElement.parentNode, tc = TagCanvas.tc[cv.id];
  714. if(tc) {
  715. tc.mx = tc.my = -1;
  716. tc.UnFreeze();
  717. tc.EndDrag();
  718. }
  719. }
  720. function MouseMove(e) {
  721. var i, t = TagCanvas, tc, p, tg = EventToCanvasId(e);
  722. for(i in t.tc) {
  723. tc = t.tc[i];
  724. if(tc.tttimer) {
  725. clearTimeout(tc.tttimer);
  726. tc.tttimer = null;
  727. }
  728. }
  729. if(tg && t.tc[tg]) {
  730. tc = t.tc[tg];
  731. if(p = EventXY(e, tc.canvas)) {
  732. tc.mx = p.x;
  733. tc.my = p.y;
  734. tc.Drag(e, p);
  735. }
  736. tc.drawn = 0;
  737. }
  738. }
  739. function MouseDown(e) {
  740. var t = TagCanvas, cb = doc.addEventListener ? 0 : 1,
  741. tg = EventToCanvasId(e);
  742. if(tg && e.button == cb && t.tc[tg]) {
  743. t.tc[tg].BeginDrag(e);
  744. }
  745. }
  746. function MouseUp(e) {
  747. var t = TagCanvas, cb = doc.addEventListener ? 0 : 1,
  748. tg = EventToCanvasId(e), tc;
  749. if(tg && e.button == cb && t.tc[tg]) {
  750. tc = t.tc[tg];
  751. MouseMove(e);
  752. if(!tc.EndDrag() && !tc.touchState)
  753. tc.Clicked(e);
  754. }
  755. }
  756. function TouchDown(e) {
  757. var tg = EventToCanvasId(e), tc = (tg && TagCanvas.tc[tg]), p;
  758. if(tc && e.changedTouches) {
  759. if(e.touches.length == 1 && tc.touchState == 0) {
  760. tc.touchState = 1;
  761. tc.BeginDrag(e);
  762. if(p = EventXY(e, tc.canvas)) {
  763. tc.mx = p.x;
  764. tc.my = p.y;
  765. tc.drawn = 0;
  766. }
  767. } else if(e.targetTouches.length == 2 && tc.pinchZoom) {
  768. tc.touchState = 3;
  769. tc.EndDrag();
  770. tc.BeginPinch(e);
  771. } else {
  772. tc.EndDrag();
  773. tc.EndPinch();
  774. tc.touchState = 0;
  775. }
  776. }
  777. }
  778. function TouchUp(e) {
  779. var tg = EventToCanvasId(e), tc = (tg && TagCanvas.tc[tg]);
  780. if(tc && e.changedTouches) {
  781. switch(tc.touchState) {
  782. case 1:
  783. tc.Draw();
  784. tc.Clicked();
  785. break;
  786. case 2:
  787. tc.EndDrag();
  788. break;
  789. case 3:
  790. tc.EndPinch();
  791. }
  792. tc.touchState = 0;
  793. }
  794. }
  795. function TouchMove(e) {
  796. var i, t = TagCanvas, tc, p, tg = EventToCanvasId(e);
  797. for(i in t.tc) {
  798. tc = t.tc[i];
  799. if(tc.tttimer) {
  800. clearTimeout(tc.tttimer);
  801. tc.tttimer = null;
  802. }
  803. }
  804. tc = (tg && t.tc[tg]);
  805. if(tc && e.changedTouches && tc.touchState) {
  806. switch(tc.touchState) {
  807. case 1:
  808. case 2:
  809. if(p = EventXY(e, tc.canvas)) {
  810. tc.mx = p.x;
  811. tc.my = p.y;
  812. if(tc.Drag(e, p))
  813. tc.touchState = 2;
  814. }
  815. break;
  816. case 3:
  817. tc.Pinch(e);
  818. }
  819. tc.drawn = 0;
  820. }
  821. }
  822. function MouseWheel(e) {
  823. var t = TagCanvas, tg = EventToCanvasId(e);
  824. if(tg && t.tc[tg]) {
  825. e.cancelBubble = true;
  826. e.returnValue = false;
  827. e.preventDefault && e.preventDefault();
  828. t.tc[tg].Wheel((e.wheelDelta || e.detail) > 0);
  829. }
  830. }
  831. function Scroll(e) {
  832. var i, t = TagCanvas;
  833. clearTimeout(t.scrollTimer);
  834. for(i in t.tc) {
  835. t.tc[i].Pause();
  836. }
  837. t.scrollTimer = setTimeout(function() {
  838. var i, t = TagCanvas;
  839. for(i in t.tc) {
  840. t.tc[i].Resume();
  841. }
  842. }, t.scrollPause);
  843. }
  844. function DrawCanvas() {
  845. DrawCanvasRAF(TimeNow());
  846. }
  847. function DrawCanvasRAF(t) {
  848. var tc = TagCanvas.tc, i;
  849. TagCanvas.NextFrame(TagCanvas.interval);
  850. t = t || TimeNow();
  851. for(i in tc)
  852. tc[i].Draw(t);
  853. }
  854. function AbsPos(id) {
  855. var e = doc.getElementById(id), r = e.getBoundingClientRect(),
  856. dd = doc.documentElement, b = doc.body, w = window,
  857. xs = w.pageXOffset || dd.scrollLeft,
  858. ys = w.pageYOffset || dd.scrollTop,
  859. xo = dd.clientLeft || b.clientLeft,
  860. yo = dd.clientTop || b.clientTop;
  861. return { x: r.left + xs - xo, y: r.top + ys - yo };
  862. }
  863. function Project(tc,p1,sx,sy) {
  864. var m = tc.radius * tc.z1 / (tc.z1 + tc.z2 + p1.z);
  865. return {
  866. x: p1.x * m * sx,
  867. y: p1.y * m * sy,
  868. z: p1.z,
  869. w: (tc.z1 - p1.z) / tc.z2
  870. };
  871. }
  872. /**
  873. * @constructor
  874. * for recursively splitting tag contents on <br> tags
  875. */
  876. function TextSplitter(e) {
  877. this.e = e;
  878. this.br = 0;
  879. this.line = [];
  880. this.text = [];
  881. this.original = e.innerText || e.textContent;
  882. }
  883. TSproto = TextSplitter.prototype;
  884. TSproto.Empty = function() {
  885. for(var i = 0; i < this.text.length; ++i)
  886. if(this.text[i].length)
  887. return false;
  888. return true;
  889. };
  890. TSproto.Lines = function(e) {
  891. var r = e ? 1 : 0, cn, cl, i;
  892. e = e || this.e;
  893. cn = e.childNodes;
  894. cl = cn.length;
  895. for(i = 0; i < cl; ++i) {
  896. if(cn[i].nodeName == 'BR') {
  897. this.text.push(this.line.join(' '));
  898. this.br = 1;
  899. } else if(cn[i].nodeType == 3) {
  900. if(this.br) {
  901. this.line = [cn[i].nodeValue];
  902. this.br = 0;
  903. } else {
  904. this.line.push(cn[i].nodeValue);
  905. }
  906. } else {
  907. this.Lines(cn[i]);
  908. }
  909. }
  910. r || this.br || this.text.push(this.line.join(' '));
  911. return this.text;
  912. };
  913. TSproto.SplitWidth = function(w, c, f, h) {
  914. var i, j, words, text = [];
  915. c.font = h + 'px ' + f;
  916. for(i = 0; i < this.text.length; ++i) {
  917. words = this.text[i].split(/\s+/);
  918. this.line = [words[0]];
  919. for(j = 1; j < words.length; ++j) {
  920. if(c.measureText(this.line.join(' ') + ' ' + words[j]).width > w) {
  921. text.push(this.line.join(' '));
  922. this.line = [words[j]];
  923. } else {
  924. this.line.push(words[j]);
  925. }
  926. }
  927. text.push(this.line.join(' '));
  928. }
  929. return this.text = text;
  930. };
  931. /**
  932. * @constructor
  933. */
  934. function Outline(tc,t) {
  935. this.ts = null;
  936. this.tc = tc;
  937. this.tag = t;
  938. this.x = this.y = this.w = this.h = this.sc = 1;
  939. this.z = 0;
  940. this.pulse = 1;
  941. this.pulsate = tc.pulsateTo < 1;
  942. this.colour = tc.outlineColour;
  943. this.adash = ~~tc.outlineDash;
  944. this.agap = ~~tc.outlineDashSpace || this.adash;
  945. this.aspeed = tc.outlineDashSpeed * 1;
  946. if(this.colour == 'tag')
  947. this.colour = GetProperty(t.a, 'color');
  948. else if(this.colour == 'tagbg')
  949. this.colour = GetProperty(t.a, 'background-color');
  950. this.Draw = this.pulsate ? this.DrawPulsate : this.DrawSimple;
  951. this.radius = tc.outlineRadius | 0;
  952. this.SetMethod(tc.outlineMethod);
  953. }
  954. Oproto = Outline.prototype;
  955. Oproto.SetMethod = function(om) {
  956. var methods = {
  957. block: ['PreDraw','DrawBlock'],
  958. colour: ['PreDraw','DrawColour'],
  959. outline: ['PostDraw','DrawOutline'],
  960. classic: ['LastDraw','DrawOutline'],
  961. size: ['PreDraw','DrawSize'],
  962. none: ['LastDraw']
  963. }, funcs = methods[om] || methods.outline;
  964. if(om == 'none') {
  965. this.Draw = function() { return 1; }
  966. } else {
  967. this.drawFunc = this[funcs[1]];
  968. }
  969. this[funcs[0]] = this.Draw;
  970. };
  971. Oproto.Update = function(x,y,w,h,sc,z,xo,yo) {
  972. var o = this.tc.outlineOffset, o2 = 2 * o;
  973. this.x = sc * x + xo - o;
  974. this.y = sc * y + yo - o;
  975. this.w = sc * w + o2;
  976. this.h = sc * h + o2;
  977. this.sc = sc; // used to determine frontmost
  978. this.z = z;
  979. };
  980. Oproto.Ants = function(c) {
  981. if(!this.adash)
  982. return;
  983. var l = this.adash, g = this.agap, s = this.aspeed, length = l + g,
  984. l1 = 0, l2 = l, g1 = g, g2 = 0, seq = 0, ants;
  985. if(s) {
  986. seq = abs(s) * (TimeNow() - this.ts) / 50;
  987. if(s < 0)
  988. seq = 8.64e6 - seq;
  989. s = ~~seq % length;
  990. }
  991. if(s) {
  992. if(l >= s) {
  993. l1 = l - s;
  994. l2 = s;
  995. } else {
  996. g1 = length - s;
  997. g2 = g - g1;
  998. }
  999. ants = [l1, g1, l2, g2];
  1000. } else {
  1001. ants = [l,g];
  1002. }
  1003. c.setLineDash(ants);
  1004. }
  1005. Oproto.DrawOutline = function(c,x,y,w,h,colour) {
  1006. var r = min(this.radius, h/2, w/2);
  1007. c.strokeStyle = colour;
  1008. this.Ants(c);
  1009. RRect(c, x, y, w, h, r, true);
  1010. };
  1011. Oproto.DrawSize = function(c,x,y,w,h,colour,tag,x1,y1) {
  1012. var tw = tag.w, th = tag.h, m, i, sc;
  1013. if(this.pulsate) {
  1014. if(tag.image)
  1015. sc = (tag.image.height + this.tc.outlineIncrease) / tag.image.height;
  1016. else
  1017. sc = tag.oscale;
  1018. i = tag.fimage || tag.image;
  1019. m = 1 + ((sc - 1) * (1-this.pulse));
  1020. tag.h *= m;
  1021. tag.w *= m;
  1022. } else {
  1023. i = tag.oimage;
  1024. }
  1025. tag.alpha = 1;
  1026. tag.Draw(c, x1, y1, i);
  1027. tag.h = th;
  1028. tag.w = tw;
  1029. return 1;
  1030. };
  1031. Oproto.DrawColour = function(c,x,y,w,h,colour,tag,x1,y1) {
  1032. if(tag.oimage) {
  1033. if(this.pulse < 1) {
  1034. tag.alpha = 1 - pow(this.pulse, 2);
  1035. tag.Draw(c, x1, y1, tag.fimage);
  1036. tag.alpha = this.pulse;
  1037. } else {
  1038. tag.alpha = 1;
  1039. }
  1040. tag.Draw(c, x1, y1, tag.oimage);
  1041. return 1;
  1042. }
  1043. return this[tag.image ? 'DrawColourImage' : 'DrawColourText'](c,x,y,w,h,colour,tag,x1,y1);
  1044. };
  1045. Oproto.DrawColourText = function(c,x,y,w,h,colour,tag,x1,y1) {
  1046. var normal = tag.colour;
  1047. tag.colour = colour;
  1048. tag.alpha = 1;
  1049. tag.Draw(c,x1,y1);
  1050. tag.colour = normal;
  1051. return 1;
  1052. };
  1053. Oproto.DrawColourImage = function(c,x,y,w,h,colour,tag,x1,y1) {
  1054. var ccanvas = c.canvas, fx = ~~max(x,0), fy = ~~max(y,0),
  1055. fw = min(ccanvas.width - fx, w) + .5|0, fh = min(ccanvas.height - fy,h) + .5|0, cc;
  1056. if(ocanvas)
  1057. ocanvas.width = fw, ocanvas.height = fh;
  1058. else
  1059. ocanvas = NewCanvas(fw, fh);
  1060. if(!ocanvas)
  1061. return this.SetMethod('outline'); // if using IE and images, give up!
  1062. cc = ocanvas.getContext('2d');
  1063. cc.drawImage(ccanvas,fx,fy,fw,fh,0,0,fw,fh);
  1064. c.clearRect(fx,fy,fw,fh);
  1065. if(this.pulsate) {
  1066. tag.alpha = 1 - pow(this.pulse, 2);
  1067. } else {
  1068. tag.alpha = 1;
  1069. }
  1070. tag.Draw(c,x1,y1);
  1071. c.setTransform(1,0,0,1,0,0);
  1072. c.save();
  1073. c.beginPath();
  1074. c.rect(fx,fy,fw,fh);
  1075. c.clip();
  1076. c.globalCompositeOperation = 'source-in';
  1077. c.fillStyle = colour;
  1078. c.fillRect(fx,fy,fw,fh);
  1079. c.restore();
  1080. c.globalAlpha = 1;
  1081. c.globalCompositeOperation = 'destination-over';
  1082. c.drawImage(ocanvas,0,0,fw,fh,fx,fy,fw,fh);
  1083. c.globalCompositeOperation = 'source-over';
  1084. return 1;
  1085. };
  1086. Oproto.DrawBlock = function(c,x,y,w,h,colour) {
  1087. var r = min(this.radius, h/2, w/2);
  1088. c.fillStyle = colour;
  1089. RRect(c, x, y, w, h, r);
  1090. };
  1091. Oproto.DrawSimple = function(c, tag, x1, y1, ga, useGa) {
  1092. var t = this.tc;
  1093. c.setTransform(1,0,0,1,0,0);
  1094. c.strokeStyle = this.colour;
  1095. c.lineWidth = t.outlineThickness;
  1096. c.shadowBlur = c.shadowOffsetX = c.shadowOffsetY = 0;
  1097. c.globalAlpha = useGa ? ga : 1;
  1098. return this.drawFunc(c,this.x,this.y,this.w,this.h,this.colour,tag,x1,y1);
  1099. };
  1100. Oproto.DrawPulsate = function(c, tag, x1, y1) {
  1101. var diff = TimeNow() - this.ts, t = this.tc,
  1102. ga = t.pulsateTo + ((1 - t.pulsateTo) *
  1103. (0.5 + (cos(2 * Math.PI * diff / (1000 * t.pulsateTime)) / 2)));
  1104. this.pulse = ga = TagCanvas.Smooth(1,ga);
  1105. return this.DrawSimple(c, tag, x1, y1, ga, 1);
  1106. };
  1107. Oproto.Active = function(c,x,y) {
  1108. var a = (x >= this.x && y >= this.y &&
  1109. x <= this.x + this.w && y <= this.y + this.h);
  1110. if(a) {
  1111. this.ts = this.ts || TimeNow();
  1112. } else {
  1113. this.ts = null;
  1114. }
  1115. return a;
  1116. };
  1117. Oproto.PreDraw = Oproto.PostDraw = Oproto.LastDraw = Nop;
  1118. /**
  1119. * @constructor
  1120. */
  1121. function Tag(tc, text, a, v, w, h, col, bcol, bradius, boutline, bothickness,
  1122. font, padding, original) {
  1123. this.tc = tc;
  1124. this.image = null;
  1125. this.text = text;
  1126. this.text_original = original;
  1127. this.line_widths = [];
  1128. this.title = a.title || null;
  1129. this.a = a;
  1130. this.position = new Vector(v[0], v[1], v[2]);
  1131. this.x = this.y = this.z = 0;
  1132. this.w = w;
  1133. this.h = h;
  1134. this.colour = col || tc.textColour;
  1135. this.bgColour = bcol || tc.bgColour;
  1136. this.bgRadius = bradius | 0;
  1137. this.bgOutline = boutline || this.colour;
  1138. this.bgOutlineThickness = bothickness | 0;
  1139. this.textFont = font || tc.textFont;
  1140. this.padding = padding | 0;
  1141. this.sc = this.alpha = 1;
  1142. this.weighted = !tc.weight;
  1143. this.outline = new Outline(tc,this);
  1144. }
  1145. Tproto = Tag.prototype;
  1146. Tproto.Init = function(e) {
  1147. var tc = this.tc;
  1148. this.textHeight = tc.textHeight;
  1149. if(this.HasText()) {
  1150. this.Measure(tc.ctxt,tc);
  1151. } else {
  1152. this.w = this.iw;
  1153. this.h = this.ih;
  1154. }
  1155. this.SetShadowColour = tc.shadowAlpha ? this.SetShadowColourAlpha : this.SetShadowColourFixed;
  1156. this.SetDraw(tc);
  1157. };
  1158. Tproto.Draw = Nop;
  1159. Tproto.HasText = function() {
  1160. return this.text && this.text[0].length > 0;
  1161. };
  1162. Tproto.EqualTo = function(e) {
  1163. var i = e.getElementsByTagName('img');
  1164. if(this.a.href != e.href)
  1165. return 0;
  1166. if(i.length)
  1167. return this.image.src == i[0].src;
  1168. return (e.innerText || e.textContent) == this.text_original;
  1169. };
  1170. Tproto.SetImage = function(i) {
  1171. this.image = this.fimage = i;
  1172. };
  1173. Tproto.SetDraw = function(t) {
  1174. this.Draw = this.fimage ? (t.ie > 7 ? this.DrawImageIE : this.DrawImage) : this.DrawText;
  1175. t.noSelect && (this.CheckActive = Nop);
  1176. };
  1177. Tproto.MeasureText = function(c) {
  1178. var i, l = this.text.length, w = 0, wl;
  1179. for(i = 0; i < l; ++i) {
  1180. this.line_widths[i] = wl = c.measureText(this.text[i]).width;
  1181. w = max(w, wl);
  1182. }
  1183. return w;
  1184. };
  1185. Tproto.Measure = function(c,t) {
  1186. var extents = FindTextBoundingBox(this.text, this.textFont, this.textHeight),
  1187. s, th, f, soff, cw, twidth, theight, img, tcv;
  1188. // add the gap at the top to the height to make equal gap at bottom
  1189. theight = extents ? extents.max.y + extents.min.y : this.textHeight;
  1190. c.font = this.font = this.textHeight + 'px ' + this.textFont;
  1191. twidth = this.MeasureText(c);
  1192. if(t.txtOpt) {
  1193. s = t.txtScale;
  1194. th = s * this.textHeight;
  1195. f = th + 'px ' + this.textFont;
  1196. soff = [s * t.shadowOffset[0], s * t.shadowOffset[1]];
  1197. c.font = f;
  1198. cw = this.MeasureText(c);
  1199. tcv = new TextCanvas(this.text, f, cw + s, (s * theight) + s, cw,
  1200. this.line_widths, t.textAlign, t.textVAlign, s);
  1201. if(this.image)
  1202. tcv.SetImage(this.image, this.iw, this.ih, t.imagePosition, t.imagePadding,
  1203. t.imageAlign, t.imageVAlign, t.imageScale);
  1204. img = tcv.Create(this.colour, this.bgColour, this.bgOutline,
  1205. s * this.bgOutlineThickness, t.shadow, s * t.shadowBlur, soff,
  1206. s * this.padding, s * this.bgRadius);
  1207. // add outline image using highlight colour
  1208. if(t.outlineMethod == 'colour') {
  1209. this.oimage = tcv.Create(this.outline.colour, this.bgColour, this.outline.colour,
  1210. s * this.bgOutlineThickness, t.shadow, s * t.shadowBlur, soff,
  1211. s * this.padding, s * this.bgRadius);
  1212. } else if(t.outlineMethod == 'size') {
  1213. extents = FindTextBoundingBox(this.text, this.textFont,
  1214. this.textHeight + t.outlineIncrease);
  1215. th = extents.max.y + extents.min.y;
  1216. f = (s * (this.textHeight + t.outlineIncrease)) + 'px ' + this.textFont;
  1217. c.font = f;
  1218. cw = this.MeasureText(c);
  1219. tcv = new TextCanvas(this.text, f, cw + s, (s * th) + s, cw,
  1220. this.line_widths, t.textAlign, t.textVAlign, s);
  1221. if(this.image)
  1222. tcv.SetImage(this.image, this.iw + t.outlineIncrease,
  1223. this.ih + t.outlineIncrease, t.imagePosition, t.imagePadding,
  1224. t.imageAlign, t.imageVAlign, t.imageScale);
  1225. this.oimage = tcv.Create(this.colour, this.bgColour, this.bgOutline,
  1226. s * this.bgOutlineThickness, t.shadow, s * t.shadowBlur, soff,
  1227. s * this.padding, s * this.bgRadius);
  1228. this.oscale = this.oimage.width / img.width;
  1229. if(t.outlineIncrease > 0)
  1230. img = ExpandImage(img, this.oimage.width, this.oimage.height);
  1231. else
  1232. this.oimage = ExpandImage(this.oimage, img.width, img.height);
  1233. }
  1234. if(img) {
  1235. this.fimage = img;
  1236. twidth = this.fimage.width / s;
  1237. theight = this.fimage.height / s;
  1238. }
  1239. this.SetDraw(t);
  1240. t.txtOpt = !!this.fimage;
  1241. }
  1242. this.h = theight;
  1243. this.w = twidth;
  1244. };
  1245. Tproto.SetFont = function(f, c, bc, boc) {
  1246. this.textFont = f;
  1247. this.colour = c;
  1248. this.bgColour = bc;
  1249. this.bgOutline = boc;
  1250. this.Measure(this.tc.ctxt, this.tc);
  1251. };
  1252. Tproto.SetWeight = function(w) {
  1253. var tc = this.tc, modes = tc.weightMode.split(/[, ]/), m, s, wl = w.length;
  1254. if(!this.HasText())
  1255. return;
  1256. this.weighted = true;
  1257. for(s = 0; s < wl; ++s) {
  1258. m = modes[s] || 'size';
  1259. if('both' == m) {
  1260. this.Weight(w[s], tc.ctxt, tc, 'size', tc.min_weight[s],
  1261. tc.max_weight[s], s);
  1262. this.Weight(w[s], tc.ctxt, tc, 'colour', tc.min_weight[s],
  1263. tc.max_weight[s], s);
  1264. } else {
  1265. this.Weight(w[s], tc.ctxt, tc, m, tc.min_weight[s], tc.max_weight[s], s);
  1266. }
  1267. }
  1268. this.Measure(tc.ctxt, tc);
  1269. };
  1270. Tproto.Weight = function(w, c, t, m, wmin, wmax, wnum) {
  1271. w = isNaN(w) ? 1 : w;
  1272. var nweight = (w - wmin) / (wmax - wmin);
  1273. if('colour' == m)
  1274. this.colour = FindGradientColour(t, nweight, wnum);
  1275. else if('bgcolour' == m)
  1276. this.bgColour = FindGradientColour(t, nweight, wnum);
  1277. else if('bgoutline' == m)
  1278. this.bgOutline = FindGradientColour(t, nweight, wnum);
  1279. else if('outline' == m)
  1280. this.outline.colour = FindGradientColour(t, nweight, wnum);
  1281. else if('size' == m) {
  1282. if(t.weightSizeMin > 0 && t.weightSizeMax > t.weightSizeMin) {
  1283. this.textHeight = t.weightSize *
  1284. (t.weightSizeMin + (t.weightSizeMax - t.weightSizeMin) * nweight);
  1285. } else {
  1286. // min textHeight of 1
  1287. this.textHeight = max(1, w * t.weightSize);
  1288. }
  1289. }
  1290. };
  1291. Tproto.SetShadowColourFixed = function(c,s,a) {
  1292. c.shadowColor = s;
  1293. };
  1294. Tproto.SetShadowColourAlpha = function(c,s,a) {
  1295. c.shadowColor = SetAlpha(s, a);
  1296. };
  1297. Tproto.DrawText = function(c,xoff,yoff) {
  1298. var t = this.tc, x = this.x, y = this.y, s = this.sc, i, xl;
  1299. c.globalAlpha = this.alpha;
  1300. c.fillStyle = this.colour;
  1301. t.shadow && this.SetShadowColour(c,t.shadow,this.alpha);
  1302. c.font = this.font;
  1303. x += xoff / s;
  1304. y += (yoff / s) - (this.h / 2);
  1305. for(i = 0; i < this.text.length; ++i) {
  1306. xl = x;
  1307. if('right' == t.textAlign) {
  1308. xl += this.w / 2 - this.line_widths[i];
  1309. } else if('centre' == t.textAlign) {
  1310. xl -= this.line_widths[i] / 2;
  1311. } else {
  1312. xl -= this.w / 2;
  1313. }
  1314. c.setTransform(s, 0, 0, s, s * xl, s * y);
  1315. c.fillText(this.text[i], 0, 0);
  1316. y += this.textHeight;
  1317. }
  1318. };
  1319. Tproto.DrawImage = function(c,xoff,yoff,im) {
  1320. var x = this.x, y = this.y, s = this.sc,
  1321. i = im || this.fimage, w = this.w, h = this.h, a = this.alpha,
  1322. shadow = this.shadow;
  1323. c.globalAlpha = a;
  1324. shadow && this.SetShadowColour(c,shadow,a);
  1325. x += (xoff / s) - (w / 2);
  1326. y += (yoff / s) - (h / 2);
  1327. c.setTransform(s, 0, 0, s, s * x, s * y);
  1328. c.drawImage(i, 0, 0, w, h);
  1329. };
  1330. Tproto.DrawImageIE = function(c,xoff,yoff) {
  1331. var i = this.fimage, s = this.sc,
  1332. w = i.width = this.w*s, h = i.height = this.h * s,
  1333. x = (this.x*s) + xoff - (w/2), y = (this.y*s) + yoff - (h/2);
  1334. c.setTransform(1,0,0,1,0,0);
  1335. c.globalAlpha = this.alpha;
  1336. c.drawImage(i, x, y);
  1337. };
  1338. Tproto.Calc = function(m,a) {
  1339. var pp, t = this.tc, mnb = t.minBrightness,
  1340. mxb = t.maxBrightness, r = t.max_radius;
  1341. pp = m.xform(this.position);
  1342. this.xformed = pp;
  1343. pp = Project(t, pp, t.stretchX, t.stretchY);
  1344. this.x = pp.x;
  1345. this.y = pp.y;
  1346. this.z = pp.z;
  1347. this.sc = pp.w;
  1348. this.alpha = a * Clamp(mnb + (mxb - mnb) * (r - this.z) / (2 * r), 0, 1);
  1349. return this.xformed;
  1350. };
  1351. Tproto.UpdateActive = function(c, xoff, yoff) {
  1352. var o = this.outline, w = this.w, h = this.h,
  1353. x = this.x - w/2, y = this.y - h/2;
  1354. o.Update(x, y, w, h, this.sc, this.z, xoff, yoff);
  1355. return o;
  1356. };
  1357. Tproto.CheckActive = function(c,xoff,yoff) {
  1358. var t = this.tc, o = this.UpdateActive(c, xoff, yoff);
  1359. return o.Active(c, t.mx, t.my) ? o : null;
  1360. };
  1361. Tproto.Clicked = function(e) {
  1362. var a = this.a, t = a.target, h = a.href, evt;
  1363. if(t != '' && t != '_self') {
  1364. if(self.frames[t]) {
  1365. self.frames[t].document.location = h;
  1366. } else{
  1367. try {
  1368. if(top.frames[t]) {
  1369. top.frames[t].document.location = h;
  1370. return;
  1371. }
  1372. } catch(err) {
  1373. // different domain/port/protocol?
  1374. }
  1375. window.open(h, t);
  1376. }
  1377. return;
  1378. }
  1379. if(doc.createEvent) {
  1380. evt = doc.createEvent('MouseEvents');
  1381. evt.initMouseEvent('click', 1, 1, window, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, null);
  1382. if(!a.dispatchEvent(evt))
  1383. return;
  1384. } else if(a.fireEvent) {
  1385. if(!a.fireEvent('onclick'))
  1386. return;
  1387. }
  1388. doc.location = h;
  1389. };
  1390. /**
  1391. * @constructor
  1392. */
  1393. function TagCanvas(cid,lctr,opt) {
  1394. var i, p, c = doc.getElementById(cid), cp = ['id','class','innerHTML'], raf;
  1395. if(!c) throw 0;
  1396. if(Defined(window.G_vmlCanvasManager)) {
  1397. c = window.G_vmlCanvasManager.initElement(c);
  1398. this.ie = parseFloat(navigator.appVersion.split('MSIE')[1]);
  1399. }
  1400. if(c && (!c.getContext || !c.getContext('2d').fillText)) {
  1401. p = doc.createElement('DIV');
  1402. for(i = 0; i < cp.length; ++i)
  1403. p[cp[i]] = c[cp[i]];
  1404. c.parentNode.insertBefore(p,c);
  1405. c.parentNode.removeChild(c);
  1406. throw 0;
  1407. }
  1408. for(i in TagCanvas.options)
  1409. this[i] = opt && Defined(opt[i]) ? opt[i] :
  1410. (Defined(TagCanvas[i]) ? TagCanvas[i] : TagCanvas.options[i]);
  1411. this.canvas = c;
  1412. this.ctxt = c.getContext('2d');
  1413. this.z1 = 250 / max(this.depth, 0.001);
  1414. this.z2 = this.z1 / this.zoom;
  1415. this.radius = min(c.height, c.width) * 0.0075; // fits radius of 100 in canvas
  1416. this.max_radius = 100;
  1417. this.max_weight = [];
  1418. this.min_weight = [];
  1419. this.textFont = this.textFont && FixFont(this.textFont);
  1420. this.textHeight *= 1;
  1421. this.imageRadius = this.imageRadius.toString();
  1422. this.pulsateTo = Clamp(this.pulsateTo, 0, 1);
  1423. this.minBrightness = Clamp(this.minBrightness, 0, 1);
  1424. this.maxBrightness = Clamp(this.maxBrightness, this.minBrightness, 1);
  1425. this.ctxt.textBaseline = 'top';
  1426. this.lx = (this.lock + '').indexOf('x') + 1;
  1427. this.ly = (this.lock + '').indexOf('y') + 1;
  1428. this.frozen = this.dx = this.dy = this.fixedAnim = this.touchState = 0;
  1429. this.fixedAlpha = 1;
  1430. this.source = lctr || cid;
  1431. this.repeatTags = min(64, ~~this.repeatTags);
  1432. this.minTags = min(200, ~~this.minTags);
  1433. if(~~this.scrollPause > 0)
  1434. TagCanvas.scrollPause = ~~this.scrollPause;
  1435. else
  1436. this.scrollPause = 0;
  1437. if(this.minTags > 0 && this.repeatTags < 1 && (i = this.GetTags().length))
  1438. this.repeatTags = ceil(this.minTags / i) - 1;
  1439. this.transform = Matrix.Identity();
  1440. this.startTime = this.time = TimeNow();
  1441. this.mx = this.my = -1;
  1442. this.centreImage && CentreImage(this);
  1443. this.Animate = this.dragControl ? this.AnimateDrag : this.AnimatePosition;
  1444. this.animTiming = (typeof TagCanvas[this.animTiming] == 'function' ?
  1445. TagCanvas[this.animTiming] : TagCanvas.Smooth);
  1446. if(this.shadowBlur || this.shadowOffset[0] || this.shadowOffset[1]) {
  1447. // let the browser translate "red" into "#ff0000"
  1448. this.ctxt.shadowColor = this.shadow;
  1449. this.shadow = this.ctxt.shadowColor;
  1450. this.shadowAlpha = ShadowAlphaBroken();
  1451. } else {
  1452. delete this.shadow;
  1453. }
  1454. this.Load();
  1455. if(lctr && this.hideTags) {
  1456. (function(t) {
  1457. if(TagCanvas.loaded)
  1458. t.HideTags();
  1459. else
  1460. AddHandler('load', function() { t.HideTags(); }, window);
  1461. })(this);
  1462. }
  1463. this.yaw = this.initial ? this.initial[0] * this.maxSpeed : 0;
  1464. this.pitch = this.initial ? this.initial[1] * this.maxSpeed : 0;
  1465. if(this.tooltip) {
  1466. this.ctitle = c.title;
  1467. c.title = '';
  1468. if(this.tooltip == 'native') {
  1469. this.Tooltip = this.TooltipNative;
  1470. } else {
  1471. this.Tooltip = this.TooltipDiv;
  1472. if(!this.ttdiv) {
  1473. this.ttdiv = doc.createElement('div');
  1474. this.ttdiv.className = this.tooltipClass;
  1475. this.ttdiv.style.position = 'absolute';
  1476. this.ttdiv.style.zIndex = c.style.zIndex + 1;
  1477. AddHandler('mouseover',function(e){e.target.style.display='none';},this.ttdiv);
  1478. doc.body.appendChild(this.ttdiv);
  1479. }
  1480. }
  1481. } else {
  1482. this.Tooltip = this.TooltipNone;
  1483. }
  1484. if(!this.noMouse && !handlers[cid]) {
  1485. handlers[cid] = [
  1486. ['mousemove', MouseMove],
  1487. ['mouseout', MouseOut],
  1488. ['mouseup', MouseUp],
  1489. ['touchstart', TouchDown],
  1490. ['touchend', TouchUp],
  1491. ['touchcancel', TouchUp],
  1492. ['touchmove', TouchMove]
  1493. ];
  1494. if(this.dragControl) {
  1495. handlers[cid].push(['mousedown', MouseDown]);
  1496. handlers[cid].push(['selectstart', Nop]);
  1497. }
  1498. if(this.wheelZoom) {
  1499. handlers[cid].push(['mousewheel', MouseWheel]);
  1500. handlers[cid].push(['DOMMouseScroll', MouseWheel]);
  1501. }
  1502. if(this.scrollPause) {
  1503. handlers[cid].push(['scroll', Scroll, window]);
  1504. }
  1505. for(i = 0; i < handlers[cid].length; ++i) {
  1506. p = handlers[cid][i];
  1507. AddHandler(p[0], p[1], p[2] ? p[2] : c);
  1508. }
  1509. }
  1510. if(!TagCanvas.started) {
  1511. raf = window.requestAnimationFrame = window.requestAnimationFrame ||
  1512. window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame ||
  1513. window.msRequestAnimationFrame;
  1514. TagCanvas.NextFrame = raf ? TagCanvas.NextFrameRAF :
  1515. TagCanvas.NextFrameTimeout;
  1516. TagCanvas.interval = this.interval;
  1517. TagCanvas.NextFrame(this.interval);
  1518. TagCanvas.started = 1;
  1519. }
  1520. }
  1521. TCproto = TagCanvas.prototype;
  1522. TCproto.SourceElements = function() {
  1523. if(doc.querySelectorAll)
  1524. return doc.querySelectorAll('#' + this.source);
  1525. return [doc.getElementById(this.source)];
  1526. };
  1527. TCproto.HideTags = function() {
  1528. var el = this.SourceElements(), i;
  1529. for(i = 0; i < el.length; ++i)
  1530. el[i].style.display = 'none';
  1531. };
  1532. TCproto.GetTags = function() {
  1533. var el = this.SourceElements(), etl, tl = [], i, j, k;
  1534. for(k = 0; k <= this.repeatTags; ++k) {
  1535. for(i = 0; i < el.length; ++i) {
  1536. etl = el[i].getElementsByTagName('a');
  1537. for(j = 0; j < etl.length; ++j) {
  1538. tl.push(etl[j]);
  1539. }
  1540. }
  1541. }
  1542. return tl;
  1543. };
  1544. TCproto.Message = function(text) {
  1545. var tl = [], i, p, tc = text.split(''), a, t, x, z;
  1546. for(i = 0; i < tc.length; ++i) {
  1547. if(tc[i] != ' ') {
  1548. p = i - tc.length / 2;
  1549. a = doc.createElement('A');
  1550. a.href = '#';
  1551. a.innerText = tc[i];
  1552. x = 100 * sin(p / 9);
  1553. z = -100 * cos(p / 9);
  1554. t = new Tag(this, tc[i], a, [x,0,z], 2, 18, '#000', '#fff', 0, 0, 0,
  1555. 'monospace', 2, tc[i]);
  1556. t.Init();
  1557. tl.push(t);
  1558. }
  1559. }
  1560. return tl;
  1561. };
  1562. TCproto.CreateTag = function(e) {
  1563. var im, i, t, txt, ts, font, bc, boc, p = [0, 0, 0];
  1564. if('text' != this.imageMode) {
  1565. im = e.getElementsByTagName('img');
  1566. if(im.length) {
  1567. i = new Image;
  1568. i.src = im[0].src;
  1569. if(!this.imageMode) {
  1570. t = new Tag(this, "", e, p, 0, 0);
  1571. t.SetImage(i);
  1572. //t.Init();
  1573. AddImage(i, im[0], t, this);
  1574. return t;
  1575. }
  1576. }
  1577. }
  1578. if('image' != this.imageMode) {
  1579. ts = new TextSplitter(e);
  1580. txt = ts.Lines();
  1581. if(!ts.Empty()) {
  1582. font = this.textFont || FixFont(GetProperty(e,'font-family'));
  1583. if(this.splitWidth)
  1584. txt = ts.SplitWidth(this.splitWidth, this.ctxt, font, this.textHeight);
  1585. bc = this.bgColour == 'tag' ? GetProperty(e, 'background-color') :
  1586. this.bgColour;
  1587. boc = this.bgOutline == 'tag' ? GetProperty(e, 'color') : this.bgOutline;
  1588. } else {
  1589. ts = null;
  1590. }
  1591. }
  1592. if(ts || i) {
  1593. t = new Tag(this, txt, e, p, 2, this.textHeight + 2,
  1594. this.textColour || GetProperty(e,'color'), bc, this.bgRadius,
  1595. boc, this.bgOutlineThickness, font, this.padding, ts && ts.original);
  1596. if(i) {
  1597. t.SetImage(i);
  1598. AddImage(i, im[0], t, this);
  1599. } else {
  1600. t.Init();
  1601. }
  1602. return t;
  1603. }
  1604. };
  1605. TCproto.UpdateTag = function(t, a) {
  1606. var colour = this.textColour || GetProperty(a, 'color'),
  1607. font = this.textFont || FixFont(GetProperty(a, 'font-family')),
  1608. bc = this.bgColour == 'tag' ? GetProperty(a, 'background-color') :
  1609. this.bgColour, boc = this.bgOutline == 'tag' ? GetProperty(a, 'color') :
  1610. this.bgOutline;
  1611. t.a = a;
  1612. t.title = a.title;
  1613. if(t.colour != colour || t.textFont != font || t.bgColour != bc ||
  1614. t.bgOutline != boc)
  1615. t.SetFont(font, colour, bc, boc);
  1616. };
  1617. TCproto.Weight = function(tl) {
  1618. var ll = tl.length, w, i, s, weights = [], valid,
  1619. wfrom = this.weightFrom ? this.weightFrom.split(/[, ]/) : [null],
  1620. wl = wfrom.length;
  1621. for(i = 0; i < ll; ++i) {
  1622. weights[i] = [];
  1623. for(s = 0; s < wl; ++s) {
  1624. w = FindWeight(tl[i].a, wfrom[s], this.textHeight);
  1625. if(!this.max_weight[s] || w > this.max_weight[s])
  1626. this.max_weight[s] = w;
  1627. if(!this.min_weight[s] || w < this.min_weight[s])
  1628. this.min_weight[s] = w;
  1629. weights[i][s] = w;
  1630. }
  1631. }
  1632. for(s = 0; s < wl; ++s) {
  1633. if(this.max_weight[s] > this.min_weight[s])
  1634. valid = 1;
  1635. }
  1636. if(valid) {
  1637. for(i = 0; i < ll; ++i) {
  1638. tl[i].SetWeight(weights[i]);
  1639. }
  1640. }
  1641. };
  1642. TCproto.Load = function() {
  1643. var tl = this.GetTags(), taglist = [], shape, t,
  1644. shapeArgs, rx, ry, rz, vl, i, tagmap = [], pfuncs = {
  1645. sphere: PointsOnSphere,
  1646. vcylinder: PointsOnCylinderV,
  1647. hcylinder: PointsOnCylinderH,
  1648. vring: PointsOnRingV,
  1649. hring: PointsOnRingH
  1650. };
  1651. if(tl.length) {
  1652. tagmap.length = tl.length;
  1653. for(i = 0; i < tl.length; ++i)
  1654. tagmap[i] = i;
  1655. this.shuffleTags && Shuffle(tagmap);
  1656. rx = 100 * this.radiusX;
  1657. ry = 100 * this.radiusY;
  1658. rz = 100 * this.radiusZ;
  1659. this.max_radius = max(rx, max(ry, rz));
  1660. for(i = 0; i < tl.length; ++i) {
  1661. t = this.CreateTag(tl[tagmap[i]]);
  1662. if(t)
  1663. taglist.push(t);
  1664. }
  1665. this.weight && this.Weight(taglist, true);
  1666. if(this.shapeArgs) {
  1667. this.shapeArgs[0] = taglist.length;
  1668. } else {
  1669. shapeArgs = this.shape.toString().split(/[(),]/);
  1670. shape = shapeArgs.shift();
  1671. if(typeof window[shape] === 'function')
  1672. this.shape = window[shape];
  1673. else
  1674. this.shape = pfuncs[shape] || pfuncs.sphere;
  1675. this.shapeArgs = [taglist.length, rx, ry, rz].concat(shapeArgs);
  1676. }
  1677. vl = this.shape.apply(this, this.shapeArgs);
  1678. this.listLength = taglist.length;
  1679. for(i = 0; i < taglist.length; ++i)
  1680. taglist[i].position = new Vector(vl[i][0], vl[i][1], vl[i][2]);
  1681. }
  1682. if(this.noTagsMessage && !taglist.length) {
  1683. i = (this.imageMode && this.imageMode != 'both' ? this.imageMode + ' ': '');
  1684. taglist = this.Message('No ' + i + 'tags');
  1685. }
  1686. this.taglist = taglist;
  1687. };
  1688. TCproto.Update = function() {
  1689. var tl = this.GetTags(), newlist = [],
  1690. taglist = this.taglist, found,
  1691. added = [], removed = [], vl, ol, nl, i, j;
  1692. if(!this.shapeArgs)
  1693. return this.Load();
  1694. if(tl.length) {
  1695. nl = this.listLength = tl.length;
  1696. ol = taglist.length;
  1697. // copy existing list, populate "removed"
  1698. for(i = 0; i < ol; ++i) {
  1699. newlist.push(taglist[i]);
  1700. removed.push(i);
  1701. }
  1702. // find added and removed tags
  1703. for(i = 0; i < nl; ++i) {
  1704. for(j = 0, found = 0; j < ol; ++j) {
  1705. if(taglist[j].EqualTo(tl[i])) {
  1706. this.UpdateTag(newlist[j], tl[i]);
  1707. found = removed[j] = -1;
  1708. }
  1709. }
  1710. if(!found)
  1711. added.push(i);
  1712. }
  1713. // clean out found tags from removed list
  1714. for(i = 0, j = 0; i < ol; ++i) {
  1715. if(removed[j] == -1)
  1716. removed.splice(j,1);
  1717. else
  1718. ++j;
  1719. }
  1720. // insert new tags in gaps where old tags removed
  1721. if(removed.length) {
  1722. Shuffle(removed);
  1723. while(removed.length && added.length) {
  1724. i = removed.shift();
  1725. j = added.shift();
  1726. newlist[i] = this.CreateTag(tl[j]);
  1727. }
  1728. // remove any more (in reverse order)
  1729. removed.sort(function(a,b) {return a-b});
  1730. while(removed.length) {
  1731. newlist.splice(removed.pop(), 1);
  1732. }
  1733. }
  1734. // add any extra tags
  1735. j = newlist.length / (added.length + 1);
  1736. i = 0;
  1737. while(added.length) {
  1738. newlist.splice(ceil(++i * j), 0, this.CreateTag(tl[added.shift()]));
  1739. }
  1740. // assign correct positions to tags
  1741. this.shapeArgs[0] = nl = newlist.length;
  1742. vl = this.shape.apply(this, this.shapeArgs);
  1743. for(i = 0; i < nl; ++i)
  1744. newlist[i].position = new Vector(vl[i][0], vl[i][1], vl[i][2]);
  1745. // reweight tags
  1746. this.weight && this.Weight(newlist);
  1747. }
  1748. this.taglist = newlist;
  1749. };
  1750. TCproto.SetShadow = function(c) {
  1751. c.shadowBlur = this.shadowBlur;
  1752. c.shadowOffsetX = this.shadowOffset[0];
  1753. c.shadowOffsetY = this.shadowOffset[1];
  1754. };
  1755. TCproto.Draw = function(t) {
  1756. if(this.paused)
  1757. return;
  1758. var cv = this.canvas, cw = cv.width, ch = cv.height, max_sc = 0,
  1759. tdelta = (t - this.time) * TagCanvas.interval / 1000,
  1760. x = cw / 2 + this.offsetX, y = ch / 2 + this.offsetY, c = this.ctxt,
  1761. active, a, i, aindex = -1, tl = this.taglist, l = tl.length,
  1762. frontsel = this.frontSelect, centreDrawn = (this.centreFunc == Nop), fixed;
  1763. this.time = t;
  1764. if(this.frozen && this.drawn)
  1765. return this.Animate(cw,ch,tdelta);
  1766. fixed = this.AnimateFixed();
  1767. c.setTransform(1,0,0,1,0,0);
  1768. for(i = 0; i < l; ++i)
  1769. tl[i].Calc(this.transform, this.fixedAlpha);
  1770. tl = SortList(tl, function(a,b) {return b.z-a.z});
  1771. if(fixed && this.fixedAnim.active) {
  1772. active = this.fixedAnim.tag.UpdateActive(c, x, y);
  1773. } else {
  1774. this.active = null;
  1775. for(i = 0; i < l; ++i) {
  1776. a = this.mx >= 0 && this.my >= 0 && this.taglist[i].CheckActive(c, x, y);
  1777. if(a && a.sc > max_sc && (!frontsel || a.z <= 0)) {
  1778. active = a;
  1779. aindex = i;
  1780. active.tag = this.taglist[i];
  1781. max_sc = a.sc;
  1782. }
  1783. }
  1784. this.active = active;
  1785. }
  1786. this.txtOpt || (this.shadow && this.SetShadow(c));
  1787. c.clearRect(0,0,cw,ch);
  1788. for(i = 0; i < l; ++i) {
  1789. if(!centreDrawn && tl[i].z <= 0) {
  1790. // run the centreFunc if the next tag is at the front
  1791. try { this.centreFunc(c, cw, ch, x, y); }
  1792. catch(e) {
  1793. alert(e);
  1794. // don't run it again
  1795. this.centreFunc = Nop;
  1796. }
  1797. centreDrawn = true;
  1798. }
  1799. if(!(active && active.tag == tl[i] && active.PreDraw(c, tl[i], x, y)))
  1800. tl[i].Draw(c, x, y);
  1801. active && active.tag == tl[i] && active.PostDraw(c);
  1802. }
  1803. if(this.freezeActive && active) {
  1804. this.Freeze();
  1805. } else {
  1806. this.UnFreeze();
  1807. this.drawn = (l == this.listLength);
  1808. }
  1809. if(this.fixedCallback) {
  1810. this.fixedCallback(this,this.fixedCallbackTag);
  1811. this.fixedCallback = null;
  1812. }
  1813. fixed || this.Animate(cw, ch, tdelta);
  1814. active && active.LastDraw(c);
  1815. cv.style.cursor = active ? this.activeCursor : '';
  1816. this.Tooltip(active,this.taglist[aindex]);
  1817. };
  1818. TCproto.TooltipNone = function() { };
  1819. TCproto.TooltipNative = function(active,tag) {
  1820. if(active)
  1821. this.canvas.title = tag && tag.title ? tag.title : '';
  1822. else
  1823. this.canvas.title = this.ctitle;
  1824. };
  1825. TCproto.SetTTDiv = function(title, tag) {
  1826. var tc = this, s = tc.ttdiv.style;
  1827. if(title != tc.ttdiv.innerHTML)
  1828. s.display = 'none';
  1829. tc.ttdiv.innerHTML = title;
  1830. tag && (tag.title = tc.ttdiv.innerHTML);
  1831. if(s.display == 'none' && ! tc.tttimer) {
  1832. tc.tttimer = setTimeout(function() {
  1833. var p = AbsPos(tc.canvas.id);
  1834. s.display = 'block';
  1835. s.left = p.x + tc.mx + 'px';
  1836. s.top = p.y + tc.my + 24 + 'px';
  1837. tc.tttimer = null;
  1838. }, tc.tooltipDelay);
  1839. }
  1840. };
  1841. TCproto.TooltipDiv = function(active,tag) {
  1842. if(active && tag && tag.title) {
  1843. this.SetTTDiv(tag.title, tag);
  1844. } else if(!active && this.mx != -1 && this.my != -1 && this.ctitle.length) {
  1845. this.SetTTDiv(this.ctitle);
  1846. } else {
  1847. this.ttdiv.style.display = 'none';
  1848. }
  1849. };
  1850. TCproto.Transform = function(tc, p, y) {
  1851. if(p || y) {
  1852. var sp = sin(p), cp = cos(p), sy = sin(y), cy = cos(y),
  1853. ym = new Matrix([cy,0,sy, 0,1,0, -sy,0,cy]),
  1854. pm = new Matrix([1,0,0, 0,cp,-sp, 0,sp,cp]);
  1855. tc.transform = tc.transform.mul(ym.mul(pm));
  1856. }
  1857. };
  1858. TCproto.AnimateFixed = function() {
  1859. var fa, t1, angle, m, d;
  1860. if(this.fadeIn) {
  1861. t1 = TimeNow() - this.startTime;
  1862. if(t1 >= this.fadeIn) {
  1863. this.fadeIn = 0;
  1864. this.fixedAlpha = 1;
  1865. } else {
  1866. this.fixedAlpha = t1 / this.fadeIn;
  1867. }
  1868. }
  1869. if(this.fixedAnim) {
  1870. if(!this.fixedAnim.transform)
  1871. this.fixedAnim.transform = this.transform;
  1872. fa = this.fixedAnim, t1 = TimeNow() - fa.t0, angle = fa.angle,
  1873. m, d = this.animTiming(fa.t, t1);
  1874. this.transform = fa.transform;
  1875. if(t1 >= fa.t) {
  1876. this.fixedCallbackTag = fa.tag;
  1877. this.fixedCallback = fa.cb;
  1878. this.fixedAnim = this.yaw = this.pitch = 0;
  1879. } else {
  1880. angle *= d;
  1881. }
  1882. m = Matrix.Rotation(angle, fa.axis);
  1883. this.transform = this.transform.mul(m);
  1884. return (this.fixedAnim != 0);
  1885. }
  1886. return false;
  1887. };
  1888. TCproto.AnimatePosition = function(w, h, t) {
  1889. var tc = this, x = tc.mx, y = tc.my, s, r;
  1890. if(!tc.frozen && x >= 0 && y >= 0 && x < w && y < h) {
  1891. s = tc.maxSpeed, r = tc.reverse ? -1 : 1;
  1892. tc.lx || (tc.yaw = ((x * 2 * s / w) - s) * r * t);
  1893. tc.ly || (tc.pitch = ((y * 2 * s / h) - s) * -r * t);
  1894. tc.initial = null;
  1895. } else if(!tc.initial) {
  1896. if(tc.frozen && !tc.freezeDecel)
  1897. tc.yaw = tc.pitch = 0;
  1898. else
  1899. tc.Decel(tc);
  1900. }
  1901. this.Transform(tc, tc.pitch, tc.yaw);
  1902. };
  1903. TCproto.AnimateDrag = function(w, h, t) {
  1904. var tc = this, rs = 100 * t * tc.maxSpeed / tc.max_radius / tc.zoom;
  1905. if(tc.dx || tc.dy) {
  1906. tc.lx || (tc.yaw = tc.dx * rs / tc.stretchX);
  1907. tc.ly || (tc.pitch = tc.dy * -rs / tc.stretchY);
  1908. tc.dx = tc.dy = 0;
  1909. tc.initial = null;
  1910. } else if(!tc.initial) {
  1911. tc.Decel(tc);
  1912. }
  1913. this.Transform(tc, tc.pitch, tc.yaw);
  1914. };
  1915. TCproto.Freeze = function() {
  1916. if(!this.frozen) {
  1917. this.preFreeze = [this.yaw, this.pitch];
  1918. this.frozen = 1;
  1919. this.drawn = 0;
  1920. }
  1921. };
  1922. TCproto.UnFreeze = function() {
  1923. if(this.frozen) {
  1924. this.yaw = this.preFreeze[0];
  1925. this.pitch = this.preFreeze[1];
  1926. this.frozen = 0;
  1927. }
  1928. };
  1929. TCproto.Decel = function(tc) {
  1930. var s = tc.minSpeed, ay = abs(tc.yaw), ap = abs(tc.pitch);
  1931. if(!tc.lx && ay > s)
  1932. tc.yaw = ay > tc.z0 ? tc.yaw * tc.decel : 0;
  1933. if(!tc.ly && ap > s)
  1934. tc.pitch = ap > tc.z0 ? tc.pitch * tc.decel : 0;
  1935. };
  1936. TCproto.Zoom = function(r) {
  1937. this.z2 = this.z1 * (1/r);
  1938. this.drawn = 0;
  1939. };
  1940. TCproto.Clicked = function(e) {
  1941. var a = this.active;
  1942. try {
  1943. if(a && a.tag)
  1944. if(this.clickToFront === false || this.clickToFront === null)
  1945. a.tag.Clicked(e);
  1946. else
  1947. this.TagToFront(a.tag, this.clickToFront, function() {
  1948. a.tag.Clicked(e);
  1949. }, true);
  1950. } catch(ex) {
  1951. }
  1952. };
  1953. TCproto.Wheel = function(i) {
  1954. var z = this.zoom + this.zoomStep * (i ? 1 : -1);
  1955. this.zoom = min(this.zoomMax,max(this.zoomMin,z));
  1956. this.Zoom(this.zoom);
  1957. };
  1958. TCproto.BeginDrag = function(e) {
  1959. this.down = EventXY(e, this.canvas);
  1960. e.cancelBubble = true;
  1961. e.returnValue = false;
  1962. e.preventDefault && e.preventDefault();
  1963. };
  1964. TCproto.Drag = function(e, p) {
  1965. if(this.dragControl && this.down) {
  1966. var t2 = this.dragThreshold * this.dragThreshold,
  1967. dx = p.x - this.down.x, dy = p.y - this.down.y;
  1968. if(this.dragging || dx * dx + dy * dy > t2) {
  1969. this.dx = dx;
  1970. this.dy = dy;
  1971. this.dragging = 1;
  1972. this.down = p;
  1973. }
  1974. }
  1975. return this.dragging;
  1976. };
  1977. TCproto.EndDrag = function() {
  1978. var res = this.dragging;
  1979. this.dragging = this.down = null;
  1980. return res;
  1981. };
  1982. function PinchDistance(e) {
  1983. var t1 = e.targetTouches[0], t2 = e.targetTouches[1];
  1984. return sqrt(pow(t2.pageX - t1.pageX, 2) + pow(t2.pageY - t1.pageY, 2));
  1985. }
  1986. TCproto.BeginPinch = function(e) {
  1987. this.pinched = [PinchDistance(e), this.zoom];
  1988. e.preventDefault && e.preventDefault();
  1989. };
  1990. TCproto.Pinch = function(e) {
  1991. var z, d, p = this.pinched;
  1992. if(!p)
  1993. return;
  1994. d = PinchDistance(e);
  1995. z = p[1] * d / p[0];
  1996. this.zoom = min(this.zoomMax,max(this.zoomMin,z));
  1997. this.Zoom(this.zoom);
  1998. };
  1999. TCproto.EndPinch = function(e) {
  2000. this.pinched = null;
  2001. };
  2002. TCproto.Pause = function() { this.paused = true; };
  2003. TCproto.Resume = function() { this.paused = false; };
  2004. TCproto.SetSpeed = function(i) {
  2005. this.initial = i;
  2006. this.yaw = i[0] * this.maxSpeed;
  2007. this.pitch = i[1] * this.maxSpeed;
  2008. };
  2009. TCproto.FindTag = function(t) {
  2010. if(!Defined(t))
  2011. return null;
  2012. Defined(t.index) && (t = t.index);
  2013. if(!IsObject(t))
  2014. return this.taglist[t];
  2015. var srch, tgt, i;
  2016. if(Defined(t.id))
  2017. srch = 'id', tgt = t.id;
  2018. else if(Defined(t.text))
  2019. srch = 'innerText', tgt = t.text;
  2020. for(i = 0; i < this.taglist.length; ++i)
  2021. if(this.taglist[i].a[srch] == tgt)
  2022. return this.taglist[i];
  2023. };
  2024. TCproto.RotateTag = function(tag, lt, lg, time, callback, active) {
  2025. var t = tag.Calc(this.transform, 1), v1 = new Vector(t.x, t.y, t.z),
  2026. v2 = MakeVector(lg, lt), angle = v1.angle(v2), u = v1.cross(v2).unit();
  2027. if(angle == 0) {
  2028. this.fixedCallbackTag = tag;
  2029. this.fixedCallback = callback;
  2030. } else {
  2031. this.fixedAnim = {
  2032. angle: -angle,
  2033. axis: u,
  2034. t: time,
  2035. t0: TimeNow(),
  2036. cb: callback,
  2037. tag: tag,
  2038. active: active
  2039. };
  2040. }
  2041. };
  2042. TCproto.TagToFront = function(tag, time, callback, active) {
  2043. this.RotateTag(tag, 0, 0, time, callback, active);
  2044. };
  2045. TagCanvas.Start = function(id,l,o) {
  2046. TagCanvas.Delete(id);
  2047. TagCanvas.tc[id] = new TagCanvas(id,l,o);
  2048. };
  2049. function tccall(f,id) {
  2050. TagCanvas.tc[id] && TagCanvas.tc[id][f]();
  2051. }
  2052. TagCanvas.Linear = function(t, t0) { return t0 / t; }
  2053. TagCanvas.Smooth = function(t, t0) { return 0.5 - cos(t0 * Math.PI / t) / 2; }
  2054. TagCanvas.Pause = function(id) { tccall('Pause',id); };
  2055. TagCanvas.Resume = function(id) { tccall('Resume',id); };
  2056. TagCanvas.Reload = function(id) { tccall('Load',id); };
  2057. TagCanvas.Update = function(id) { tccall('Update',id); };
  2058. TagCanvas.SetSpeed = function(id, speed) {
  2059. if(IsObject(speed) && TagCanvas.tc[id] &&
  2060. !isNaN(speed[0]) && !isNaN(speed[1])) {
  2061. TagCanvas.tc[id].SetSpeed(speed);
  2062. return true;
  2063. }
  2064. return false;
  2065. };
  2066. TagCanvas.TagToFront = function(id, options) {
  2067. if(!IsObject(options))
  2068. return false;
  2069. options.lat = options.lng = 0;
  2070. return TagCanvas.RotateTag(id, options);
  2071. };
  2072. TagCanvas.RotateTag = function(id, options) {
  2073. if(IsObject(options) && TagCanvas.tc[id]) {
  2074. if(isNaN(options.time))
  2075. options.time = 500;
  2076. var tt = TagCanvas.tc[id].FindTag(options);
  2077. if(tt) {
  2078. TagCanvas.tc[id].RotateTag(tt, options.lat, options.lng,
  2079. options.time, options.callback, options.active);
  2080. return true;
  2081. }
  2082. }
  2083. return false;
  2084. };
  2085. TagCanvas.Delete = function(id) {
  2086. var i, c;
  2087. if(handlers[id]) {
  2088. c = doc.getElementById(id);
  2089. if(c) {
  2090. for(i = 0; i < handlers[id].length; ++i)
  2091. RemoveHandler(handlers[id][i][0], handlers[id][i][1], c);
  2092. }
  2093. }
  2094. delete handlers[id];
  2095. delete TagCanvas.tc[id];
  2096. };
  2097. TagCanvas.NextFrameRAF = function() {
  2098. requestAnimationFrame(DrawCanvasRAF);
  2099. };
  2100. TagCanvas.NextFrameTimeout = function(iv) {
  2101. setTimeout(DrawCanvas, iv);
  2102. };
  2103. TagCanvas.tc = {};
  2104. TagCanvas.options = {
  2105. z1: 20000,
  2106. z2: 20000,
  2107. z0: 0.0002,
  2108. freezeActive: false,
  2109. freezeDecel: false,
  2110. activeCursor: 'pointer',
  2111. pulsateTo: 1,
  2112. pulsateTime: 3,
  2113. reverse: false,
  2114. depth: 0.5,
  2115. maxSpeed: 0.05,
  2116. minSpeed: 0,
  2117. decel: 0.95,
  2118. interval: 20,
  2119. minBrightness: 0.1,
  2120. maxBrightness: 1,
  2121. outlineColour: '#ffff99',
  2122. outlineThickness: 2,
  2123. outlineOffset: 5,
  2124. outlineMethod: 'outline',
  2125. outlineRadius: 0,
  2126. textColour: '#ff99ff',
  2127. textHeight: 15,
  2128. textFont: 'Helvetica, Arial, sans-serif',
  2129. shadow: '#000',
  2130. shadowBlur: 0,
  2131. shadowOffset: [0,0],
  2132. initial: null,
  2133. hideTags: true,
  2134. zoom: 1,
  2135. weight: false,
  2136. weightMode: 'size',
  2137. weightFrom: null,
  2138. weightSize: 1,
  2139. weightSizeMin: null,
  2140. weightSizeMax: null,
  2141. weightGradient: {0:'#f00', 0.33:'#ff0', 0.66:'#0f0', 1:'#00f'},
  2142. txtOpt: true,
  2143. txtScale: 2,
  2144. frontSelect: false,
  2145. wheelZoom: true,
  2146. zoomMin: 0.3,
  2147. zoomMax: 3,
  2148. zoomStep: 0.05,
  2149. shape: 'sphere',
  2150. lock: null,
  2151. tooltip: null,
  2152. tooltipDelay: 300,
  2153. tooltipClass: 'tctooltip',
  2154. radiusX: 1,
  2155. radiusY: 1,
  2156. radiusZ: 1,
  2157. stretchX: 1,
  2158. stretchY: 1,
  2159. offsetX: 0,
  2160. offsetY: 0,
  2161. shuffleTags: false,
  2162. noSelect: false,
  2163. noMouse: false,
  2164. imageScale: 1,
  2165. paused: false,
  2166. dragControl: false,
  2167. dragThreshold: 4,
  2168. centreFunc: Nop,
  2169. splitWidth: 0,
  2170. animTiming: 'Smooth',
  2171. clickToFront: false,
  2172. fadeIn: 0,
  2173. padding: 0,
  2174. bgColour: null,
  2175. bgRadius: 0,
  2176. bgOutline: null,
  2177. bgOutlineThickness: 0,
  2178. outlineIncrease: 4,
  2179. textAlign: 'centre',
  2180. textVAlign: 'middle',
  2181. imageMode: null,
  2182. imagePosition: null,
  2183. imagePadding: 2,
  2184. imageAlign: 'centre',
  2185. imageVAlign: 'middle',
  2186. noTagsMessage: true,
  2187. centreImage: null,
  2188. pinchZoom: false,
  2189. repeatTags: 0,
  2190. minTags: 0,
  2191. imageRadius: 0,
  2192. scrollPause: false,
  2193. outlineDash: 0,
  2194. outlineDashSpace: 0,
  2195. outlineDashSpeed: 1
  2196. };
  2197. for(i in TagCanvas.options) TagCanvas[i] = TagCanvas.options[i];
  2198. window.TagCanvas = TagCanvas;
  2199. jQuery.fn.tagcanvas = function(options, lctr) {
  2200. var fn = {
  2201. pause: function() {
  2202. $(this).each(function() { tccall('Pause',$(this)[0].id); });
  2203. },
  2204. resume: function() {
  2205. $(this).each(function() { tccall('Resume',$(this)[0].id); });
  2206. },
  2207. reload: function() {
  2208. $(this).each(function() { tccall('Load',$(this)[0].id); });
  2209. },
  2210. update: function() {
  2211. $(this).each(function() { tccall('Update',$(this)[0].id); });
  2212. },
  2213. tagtofront: function() {
  2214. $(this).each(function() { TagCanvas.TagToFront($(this)[0].id, lctr); });
  2215. },
  2216. rotatetag: function() {
  2217. $(this).each(function() { TagCanvas.RotateTag($(this)[0].id, lctr); });
  2218. },
  2219. 'delete': function() {
  2220. $(this).each(function() { TagCanvas.Delete($(this)[0].id); });
  2221. },
  2222. setspeed: function() {
  2223. $(this).each(function() { TagCanvas.SetSpeed($(this)[0].id, lctr); });
  2224. }
  2225. };
  2226. if(typeof options == 'string' && fn[options]) {
  2227. fn[options].apply(this);
  2228. return this;
  2229. } else {
  2230. TagCanvas.jquery = 1;
  2231. $(this).each(function() { TagCanvas.Start($(this)[0].id, lctr, options); });
  2232. return TagCanvas.started;
  2233. }
  2234. };
  2235. // set a flag for when the window has loaded
  2236. AddHandler('load',function(){TagCanvas.loaded=1},window);
  2237. })(jQuery);