not really known
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.

652 lines
23 KiB

  1. define([
  2. "sugar-web/activity/activity",
  3. "activity/palettes/format-text-palette",
  4. "activity/palettes/list-palette",
  5. "activity/palettes/paragraph-palette",
  6. "activity/palettes/font-palette",
  7. "sugar-web/graphics/colorpalette",
  8. "sugar-web/datastore",
  9. "sugar-web/graphics/journalchooser",
  10. "sugar-web/env",
  11. "sugar-web/graphics/presencepalette",
  12. "activity/palettes/export-palette",
  13. "webL10n",
  14. ], function (activity,formatpalette,listpalette,parapalette,fontPalette,colorpalette , datastore , journalchooser,env,presencepalette,exportpalette,webL10n) {
  15. // Manipulate the DOM only when it is ready.
  16. requirejs(['domReady!','humane'], function (doc,humane) {
  17. // Initialize the activity.
  18. activity.setup();
  19. var options = {
  20. modules: {
  21. toolbar: '#main-toolbar',
  22. history: {
  23. maxStack: 500,
  24. },
  25. imageResize: {},
  26. cursors: {
  27. transformOnTextChange: true,
  28. },
  29. clipboard: true
  30. },
  31. };
  32. Quill.register('modules/cursors', QuillCursors);
  33. var container = document.getElementById('editor');
  34. var editor = new Quill(container,options);
  35. editor.focus();
  36. editor.format('size','24px');
  37. const cursors = editor.getModule('cursors');
  38. const Delta = Quill.import('delta');
  39. // Journal Handling (Load)
  40. env.getEnvironment(function(err, environment) {
  41. currentenv = environment;
  42. // Language Settings
  43. var defaultLanguage = (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language;
  44. var language = environment.user ? environment.user.language : defaultLanguage;
  45. webL10n.language.code = language;
  46. window.addEventListener("localized", function() {
  47. document.getElementById("network-button").title = webL10n.get("Network");
  48. document.getElementById("color-button-1").title = webL10n.get("ForegroundColor");
  49. document.getElementById("color-button-2").title = webL10n.get("BackgroundColor");
  50. document.getElementById("format-text").title = webL10n.get("Formattext");
  51. document.getElementById("paragraph").title = webL10n.get("Paragraph");
  52. document.getElementById("list").title = webL10n.get("List");
  53. document.getElementById("resize-inc").title = webL10n.get("Increasefontsize");
  54. document.getElementById("font-button").title = webL10n.get("ChooseFont");
  55. document.getElementById("resize-dec").title = webL10n.get("Decreasefontsize");
  56. document.getElementById("insert-picture").title = webL10n.get("Image");
  57. document.getElementById("edit-undo").title = webL10n.get("Undo");
  58. document.getElementById("edit-redo").title = webL10n.get("Redo");
  59. document.getElementById("edit-copy").title = webL10n.get("Copy");
  60. document.getElementById("edit-paste").title = webL10n.get("Paste");
  61. document.getElementById("export").title = webL10n.get("Export");
  62. document.getElementById(5).title = webL10n.get("Bold");
  63. document.getElementById(6).title = webL10n.get("Italic");
  64. document.getElementById(7).title = webL10n.get("Underline");
  65. document.getElementById(8).title = webL10n.get("Strike");
  66. document.getElementById(9).title = webL10n.get("OrderedList");
  67. document.getElementById(10).title = webL10n.get("UnorderedList");
  68. document.getElementById(11).title = webL10n.get("JustifyLeft");
  69. document.getElementById(12).title = webL10n.get("JustifyRight");
  70. document.getElementById(13).title = webL10n.get("JustifyCenter");
  71. document.getElementById(19).title = webL10n.get("ExportToTxt");
  72. document.getElementById(20).title = webL10n.get("ExportToPdf");
  73. document.getElementById(21).title = webL10n.get("ExportToDoc");
  74. document.getElementById(22).title = webL10n.get("ExportToOdt");
  75. });
  76. if (!environment.objectId && !environment.sharedId) {
  77. // New instance
  78. // Intentionally added setTimeout to allow locale.ini file to be loaded
  79. setTimeout(function(){
  80. editor.setContents([
  81. {insert: webL10n.get('Welcome',{username: environment.user.name}) + '\n' , attributes: { size: "40px" , color : environment.user.colorvalue.stroke , bold: true }},
  82. ]);
  83. var length = editor.getLength();
  84. editor.clipboard.dangerouslyPasteHTML(length,webL10n.get('Write'));
  85. length = editor.getLength();
  86. editor.clipboard.dangerouslyPasteHTML(length,webL10n.get('Writefeatures'));
  87. length = editor.getLength();
  88. editor.clipboard.dangerouslyPasteHTML(length,webL10n.get('Enjoy'));
  89. length = editor.getLength();
  90. editor.clipboard.dangerouslyPasteHTML(length,"<br></br>");
  91. length = editor.getLength();
  92. editor.updateContents(
  93. new Delta()
  94. .retain(editor.getSelection().index+1)
  95. .insert({
  96. image: window.initialImageDataUrl
  97. })
  98. );
  99. },200);
  100. } else {
  101. // Existing instance
  102. activity.getDatastoreObject().loadAsText(function(error, metadata, data) {
  103. if (error==null && data!=null) {
  104. var delta = JSON.parse(data);
  105. console.log(delta);
  106. editor.setContents(delta);
  107. }
  108. });
  109. }
  110. // Shared instances
  111. if (environment.sharedId) {
  112. console.log("Shared instance");
  113. // Hide GUI of undo and redo for non host users
  114. document.getElementById("edit-undo").style.display = "none";
  115. document.getElementById("edit-redo").style.display = "none";
  116. document.getElementById("shared-button").click();
  117. presence = activity.getPresenceObject(function(error, network) {
  118. network.onDataReceived(onNetworkDataReceived);
  119. network.onSharedActivityUserChanged(onNetworkUserChanged);
  120. });
  121. }
  122. });
  123. // Save in Journal on Stop
  124. document.getElementById("stop-button").addEventListener('click', function (event) {
  125. // Journal handling
  126. var data = editor.getContents();
  127. var jsondata = JSON.stringify(data);
  128. activity.getDatastoreObject().setDataAsText(jsondata);
  129. activity.getDatastoreObject().save(function (error) {
  130. if (error === null) {
  131. console.log("write done.");
  132. } else {
  133. console.log("write failed.");
  134. }
  135. });
  136. });
  137. var changeMadebyUser=false;
  138. var copiedContent = null ;
  139. document.getElementById("edit-copy").addEventListener('click',function(){
  140. var range = editor.getSelection();
  141. copiedContent = editor.getContents(range.index,range.length);
  142. document.execCommand('copy');
  143. });
  144. document.getElementById("edit-paste").addEventListener('click',function(){
  145. if(document.execCommand('paste')){
  146. // Your browser supports execCommand('paste')
  147. } else if(copiedContent!=null) {
  148. // Your browser does not support execCommand('paste')
  149. changeMadebyUser=true;
  150. editor.updateContents(
  151. new Delta()
  152. .retain(editor.getSelection().index)
  153. .concat(copiedContent)
  154. );
  155. }
  156. });
  157. // Sync Keyboard Shortcut of copy with custom events
  158. editor.keyboard.addBinding({ key: 'C', shortKey: true }, function(){document.getElementById("edit-copy").click()});
  159. document.getElementById("edit-undo").addEventListener('click',function(){
  160. editor.history.undo();
  161. });
  162. document.getElementById("edit-redo").addEventListener('click',function(){
  163. editor.history.redo();
  164. });
  165. // Initiating format-text-palette ( for cut/copy/undo/redo )
  166. var formatButton = document.getElementById("format-text");
  167. var formatoptions = [
  168. {"id": 5, "title": "bold", "cmd":"bold"},
  169. {"id": 6, "title": "italic", "cmd":"italic"},
  170. {"id": 7, "title": "underline", "cmd":"underline"},
  171. {"id": 8, "title": "strike", "cmd":"strikeThrough"}
  172. ];
  173. formatpalette = new formatpalette.Formatpalette(formatButton, undefined);
  174. formatpalette.setCategories(formatoptions);
  175. formatpalette.addEventListener('format', function () {
  176. formatpalette.popDown();
  177. editor.focus();
  178. });
  179. document.getElementById(5).addEventListener('click',function(){
  180. document.getElementById("bold").click();
  181. });
  182. document.getElementById(6).addEventListener('click',function(){
  183. document.getElementById("italic").click();
  184. });
  185. document.getElementById(7).addEventListener('click',function(){
  186. document.getElementById("underline").click();
  187. });
  188. document.getElementById(8).addEventListener('click',function(){
  189. document.getElementById("strike").click();
  190. });
  191. // Initiating lists palette
  192. var listButton = document.getElementById("list");
  193. var listoptions = [
  194. {"id": 10, "title": "unordered list", "cmd":"insertUnorderedList"},
  195. {"id": 9, "title": "ordered list", "cmd":"insertorderedList"},
  196. ];
  197. listpalette = new listpalette.Listpalette(listButton, undefined);
  198. listpalette.setCategories(listoptions);
  199. listpalette.addEventListener('list', function () {
  200. listpalette.popDown();
  201. });
  202. document.getElementById("9").addEventListener("click",function(){
  203. document.getElementById("list-ordered").click();
  204. });
  205. document.getElementById("10").addEventListener("click",function(){
  206. document.getElementById("list-unordered").click();
  207. });
  208. // Initiating paragraph palette ( Alignment settings )
  209. var paraButton = document.getElementById("paragraph");
  210. var paraoptions = [
  211. {"id": 11, "title":"justify Left" , "cmd":"justifyLeft"},
  212. {"id": 13, "title":"justify Center" , "cmd":"justifyCenter"},
  213. {"id": 12, "title":"justify Right" , "cmd":"justifyRight"},
  214. ];
  215. parapalette = new parapalette.Parapalette(paraButton, undefined);
  216. parapalette.setCategories(paraoptions);
  217. parapalette.addEventListener('para', function () {
  218. parapalette.popDown();
  219. editor.focus();
  220. });
  221. document.getElementById(11).addEventListener("click",function(){
  222. changeMadebyUser=true;
  223. editor.format('align','justify');
  224. })
  225. document.getElementById(12).addEventListener("click",function(){
  226. changeMadebyUser=true;
  227. editor.format('align','right');
  228. });
  229. document.getElementById(13).addEventListener("click",function(){
  230. changeMadebyUser=true;
  231. editor.format('align','center');
  232. });
  233. // Initialise font palette
  234. var fontButton = document.getElementById("font-button");
  235. fontPalette = new fontPalette.Fontpalette(fontButton);
  236. fontPalette.addEventListener('fontChange', function(e) {
  237. var newfont = e.detail.family;
  238. if(newfont=="Arial") newfont="arial";
  239. if(newfont=="Comic Sans MS") newfont="comic";
  240. changeMadebyUser=true;
  241. editor.format('font',newfont);
  242. });
  243. // Initiating colour palette for foreground and background
  244. var forecolorButton = document.getElementById("color-button-1");
  245. var changeForeColorPalette = new colorpalette.ColorPalette(forecolorButton);
  246. changeForeColorPalette.setColor('rgb(0, 0, 0)');
  247. changeForeColorPalette.addEventListener('colorChange', function(e) {
  248. changeMadebyUser=true;
  249. editor.format('color',e.detail.color);
  250. });
  251. var backcolorButton = document.getElementById("color-button-2");
  252. var changeBackColorPalette = new colorpalette.ColorPalette(backcolorButton);
  253. changeBackColorPalette.setColor('rgb(255,255,255)');
  254. changeBackColorPalette.addEventListener('colorChange', function(e) {
  255. changeMadebyUser=true;
  256. editor.format('background-color',e.detail.color);
  257. });
  258. // Initiating font-size-palette
  259. // For increase
  260. var sizes = ['16px', '24px', '32px' ,'40px', '48px' , '56px', '64px' , '72px' , '80px' , '100px'];
  261. var sizeIncButton = document.getElementById("resize-inc");
  262. sizeIncButton.addEventListener("click",function(){
  263. var currentSize = editor.getFormat();
  264. if(currentSize.size==null){
  265. var index = sizes.indexOf('24px');
  266. editor.format('size',sizes[index+1]);
  267. }
  268. else {
  269. var index = sizes.indexOf(currentSize.size);
  270. index++;
  271. if(index<sizes.length){
  272. editor.format('size',sizes[index]);
  273. }
  274. }
  275. });
  276. // For decrease
  277. var sizeDecButton = document.getElementById("resize-dec");
  278. sizeDecButton.addEventListener("click",function(){
  279. var currentSize = editor.getFormat();
  280. if(currentSize.size==null){
  281. var index = sizes.indexOf('24px');
  282. if(index>0)
  283. editor.format('size',sizes[index-1]);
  284. }
  285. else {
  286. var index = sizes.indexOf(currentSize.size);
  287. index--;
  288. if(index>=0){
  289. editor.format('size',sizes[index]);
  290. }
  291. }
  292. });
  293. // Insert Image handling
  294. document.getElementById("insert-picture").addEventListener("click",function(e){
  295. journalchooser.show(function (entry) {
  296. if (!entry) {
  297. return;
  298. }
  299. var dataentry = new datastore.DatastoreObject(entry.objectId);
  300. dataentry.loadAsText(function (err, metadata, data) {
  301. editor.focus();
  302. changeMadebyUser=true;
  303. editor.updateContents(
  304. new Delta()
  305. .retain(editor.getSelection().index)
  306. .insert({
  307. image: data
  308. })
  309. );
  310. });
  311. }, { mimetype: 'image/png' }, { mimetype: 'image/jpeg' });
  312. });
  313. // Initiating export-palette
  314. var exportButton = document.getElementById("export");
  315. var options = [
  316. {"id": 19, "title": "export to txt" , "cmd":"save-as-txt"},
  317. {"id": 20, "title": "export to pdf", "cmd":"save-as-pdf"},
  318. {"id": 21, "title": "export to doc", "cmd":"doc"},
  319. {"id": 22, "title": "export to odt", "cmd":"odt"},
  320. ];
  321. exportpalette = new exportpalette.Exportpalette(exportButton, undefined);
  322. exportpalette.setCategories(options);
  323. exportpalette.addEventListener('export', function () {
  324. exportpalette.popDown();
  325. });
  326. // save as txt
  327. document.getElementById("19").addEventListener('click',function(){
  328. var title = document.getElementById("title").value;
  329. var mimetype = 'text/plain';
  330. var inputData = document.getElementById("editor").textContent;
  331. inputData=JSON.stringify(inputData);
  332. var metadata = {
  333. mimetype: mimetype,
  334. title: title+".txt",
  335. activity: "",
  336. timestamp: new Date().getTime(),
  337. creation_time: new Date().getTime(),
  338. file_size: 0
  339. };
  340. datastore.create(metadata, function() {
  341. console.log("export done.");
  342. humane.log(webL10n.get("Txt"));
  343. }, inputData);
  344. });
  345. // save as PDF
  346. document.getElementById("20").addEventListener('click',function(){
  347. var title = document.getElementById("title").value;
  348. editor.scrollingContainer.style.overflowY = 'visible';
  349. console.log(editor.scrollingContainer.style.height);
  350. var h = editor.scrollingContainer.offsetHeight;
  351. editor.scrollingContainer.style.height="auto";
  352. editor.scrollingContainer.scrollTop=0;
  353. html2canvas(editor.scrollingContainer).then(function(canvas){
  354. editor.scrollingContainer.style.height=h;
  355. editor.scrollingContainer.style.overflowY = 'auto';
  356. var imgData = canvas.toDataURL('image/png');
  357. var imgData = canvas.toDataURL('image/png');
  358. var imgWidth = 210;
  359. var pageHeight = 295;
  360. var imgHeight = canvas.height * imgWidth / canvas.width;
  361. var heightLeft = imgHeight;
  362. var doc = new jsPDF('p', 'mm' , '',true);
  363. var position = 0;
  364. doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight , '' , 'FAST');
  365. heightLeft -= pageHeight;
  366. while (heightLeft >= 0) {
  367. position = heightLeft - imgHeight;
  368. doc.addPage();
  369. doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight , '' , 'FAST');
  370. heightLeft -= pageHeight;
  371. }
  372. var inputData = doc.output('dataurlstring');
  373. var mimetype = 'application/pdf';
  374. var metadata = {
  375. mimetype: mimetype,
  376. title: title+".pdf",
  377. activity: "",
  378. timestamp: new Date().getTime(),
  379. creation_time: new Date().getTime(),
  380. file_size: 0
  381. };
  382. datastore.create(metadata, function() {
  383. console.log("export done.");
  384. humane.log(webL10n.get("Pdf"));
  385. }, inputData);
  386. });
  387. });
  388. // Save as doc
  389. document.getElementById(21).addEventListener("click",function(){
  390. var title = document.getElementById("title").value;
  391. var content =document.getElementById("editor").innerHTML;
  392. var header = "<html xmlns:o='urn:schemas-microsoft-com:office:office' "+
  393. "xmlns:w='urn:schemas-microsoft-com:office:word' "+
  394. "xmlns='http://www.w3.org/TR/REC-html40'>"+
  395. "<head><meta charset='utf-8'></head><body>";
  396. var footer = "</body></html>";
  397. var sourceHTML = header+content+footer;
  398. var inputData = 'data:application/vnd.ms-word;charset=utf-8;base64,' + btoa(unescape(encodeURIComponent( sourceHTML )));
  399. var mimetype = 'application/msword';
  400. var metadata = {
  401. mimetype: mimetype,
  402. title: title+".doc",
  403. activity: "",
  404. timestamp: new Date().getTime(),
  405. creation_time: new Date().getTime(),
  406. file_size: 0
  407. };
  408. datastore.create(metadata, function() {
  409. console.log("export done.");
  410. humane.log(webL10n.get("Doc"));
  411. }, inputData);
  412. });
  413. //Save as odt
  414. document.getElementById("22").addEventListener("click",function(){
  415. // resetXML();
  416. var data = document.getElementsByClassName("ql-editor");
  417. var xml = traverse(data[0]);
  418. var mimetype = 'application/vnd.oasis.opendocument.text';
  419. var title = document.getElementById("title").value;
  420. var inputData = 'data:application/vnd.oasis.opendocument.text;charset=utf-8;base64,' + btoa(unescape(encodeURIComponent( xml )));
  421. var metadata = {
  422. mimetype: mimetype,
  423. title: title+".odt",
  424. activity: "",
  425. timestamp: new Date().getTime(),
  426. creation_time: new Date().getTime(),
  427. file_size: 0
  428. };
  429. datastore.create(metadata, function() {
  430. console.log("export done.");
  431. humane.log(webL10n.get("Odt"));
  432. resetXML();
  433. }, inputData);
  434. });
  435. // On content change handlers , sends data to other users on content being changed
  436. editor.on('text-change', function(delta, oldDelta, source) {
  437. // Executes on text or formatting changes
  438. if ((source == 'user' || changeMadebyUser==true) && presence!=null) {
  439. var range = editor.getSelection();
  440. presence.sendMessage(presence.getSharedInfo().id, {
  441. user: presence.getUserInfo(),
  442. content: {
  443. action: 'typing',
  444. data: delta,
  445. range: range
  446. }
  447. });
  448. changeMadebyUser=false;
  449. }
  450. });
  451. editor.on('selection-change', function(range, oldRange, source) {
  452. // Executes when user selection changes
  453. if (range) {
  454. if (presence!=null) {
  455. presence.sendMessage(presence.getSharedInfo().id, {
  456. user: presence.getUserInfo(),
  457. content: {
  458. action: 'selection',
  459. range: range
  460. }
  461. });
  462. }
  463. }
  464. });
  465. // Presence Palette
  466. // Link presence palette
  467. var presence = null;
  468. var isHost = false;
  469. var myid;
  470. var nomoreinit = false;
  471. var mycursor;
  472. var palette = new presencepalette.PresencePalette(document.getElementById("network-button"), undefined);
  473. palette.addEventListener('shared', function() {
  474. palette.popDown();
  475. console.log("Want to share");
  476. presence = activity.getPresenceObject(function(error, network) {
  477. if (error) {
  478. console.log("Sharing error");
  479. return;
  480. }
  481. network.createSharedActivity('org.sugarlabs.Write', function(groupId) {
  482. console.log("Activity shared");
  483. isHost = true;
  484. });
  485. network.onDataReceived(onNetworkDataReceived);
  486. network.onSharedActivityUserChanged(onNetworkUserChanged);
  487. });
  488. });
  489. var onNetworkDataReceived = function(msg) {
  490. if (presence.getUserInfo().networkId === msg.user.networkId) {
  491. return;
  492. }
  493. if(msg.content.action=='init' && nomoreinit==false){
  494. editor.updateContents(msg.content.data);
  495. var getallcursors = msg.content.allcursors;
  496. for(var i = 0 ; i < getallcursors.length ; i++){
  497. console.log(getallcursors[i]);
  498. if(getallcursors[i].id!=myid){
  499. cursors.createCursor(getallcursors[i].id, getallcursors[i].name,getallcursors[i].color) ;
  500. cursors.moveCursor(getallcursors[i].id, getallcursors[i].range) ;
  501. }
  502. }
  503. cursors.update();
  504. // Create Fake event to init Cursors
  505. document.getElementById("list-ordered").click();
  506. document.getElementById("list-ordered").click();
  507. nomoreinit=true;
  508. }
  509. if(msg.content.action=='typing'){
  510. editor.updateContents(msg.content.data);
  511. }
  512. if(msg.content.action=='selection'){
  513. setTimeout(function() {cursors.moveCursor(msg.user.networkId,msg.content.range)} , 5);
  514. }
  515. };
  516. var onNetworkUserChanged = function(msg) {
  517. if (isHost) {
  518. var data = editor.getContents();
  519. var range = editor.getSelection();
  520. mycursor.range = range;
  521. var allcursors = cursors.cursors();
  522. presence.sendMessage(presence.getSharedInfo().id, {
  523. user: presence.getUserInfo(),
  524. content: {
  525. action: 'init',
  526. data: data,
  527. allcursors: allcursors
  528. }
  529. });
  530. mycursor.range = null;
  531. }
  532. if(!myid){
  533. myid = msg.user.networkId;
  534. }
  535. // handle user enter/exit Notifications
  536. var userName = msg.user.name.replace('<', '&lt;').replace('>', '&gt;');
  537. var html = "<img style='height:30px;' src='" + generateXOLogoWithColor(msg.user.colorvalue) + "'>";
  538. presence.listSharedActivities(function(activities){
  539. for (var i = 0; i < activities.length; i++) {
  540. if (activities[i].id === presence.getSharedInfo().id) {
  541. getConnectedPeople(activities[i].users);
  542. }
  543. }
  544. });
  545. for (var key in connectedPeople) {
  546. console.log(connectedPeople[key].name,key,connectedPeople[key].networkId);
  547. }
  548. if(msg.move==1){
  549. humane.log(html + webL10n.get("PlayerJoin",{user: userName}));
  550. var c = cursors.createCursor(msg.user.networkId, userName, msg.user.colorvalue.stroke);
  551. if(myid==msg.user.networkId) {mycursor=c;}
  552. }
  553. if (msg.move === -1) {
  554. cursors.removeCursor(msg.user.networkId);
  555. humane.log(html + webL10n.get("PlayerLeave",{user: userName}));
  556. if(msg.user.networkId == connectedPeople[0].networkId){
  557. if(connectedPeople[1].networkId == myid){
  558. document.getElementById(3).style.display = "inline";
  559. document.getElementById(4).style.display = "inline";
  560. isHost=true;
  561. }
  562. }
  563. }
  564. };
  565. var xoLogo = '<?xml version="1.0" ?><!DOCTYPE svg PUBLIC \'-//W3C//DTD SVG 1.1//EN\' \'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\' [<!ENTITY stroke_color "#010101"><!ENTITY fill_color "#FFFFFF">]><svg enable-background="new 0 0 55 55" height="55px" version="1.1" viewBox="0 0 55 55" width="55px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px"><g display="block" id="stock-xo_1_"><path d="M33.233,35.1l10.102,10.1c0.752,0.75,1.217,1.783,1.217,2.932 c0,2.287-1.855,4.143-4.146,4.143c-1.145,0-2.178-0.463-2.932-1.211L27.372,40.961l-10.1,10.1c-0.75,0.75-1.787,1.211-2.934,1.211 c-2.284,0-4.143-1.854-4.143-4.141c0-1.146,0.465-2.184,1.212-2.934l10.104-10.102L11.409,24.995 c-0.747-0.748-1.212-1.785-1.212-2.93c0-2.289,1.854-4.146,4.146-4.146c1.143,0,2.18,0.465,2.93,1.214l10.099,10.102l10.102-10.103 c0.754-0.749,1.787-1.214,2.934-1.214c2.289,0,4.146,1.856,4.146,4.145c0,1.146-0.467,2.18-1.217,2.932L33.233,35.1z" fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5"/><circle cx="27.371" cy="10.849" fill="&fill_color;" r="8.122" stroke="&stroke_color;" stroke-width="3.5"/></g></svg>';
  566. function generateXOLogoWithColor(color) {
  567. var coloredLogo = xoLogo;
  568. coloredLogo = coloredLogo.replace("#010101", color.stroke)
  569. coloredLogo = coloredLogo.replace("#FFFFFF", color.fill)
  570. return "data:image/svg+xml;base64," + btoa(coloredLogo);
  571. }
  572. var connectedPeople = {};
  573. // Maintain a list of connected users
  574. function displayConnectedPeople(){
  575. var presenceUsersDiv = document.getElementById("presence-users");
  576. var html = "<hr><ul style='list-style: none; padding:0;'>";
  577. for (var key in connectedPeople) {
  578. html += "<li><img style='height:30px;' src='" + generateXOLogoWithColor(connectedPeople[key].colorvalue) + "'>" + connectedPeople[key].name + "</li>"
  579. }
  580. html += "</ul>"
  581. presenceUsersDiv.innerHTML = html
  582. }
  583. function getConnectedPeople(users){
  584. var presenceUsersDiv = document.getElementById("presence-users");
  585. if (!users || !presenceUsersDiv) {
  586. return;
  587. }
  588. connectedPeople = {};
  589. presence.listSharedActivityUsers(presence.getSharedInfo().id , function(usersConnected){
  590. connectedPeople = {};
  591. for (var i = 0; i < usersConnected.length; i++) {
  592. var userConnected = usersConnected[i];
  593. connectedPeople[i] = userConnected;
  594. }
  595. displayConnectedPeople();
  596. });
  597. }
  598. });
  599. });