svg.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. if (!String.prototype.encodeHTML) {
  2. String.prototype.encodeHTML = function () {
  3. return this.replace(/&/g, '&')
  4. .replace(/</g, '&lt;')
  5. .replace(/>/g, '&gt;')
  6. .replace(/"/g, '&quot;')
  7. .replace(/'/g, '&apos;');
  8. };
  9. }
  10. var transition = {pid: '', port: '8080' };
  11. // BERT Protocol
  12. var players = ["Gabrielo","Mustafa","Alina","Me"];
  13. function statsRow(start_name,i,games) {
  14. var start_score = 200;
  15. var name = template_engine(
  16. '<tspan xmlns="http://www.w3.org/2000/svg" x="{this.x}" y="{this.y}">{this.body}</tspan>',{
  17. x: start_name,
  18. y: 180+25*i,
  19. body: games[i].value[0][0] + " — " + games[i].value[0][1]});
  20. var element1 = svg(name);
  21. document.getElementById('Stat-Right').appendChild(element1);
  22. }
  23. var user_count = 0;
  24. function handle_web_socket(body) {
  25. // console.log(dec(body).value[0][0].value);
  26. switch (dec(body).value[0][0].value) {
  27. case 'roster_item':
  28. var id = dec(body).value[0][1].value;
  29. var names = dec(body).value[0][2].value;
  30. var surnames = dec(body).value[0][3].value;
  31. addOnlineUser(id,names+" "+surnames+ " "+user_count++,'appendChild');
  32. break;
  33. case 'roster_group':
  34. var list = dec(body).value[0][1];
  35. for (var i=0;i<list.length;i++) {
  36. var item = list[i];
  37. var id = item.value[0][0].value;
  38. var names = item.value[0][1].value;
  39. var surnames = item.value[0][2].value;
  40. addOnlineUser(id,names+" "+surnames+ " "+user_count++,'appendChild');
  41. }
  42. break;
  43. case 'roster_end':
  44. onlineHover();
  45. mouseWheelHandler({'detail':5,'wheelDelta':5});
  46. onlineHoverOut();
  47. break;
  48. case 'online':
  49. var id = dec(body).value[0][1].value;
  50. var name = dec(body).value[0][2].value;
  51. var surname = dec(body).value[0][3].value;
  52. removeOnlineUser(id);
  53. addOnlineUser(id,name+" "+surname,"insertTop");
  54. break;
  55. case 'offline':
  56. var id = dec(body).value[0][1].value;
  57. var name = dec(body).value[0][2].value;
  58. var surname = dec(body).value[0][3].value;
  59. removeOnlineUser(id);
  60. addOnlineUser(id,name+" "+surname,"appendChild");
  61. break;
  62. case 'online_number':
  63. var number = dec(body).value[0][1];
  64. document.getElementById("722").firstElementChild.textContent = number.toString();
  65. break;
  66. case 'stats_event':
  67. document.getElementById('Player-Statistics').style.display = '';
  68. var games = dec(body).value[0][2];
  69. var reveals = dec(body).value[0][3];
  70. var protocol = dec(body).value[0][4];
  71. removeChilds(document.getElementById('Stat-Left'));
  72. removeChilds(document.getElementById('Stat-Right'));
  73. for (var i=0;i<games.length;i++) { statsRow(24, i,games); }
  74. for (var i=0;i<protocol.length;i++) { statsRow(340,i,protocol); }
  75. // for (var i=0;i<reveals.length;i++) { statsRow(340,i,reveals); }
  76. break;
  77. }
  78. switch (dec(body).value[0][2].value) {
  79. case 'okey_game_info':
  80. var a = dec(body).value[0][3][0].value[0][1];
  81. // console.log("Players: " + a.length);
  82. for (var i=0;i<a.length;i++) {
  83. var c = a[i].value[0][3].value;
  84. var v = a[i].value[0][4].value;
  85. setPlayerName(players[i],c + " " + v);
  86. // console.log("Player: " + c + " " + v);
  87. }
  88. break;
  89. case 'okey_game_started':
  90. var a = dec(body).value[0][3][0].value[0][1];
  91. // console.log("Cards: " + a.length);
  92. for (var i=1;i<=a.length;i++) {
  93. var c = a[i-1].value[0][1];
  94. var v = a[i-1].value[0][2];
  95. // console.log("Card: " + c + " " + v);
  96. place_card(i,rand(1,2),c,v);
  97. }
  98. break;
  99. case 'okey_game_player_state': /// these two messages should be combined
  100. var a = dec(body).value[0][3][3].value[0][1];
  101. // console.log("Cards: " + a.length);
  102. for (var i=1;i<=a.length;i++) {
  103. var c = a[i-1].value[0][1];
  104. var v = a[i-1].value[0][2];
  105. // console.log("Card: " + c + " " + v);
  106. place_card(i,1,c,v);
  107. }
  108. break;
  109. case 'okey_tile_discarded':
  110. console.log(String(dec(body)));
  111. var player = dec(body).value[0][3][0].value[0][1];
  112. var tile = dec(body).value[0][3][1].value[0][1];
  113. if (player.value == document.user) {
  114. console.log("Discard: " + player.value);
  115. var p = findCardOnTable(tile.value[0][1],tile.value[0][2]);
  116. empty_card(p.x,p.y);
  117. }
  118. break;
  119. case 'okey_tile_taken':
  120. console.log(String(dec(body)));
  121. var player = dec(body).value[0][3][0].value[0][1];
  122. var taken = dec(body).value[0][3][2].value[0][1];
  123. if (taken.value != 'null' && player.value == document.user) {
  124. console.log("Taken: " + player.value);
  125. var c = taken.value[0][1];
  126. var v = taken.value[0][2];
  127. var pos = findPlace();
  128. // console.log(pos);
  129. place_card(pos.x,pos.y,c,v);
  130. }
  131. break;
  132. default:
  133. console.log(String(dec(body)));
  134. }
  135. }
  136. // SVG DOM and Template Engine
  137. function template_engine(html, data) {
  138. var re = /{([^}]+)?}/g, code = 'var r=[];', cursor = 0;
  139. var add = function(line,js) {
  140. js? (code += 'r.push(' + line + ');') :
  141. (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");' : '');
  142. return add; }
  143. while(match = re.exec(html)) {
  144. add(html.slice(cursor, match.index))(match[1],true);
  145. cursor = match.index + match[0].length; }
  146. add(html.substr(cursor, html.length - cursor));
  147. code += 'return r.join("");';
  148. return new Function(code.replace(/[\r\t\n]/g, '')).apply(data); }
  149. function reload(file, name) { var slot = document.getElementById(name);
  150. slot.parentNode.replaceChild(svg(localStorage.getItem(file)),slot);}
  151. function reload_cont(cont,name,element) { if (null != cont) (cont)(); else reload(name,element); }
  152. function loadFile(name,cont,element) {
  153. if (localStorage.getItem(name) == null) {
  154. var client = new XMLHttpRequest();
  155. client.open('GET', name, true);
  156. client.onload = function() {
  157. localStorage.setItem(name,client.responseText);
  158. reload_cont(cont,name,element); }
  159. client.send(); }
  160. else reload_cont(cont,name,element); }
  161. function svg(html) {
  162. return new DOMParser().parseFromString(html, "text/xml").firstChild;
  163. }
  164. function svgBulk() {
  165. var res = [];
  166. var node = new DOMParser().parseFromString(html, "text/xml").firstChild;
  167. for (var i=0;i<node.childnode.length;i++) { var child = childNodes.item(i);
  168. if (child.tagName != undefined) res.push(child); } }
  169. // The Card
  170. //var color = ['#CE290F','#3B5998','#48AF5E','#FFEC00'];
  171. var color = ['#DE3F26','#606060','#48AF5E','#FFC800'];
  172. var slotName = slotNameDef;
  173. function slotNameDef(x,y) { return "Slot-"+y+","+x; }
  174. function card(line,pos,col,v) {
  175. return template_engine(
  176. localStorage.getItem("templates/Card.svg"),
  177. { name: slotName(pos,line),
  178. suit: color[col-1],
  179. value: v,
  180. y: (line-1)*69,
  181. x: (pos-1)*42 }); }
  182. // Game Scene
  183. function setPlayerName(e, playerName) {
  184. var dx = (document.getElementById(e).attributes['fill'].value == "#FFFFFF") ? 65 : 20;
  185. document.getElementById(e).setAttribute("y",27);
  186. document.getElementById(e).setAttribute("x",dx);
  187. document.getElementById(e).textContent = playerName;
  188. // console.log("Bounding Box: " + document.getElementById(e).getBBox().width);
  189. document.getElementById(e+"-Pad").setAttribute('width',
  190. document.getElementById(e).getBBox().width + 45); }
  191. function place_card(x,y,c,v) {
  192. var slot = document.getElementById(slotName(x,y));
  193. slot.parentNode.replaceChild(svg(card(y,x,c,v)),slot); }
  194. function empty_card(x,y) { var slot = document.getElementById(slotName(x,y));
  195. var html = '<g xmlns="http://www.w3.org/2000/svg" id="'+slotName(x,y)+'"/>';
  196. slot.parentNode.replaceChild(svg(html),slot); }
  197. function rand(lo,hi) { return Math.floor((Math.random()*hi)+lo); }
  198. function loadScene() {
  199. reload("Kakaranet-Scene.svg", "Refined");
  200. for (var i=1;i<16;i++) { empty_card(i,2); empty_card(i,1); }
  201. //drawSampleCards();
  202. }
  203. function findPlace() {
  204. for (var y=1;y<3;y++) for (var x=1;x<15;x++) {
  205. var e = document.getElementById(slotName(x,y));
  206. if (e.childElementCount == 0) {
  207. var pos = e.attributes['id'].value.split("-")[1].split(",");
  208. console.log("Free");
  209. console.log(pos[0]);
  210. console.log(pos[1]);
  211. return { y: pos[0], x: pos[1] }; } } }
  212. function findCardOnTable(c,v) {
  213. console.log("Find Card " + c + " " + v);
  214. for (var y=1;y<3;y++) for (var x=1;x<15;x++) {
  215. var e = document.getElementById(slotName(x,y));
  216. if (e.childElementCount > 0) {
  217. var value = e.lastChild.textContent;
  218. var col = color.indexOf(e.lastChild.attributes['fill'].value) + 1;
  219. console.log(col + " " + value);
  220. if (c == col && v == value) return { 'x': x, 'y': y }; } }
  221. console.log("Card Not Found");
  222. return ""; }
  223. function loadAppend(file, animation, name) {
  224. loadFile(file, function() {
  225. var slot = document.getElementById(name);
  226. var r = template_engine(localStorage.getItem(file),{'name': animation});
  227. document.getElementById(name).appendChild(svg(r)); }); }
  228. function loadAnimationForButton(a, b) { return loadAppend('templates/ButtonAnimation.svg', a, b); }
  229. // TODO: Rollout Monadic Chain here
  230. loadFile('templates/Card.svg', function() {
  231. loadFile('Kakaranet-Scene.svg', function() {
  232. loadScene();
  233. var a = [{button: "Create", pathes: ["CreateShow", "CreateHide"]},
  234. {button: "Play", pathes: ["PlayShow", "PlayHide"]}];
  235. for (var y=0;y<a.length;y++) for (var x=0;x<a[y].pathes.length;x++)
  236. loadAnimationForButton(a[y].pathes[x],a[y].button);
  237. document.getElementById("Right-Menu") .setAttribute('onclick', 'onRightMenu(evt)');
  238. document.getElementById("Play") .setAttribute('onclick', 'onRightMenuDown(evt)');
  239. document.getElementById("Create") .setAttribute('onclick', 'onRightMenuDown(evt)');
  240. document.getElementById("Point-Table").setAttribute('onclick', 'onPlayerInfo(evt)');
  241. document.getElementById("Player-Statistics").setAttribute('onclick', 'onPlayerInfoClose(evt)');
  242. document.getElementById('Page-1').addEventListener("mousewheel", mouseWheelHandler, false);
  243. onRightMenuDown();
  244. });
  245. });
  246. var clipPath1 = svg('<clipPath id="myClip1"><rect xmlns="http://www.w3.org/2000/svg" id="Clip-Path-Left" x="0" y="0" width="216" height="400"/></clipPath>');
  247. var clipPath2 = svg('<clipPath id="myClip2"><rect xmlns="http://www.w3.org/2000/svg" id="Clip-Path-Right" x="0" y="0" width="216" height="400"/></clipPath>');
  248. document.getElementsByTagName('defs').item(0).appendChild(clipPath1);
  249. document.getElementsByTagName('defs').item(0).appendChild(clipPath2);
  250. document.getElementById("Online-List").setAttribute("clip-path","url(#myClip1)");
  251. document.getElementById("Chat").setAttribute("clip-path","url(#myClip2)");
  252. document.getElementById("Clip-Path-Left").setAttribute("transform", "translate(0,0)");
  253. document.getElementById("Clip-Path-Right").setAttribute("transform", "translate(0,0)");
  254. document.getElementById('Player-Statistics').style.display = 'none';
  255. document.getElementById("Right-Bar").setAttribute("fill","skyblue");
  256. document.getElementById("Right-Bar").onmouseover = barHover;
  257. document.getElementById("Right-Bar").onmouseout = barHoverOut;
  258. document.getElementById("Left-Bar").onmouseover = onlineHover;
  259. document.getElementById("Left-Bar").onmouseout = onlineHoverOut;
  260. document.getElementById('edit').setAttribute("contentEditable","true");
  261. document.getElementById('edit').onkeydown = chatEditor;
  262. var removeChilds = function (node) {
  263. var last;
  264. while (last = node.lastChild) node.removeChild(last);
  265. };
  266. function onPlayerInfo(evt) {
  267. ws.send(enc(tuple(atom('client'),
  268. tuple(atom('stats_action'),bin(document.user),atom('game_okey')))));
  269. }
  270. function onPlayerInfoClose(evt) {
  271. document.getElementById('Player-Statistics').style.display = 'none';
  272. }
  273. function onRightMenu(evt) {
  274. localStorage.clear();
  275. ["PlayShow","CreateShow"].map(function (x) {
  276. document.getElementById(x+"-Motion").beginElement(); }); }
  277. function onRightMenuDown(evt) {
  278. ["PlayHide","CreateHide"].map(function (x) {
  279. document.getElementById(x+"-Motion").beginElement(); }); }
  280. // SVG Samples for svg.htm
  281. /*
  282. loadFile('templates/Mustafa-Persona.svg', null, "Mustafa-Persona-Sample");
  283. loadFile('templates/Mustafa-Selection.svg', null, "Mustafa-Selection-Sample");
  284. document.getElementById("MustafaSelection").addEventListener('click', function() {
  285. var style = document.getElementById("Mustafa-Selection-Sample").style;
  286. if (style.display == 'none') style.display = 'block';
  287. else style.display = 'none'; });
  288. */
  289. function slotName1(x,y) { return "1Slot-"+y+","+x; }
  290. function drawSampleCards() {
  291. slotName = slotName1;
  292. for (var i=1;i<15;i++) { place_card(i,rand(1,2),rand(1,4),rand(1,13)); }
  293. slotName = slotNameDef; }
  294. var scrollSensitivity = 0.2;
  295. var scroll_left = 5;
  296. var scroll_right = -10000;
  297. function chatMessage(id, me, string) {
  298. var i=0;
  299. var colors=['#FDFDFD','#DFF1F4'];
  300. var x1 = 7;
  301. var y1 = 0;
  302. var translate_y = parseFloat(document.getElementById("Chat").getBBox().height);
  303. var x2 = 205;
  304. var textElement = chatText(id,me,string);
  305. var dy = translate_y == 0 ? 0 : translate_y + 10;
  306. var html = "<g xmlns='http://www.w3.org/2000/svg' " +
  307. "id='Message-"+id+"' transform='translate(0,"+dy+")'></g>";
  308. var messageElement = svg(html);
  309. messageElement.appendChild(textElement);
  310. document.getElementById("Chat").appendChild(messageElement);
  311. create_multiline(textElement);
  312. var y2 = textElement.getBBox().height + 5;
  313. var box = "<path xmlns='http://www.w3.org/2000/svg' d='M"+x1+","+y1+
  314. " L"+x2+","+y1+
  315. ((me == "Maxim") ?
  316. (" L"+x2+","+parseFloat(y2-7)+
  317. " L"+parseFloat(x2+7)+","+y2+
  318. " L"+x1+","+y2)
  319. :
  320. (" L"+x2+","+y2+
  321. " L"+0+","+y2+
  322. " L"+x1+","+parseFloat(y2-7)))
  323. + " L"+x1+","+y1+"' fill='"+colors[me=="Maxim"?1:0]+"'></path>";
  324. var boxElement = svg(box);
  325. messageElement.insertBefore(boxElement,textElement);
  326. boxElement.setAttribute("mouseover","barHover(evt);");
  327. boxElement.setAttribute("mouseout","barHoverOut(evt);");
  328. textElement.setAttribute("mouseover","barHover(evt);");
  329. textElement.setAttribute("mouseout","barHoverOut(evt);");
  330. messageElement.setAttribute("onmouseover","barHover(evt);");
  331. messageElement.setAttribute("onmouseout","barHoverOut(evt);");
  332. // console.log(messageElement);
  333. }
  334. function chatText(id, me, string) {
  335. var i = 0;
  336. var colors=['#3B5998'];
  337. var html = "<text id='ChatText-"+id+"' width='180' " +
  338. " xmlns='http://www.w3.org/2000/svg' "+
  339. " font-family='Exo 2' font-size='16' font-weight='normal' fill='"+colors[i]+"'>" +
  340. string + "</text>";
  341. // console.log(html);
  342. return svg(html);
  343. }
  344. function mouseWheelHandler(e) {
  345. var leftBar = document.getElementById("Left-Bar");
  346. var rightBar = document.getElementById("Right-Bar");
  347. var leftFill = leftBar.getAttribute("fill");
  348. var rightFill = rightBar.getAttribute("fill");
  349. var leftActive = leftFill == "skyblue";
  350. var rightActive = rightFill == "skyblue";
  351. if (!leftActive && !rightActive) return;
  352. // console.log(leftActive);
  353. var evt = e;
  354. var scroll_dy = evt.detail ? evt.detail * scrollSensitivity : evt.wheelDelta * scrollSensitivity;
  355. var ori = leftActive ? scroll_left : scroll_right;
  356. var scroll = parseFloat(scroll_dy) + parseFloat(ori);
  357. var selectedBar = leftActive ? "Online-List" : "Chat";
  358. var selectedClip = leftActive ? "Clip-Path-Left" : "Clip-Path-Right";
  359. var selectedBarShift = leftActive ? 0 : 857;
  360. var limit = parseFloat(document.getElementById(selectedBar).getBBox().height) - 400;
  361. if (scroll > 5) scroll = 5;
  362. if (scroll < -limit) scroll = -limit;
  363. document.getElementById(selectedClip).setAttribute("transform", "translate(0,"+parseFloat(-scroll)+")");
  364. document.getElementById(selectedBar).setAttribute("transform", "translate("+selectedBarShift+","+(parseFloat(95+scroll))+")");
  365. if (leftActive) scroll_left = scroll; else scroll_right = scroll;
  366. return true;
  367. }
  368. var svgNS = "http://www.w3.org/2000/svg";
  369. function create_multiline(target) {
  370. var text_element = target; // evt.target;
  371. var width = 190; //target.getAttribute("width");
  372. var words = text_element.firstChild.data.split('');
  373. // console.log(words);
  374. // var words = [].concat.apply([],lines.map(function(line) { return line.split(' '); }));;
  375. var start_x = 15; //text_element.getAttribute('x');
  376. text_element.firstChild.data = '';
  377. var tspan_element = document.createElementNS(svgNS, "tspan");
  378. tspan_element.setAttribute("x", start_x);
  379. tspan_element.setAttribute("dy", 18);
  380. var text_node = document.createTextNode(words[0]);
  381. tspan_element.appendChild(text_node);
  382. text_element.appendChild(tspan_element);
  383. for(var i=1; i<words.length; i++) {
  384. if (words[i]=="") continue;
  385. var len = tspan_element.firstChild.data.length;
  386. tspan_element.firstChild.data += words[i];
  387. if (tspan_element.getComputedTextLength() > width || words[i]=="\n") {
  388. if (words[i]=='\n') words[i]="";
  389. tspan_element.firstChild.data = tspan_element.firstChild.data.slice(0, len);
  390. var tspan_element = document.createElementNS(svgNS, "tspan");
  391. tspan_element.setAttribute("x", start_x);
  392. tspan_element.setAttribute("dy", 18);
  393. text_node = document.createTextNode(words[i]);
  394. tspan_element.appendChild(text_node);
  395. text_element.appendChild(tspan_element);
  396. }
  397. }
  398. }
  399. function barHover(evt) { document.getElementById("Right-Bar").setAttribute("fill","skyblue"); }
  400. function barHoverOut(evt) { document.getElementById("Right-Bar").setAttribute("fill","lightblue"); }
  401. function onlineHover(evt) { document.getElementById("Left-Bar").setAttribute("fill","skyblue"); }
  402. function onlineHoverOut(evt) { document.getElementById("Left-Bar").setAttribute("fill","lightblue"); }
  403. function onlineHoverColor(evt) {
  404. onlineHover(evt);
  405. var name = evt.target.getAttribute("xmlns:data");
  406. if (null != name) document.getElementById(name).setAttribute("fill","#FFF687");
  407. }
  408. function onlineHoverOutColor(evt) {
  409. onlineHoverOut(evt);
  410. var name = evt.target.getAttribute("xmlns:data");
  411. if (null != name) document.getElementById(name).setAttribute("fill","#DBEBED");
  412. }
  413. function chatEditor(evt) {
  414. if (evt.keyCode == 13 && evt.metaKey == false) {
  415. var e = document.getElementById('edit');
  416. if (e.innerText.trim() != ""){
  417. chatMessage("100","Maxim",e.innerText.trim().encodeHTML());
  418. e.innerHTML = '';
  419. }
  420. } else if (evt.keyCode == 13 && evt.metaKey == true) {
  421. document.execCommand('insertText',false, '\n');
  422. }
  423. var scroll = -1000000;
  424. mouseWheelHandler({'detail':scroll,'wheelDelta':scroll});
  425. }
  426. function shiftTranslate(name,shiftValue) {
  427. var rect = document.getElementById(name);
  428. if (null == rect) return;
  429. var remove = rect.parentNode.parentNode;
  430. var children = document.getElementById("Online-List").childNodes;
  431. var removeIndex = -1;
  432. for(var i = 0; i<children.length; ++i) {
  433. var child = children[i];
  434. if (child == remove) removeIndex = i;
  435. if (removeIndex != -1 && i>=removeIndex)
  436. child.setAttribute("transform","translate(0,"+(parseFloat(i)+parseFloat(shiftValue))
  437. *remove.getBBox().height+")");
  438. }
  439. return rect.parentNode.parentNode;
  440. }
  441. function removeOnlineUser(name) {
  442. shiftTranslate(name,-2).remove();
  443. }
  444. function addOnlineUser(name,full_name,insertMode) {
  445. var listElement = document.getElementById("Online-List");
  446. var color = insertMode == "insertTop" ? "red" : "green";
  447. var y = (insertMode == "insertTop") ? "0" : listElement.getBBox().height;
  448. var html = '<g xmlns="http://www.w3.org/2000/svg" height="60" transform="translate(0, '+y+')">' +
  449. '<g xmlns:data="'+name+'"fill="#DBEBED" onmouseover="onlineHoverColor(evt);" onmouseout="onlineHoverOutColor(evt);">' +
  450. ' <rect xmlns:data="'+name+'" fill="#DBEBED" id="'+name+'" x="10" y="0" width="196" height="48" onmouseover="onlineHoverColor(evt);" onmouseout="onlineHoverOutColor(evt);"></rect></g>' +
  451. '<text xmlns:data="'+name+'" onmouseover="onlineHoverColor(evt);" onmouseout="onlineHoverOutColor(evt);" '+
  452. 'font-family="Exo 2" font-size="18" font-weight="normal" line-spacing="18"'+
  453. ' fill="#3B5998">' +
  454. '<tspan xmlns:data="'+name+'" font-weight="normal" fill="'+color+'" x="19" y="22">'+full_name+'</tspan>' +
  455. '<tspan xmlns:data="'+name+'" font-size="14" x="19" y="40">Score: 1043 Pos: 13</tspan></text>'+
  456. '<rect onmouseover="onlineHover(evt);" onmouseout="onlineHoverOut(evt);"'+
  457. ' x="10" y="48" width="196" height="8"></rect></g>';
  458. var element = svg(html);
  459. if (insertMode == "insertTop") {
  460. var firstElement = listElement.firstElementChild;
  461. var first = firstElement.firstElementChild.getAttribute("xmlns:data");
  462. shiftTranslate(first,0);
  463. listElement.insertBefore(element,firstElement);
  464. } else listElement.appendChild(element);
  465. }
  466. chatMessage("1","Maxim2","Joe:\nHello There!".encodeHTML());
  467. chatMessage("2","Maxim2","Alice:\nYou got new Design. Eh?".encodeHTML());
  468. chatMessage("3","Maxim","Maxim So:\nThis was made with pure SVG".encodeHTML());
  469. /*
  470. for (var i=0;i<5;i++) {
  471. addOnlineUser("Maxim1"+i,"Maxim Sokhatsky",'appendChild');
  472. addOnlineUser("Maxim2"+i,"Sinan Ustel",'appendChild');
  473. addOnlineUser("Maxim3"+i,"Ahmet Tez",'appendChild');
  474. addOnlineUser("Maxim4"+i,"Alice Cooper",'appendChild');
  475. }
  476. */
  477. barHover();
  478. mouseWheelHandler({'detail':-100000,'wheelDelta':-100000});
  479. barHoverOut();