ui.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. var
  2. /**
  3. * Minimum time between 2 notifications (ms)
  4. * @const
  5. * @type {number}
  6. **/
  7. NOTIFICATION_COOLDOWN = 30 * 1000 //30 sec
  8. /**
  9. * Maximum time the notification will stay visible (ms)
  10. * @const
  11. * @type {number}
  12. **/
  13. ,NOTIFICATION_DELAY = 5 * 1000 // 5 sec
  14. ,MSG_GROUPS = []
  15. /** @type {number} */
  16. ,lastNotificationSpawn = 0
  17. ;
  18. function onContextUpdated() {
  19. var chanListFram = document.createDocumentFragment()
  20. ,sortedChans = Object.keys(SLACK.context.channels || {})
  21. ,starred = []
  22. ,channels = []
  23. ,privs = []
  24. ,priv = [];
  25. sortedChans.sort(function(a, b) {
  26. if (a[0] !== b[0]) {
  27. return a[0] - b[0];
  28. }
  29. return SLACK.context.channels[a].name.localeCompare(SLACK.context.channels[b].name);
  30. });
  31. sortedChans.forEach(function(chanId) {
  32. var chan = SLACK.context.channels[chanId];
  33. if (!chan.archived && chan.isMember !== false) {
  34. if (chan instanceof PrivateMessageRoom) {
  35. if (!chan.user.deleted) {
  36. var chanListItem = createImsListItem(chan);
  37. if (chanListItem) {
  38. if (chan.starred)
  39. starred.push(chanListItem);
  40. else
  41. priv.push(chanListItem);
  42. }
  43. }
  44. } else {
  45. var chanListItem = createChanListItem(chan);
  46. if (chanListItem) {
  47. if (chan.starred)
  48. starred.push(chanListItem);
  49. else if (chan.isPrivate)
  50. privs.push(chanListItem);
  51. else
  52. channels.push(chanListItem);
  53. }
  54. }
  55. }
  56. });
  57. if (starred.length)
  58. chanListFram.appendChild(createChanListHeader(locale.starred));
  59. starred.forEach(function(dom) {
  60. chanListFram.appendChild(dom);
  61. });
  62. if (channels.length)
  63. chanListFram.appendChild(createChanListHeader(locale.channels));
  64. channels.forEach(function(dom) {
  65. chanListFram.appendChild(dom);
  66. });
  67. privs.forEach(function(dom) {
  68. chanListFram.appendChild(dom);
  69. });
  70. if (priv.length)
  71. chanListFram.appendChild(createChanListHeader(locale.privateMessageRoom));
  72. priv.forEach(function(dom) {
  73. chanListFram.appendChild(dom);
  74. });
  75. document.getElementById(R.id.chanList).textContent = "";
  76. document.getElementById(R.id.chanList).appendChild(chanListFram);
  77. setRoomFromHashBang();
  78. updateTitle();
  79. createContextBackground(function(imgData) {
  80. document.getElementById(R.id.context).style.backgroundImage = 'url(' +imgData +')';
  81. });
  82. }
  83. function onTypingUpdated() {
  84. var typing = SLACK.context.typing;
  85. for (var chanId in SLACK.context.self.channels) {
  86. if (!SLACK.context.self.channels[chanId].archived) {
  87. var dom = document.getElementById("room_" +chanId);
  88. if (typing[chanId])
  89. dom.classList.add(R.klass.chatList.typing);
  90. else
  91. dom.classList.remove(R.klass.chatList.typing);
  92. }
  93. }
  94. for (var userId in SLACK.context.users) {
  95. var ims = SLACK.context.users[userId].privateRoom;
  96. if (ims && !ims.archived) {
  97. var dom = document.getElementById("room_" +ims.id);
  98. if (dom) {
  99. if (typing[ims.id])
  100. dom.classList.add(R.klass.chatList.typing);
  101. else
  102. dom.classList.remove(R.klass.chatList.typing);
  103. }
  104. }
  105. }
  106. updateTypingChat();
  107. }
  108. function updateTypingChat() {
  109. var typing = SLACK.context.typing;
  110. document.getElementById(R.id.typing).textContent = "";
  111. if (SELECTED_ROOM && typing[SELECTED_ROOM.id]) {
  112. var areTyping = document.createDocumentFragment()
  113. ,isOutOfSync = false;
  114. for (var i in typing[SELECTED_ROOM.id]) {
  115. var member = SLACK.context.users[i];
  116. if (member)
  117. areTyping.appendChild(makeUserIsTypingDom(member));
  118. else
  119. isOutOfSync = true;
  120. }
  121. if (isOutOfSync)
  122. outOfSync();
  123. document.getElementById(R.id.typing).appendChild(areTyping);
  124. }
  125. }
  126. function onNetworkStateUpdated(isNetworkWorking) {
  127. isNetworkWorking ? document.body.classList.remove(R.klass.noNetwork) : document.body.classList.add(R.klass.noNetwork);
  128. updateTitle();
  129. }
  130. function onRoomSelected() {
  131. var name = SELECTED_ROOM.name || (SELECTED_ROOM.user ? SELECTED_ROOM.user.name : undefined);
  132. if (!name) {
  133. /** @type {Array.<string>} */
  134. var members = [];
  135. SELECTED_ROOM.users.forEach(function(i) {
  136. members.push(i.name);
  137. });
  138. name = members.join(", ");
  139. }
  140. var roomLi = document.getElementById("room_" +SELECTED_ROOM.id);
  141. document.getElementById(R.id.currentRoom.title).textContent = name;
  142. onRoomUpdated();
  143. focusInput();
  144. document.getElementById(R.id.message.file.formContainer).classList.add(R.klass.hidden);
  145. markRoomAsRead(SELECTED_ROOM);
  146. if (REPLYING_TO) {
  147. REPLYING_TO = null;
  148. onReplyingToUpdated();
  149. }
  150. if (EDITING) {
  151. EDITING = null;
  152. onReplyingToUpdated();
  153. }
  154. updateTypingChat();
  155. }
  156. function onReplyingToUpdated() {
  157. if (REPLYING_TO) {
  158. document.body.classList.add(R.klass.replyingTo);
  159. var domParent = document.getElementById(R.id.message.replyTo)
  160. ,closeLink = document.createElement("a");
  161. closeLink.addEventListener("click", function() {
  162. REPLYING_TO = null;
  163. onReplyingToUpdated();
  164. });
  165. closeLink.className = R.klass.msg.replyTo.close;
  166. closeLink.textContent = 'x';
  167. domParent.textContent = "";
  168. domParent.appendChild(closeLink);
  169. domParent.appendChild(REPLYING_TO.duplicateDom());
  170. focusInput();
  171. } else {
  172. document.body.classList.remove(R.klass.replyingTo);
  173. document.getElementById(R.id.message.replyTo).textContent = "";
  174. focusInput();
  175. }
  176. }
  177. function onEditingUpdated() {
  178. if (EDITING) {
  179. document.body.classList.add(R.klass.replyingTo);
  180. var domParent = document.getElementById(R.id.message.replyTo)
  181. ,closeLink = document.createElement("a");
  182. closeLink.addEventListener("click", function() {
  183. EDITING = null;
  184. onEditingUpdated();
  185. });
  186. closeLink.className = R.klass.msg.replyTo.close;
  187. closeLink.textContent = 'x';
  188. domParent.textContent = "";
  189. domParent.appendChild(closeLink);
  190. domParent.appendChild(EDITING.duplicateDom());
  191. document.getElementById(R.id.message.input).value = EDITING.text;
  192. focusInput();
  193. } else {
  194. document.body.classList.remove(R.klass.replyingTo);
  195. document.getElementById(R.id.message.replyTo).textContent = "";
  196. focusInput();
  197. }
  198. }
  199. /**
  200. * @param {string} chanId
  201. * @param {string} msgId
  202. * @param {string} reaction
  203. **/
  204. window['toggleReaction'] = function(chanId, msgId, reaction) {
  205. var hist = SLACK.history[chanId];
  206. if (!hist)
  207. return;
  208. var msg = hist.getMessageById(msgId);
  209. if (msg) {
  210. if (msg.hasReactionForUser(reaction, SLACK.context.self.id)) {
  211. removeReaction(chanId, msgId, reaction);
  212. } else {
  213. addReaction(chanId, msgId, reaction);
  214. }
  215. }
  216. };
  217. /**
  218. * Try to resolve emoji from customized context
  219. * @param {string} emoji
  220. * @return {Element|string}
  221. **/
  222. function tryGetCustomEmoji(emoji) {
  223. var loop = {};
  224. while (!loop[emoji]) {
  225. var emojisrc= SLACK.context.emojis.data[emoji];
  226. if (emojisrc) {
  227. if (emojisrc.substr(0, 6) == "alias:") {
  228. loop[emoji] = true;
  229. emoji = emojisrc.substr(6);
  230. } else {
  231. var dom = document.createElement("span");
  232. dom.className = R.klass.emoji.custom +' ' +R.klass.emoji.emoji;
  233. dom.style.backgroundImage = "url('" +emojisrc +"')";
  234. return dom;
  235. }
  236. }
  237. return emoji; // Emoji not found, fallback to std emoji
  238. }
  239. return emoji; //loop detected, return first emoji
  240. }
  241. function makeEmojiDom(emojiCode) {
  242. var emoji = tryGetCustomEmoji(emojiCode);
  243. if (typeof emoji === "string" && "makeEmoji" in window)
  244. emoji = window['makeEmoji'](emoji);
  245. return typeof emoji === "string" ? null : emoji;
  246. }
  247. /**
  248. * @param {number} unreadhi
  249. * @param {number} unread
  250. **/
  251. function setFavicon(unreadhi, unread) {
  252. if (!unreadhi && !unread)
  253. document.getElementById(R.id.favicon).href = "favicon_ok.png";
  254. else
  255. document.getElementById(R.id.favicon).href = "favicon.png?h="+unreadhi+"&m="+unread;
  256. }
  257. function setNetErrorFavicon() {
  258. document.getElementById(R.id.favicon).href = "favicon_err.png";
  259. }
  260. function updateTitle() {
  261. var hasHl = HIGHLIGHTED_CHANS.length
  262. ,title = "";
  263. if (NEXT_RETRY) {
  264. title = '!' +locale.netErrorShort +' - ';
  265. setNetErrorFavicon();
  266. } else if (hasHl) {
  267. title = "(!" +hasHl +") - ";
  268. setFavicon(hasHl, hasHl);
  269. } else {
  270. var hasUnread = 0;
  271. for (var chanId in SLACK.context.channels) {
  272. var i = SLACK.context.channels[chanId];
  273. if (i.lastMsg > i.lastRead)
  274. hasUnread++;
  275. }
  276. if (hasUnread)
  277. title = "(" +hasUnread +") - ";
  278. setFavicon(0, hasUnread);
  279. }
  280. if (SLACK.context.team)
  281. title += SLACK.context.team.name;
  282. document.title = title;
  283. }
  284. function spawnNotification() {
  285. if (!("Notification" in window))
  286. {}
  287. else if (Notification.permission === "granted") {
  288. var now = Date.now();
  289. if (lastNotificationSpawn + NOTIFICATION_COOLDOWN < now) {
  290. var n = new Notification(locale.newMessage);
  291. lastNotificationSpawn = now;
  292. setTimeout(function() {
  293. n.close();
  294. }, NOTIFICATION_DELAY);
  295. }
  296. }
  297. else if (Notification.permission !== "denied")
  298. Notification.requestPermission();
  299. }
  300. function onRoomUpdated() {
  301. var chatFrag = document.createDocumentFragment()
  302. ,currentRoomId = SELECTED_ROOM.id
  303. ,prevMsg = null
  304. ,firstTsCombo = 0
  305. ,prevMsgDom = null
  306. ,currentMsgGroupDom;
  307. MSG_GROUPS = [];
  308. if (SLACK.history[currentRoomId])
  309. SLACK.history[currentRoomId].messages.forEach(function(msg) {
  310. if (!msg.removed) {
  311. var dom = msg.getDom()
  312. ,newGroupDom = false;
  313. if (prevMsg && prevMsg.userId === msg.userId && msg.userId) {
  314. if (Math.abs(firstTsCombo -msg.ts) < 30 && !(msg instanceof MeMessage))
  315. prevMsgDom.classList.add(R.klass.msg.sameTs);
  316. else
  317. firstTsCombo = msg.ts;
  318. } else {
  319. firstTsCombo = msg.ts;
  320. newGroupDom = true;
  321. }
  322. if ((!prevMsg || prevMsg.ts <= SELECTED_ROOM.lastRead) && msg.ts > SELECTED_ROOM.lastRead)
  323. dom.classList.add(R.klass.msg.firstUnread);
  324. else
  325. dom.classList.remove(R.klass.msg.firstUnread);
  326. if (msg instanceof MeMessage) {
  327. prevMsg = null;
  328. prevMsgDom = null;
  329. firstTsCombo = 0;
  330. newGroupDom = true;
  331. chatFrag.appendChild(dom);
  332. currentMsgGroupDom = null;
  333. } else {
  334. if (newGroupDom || !currentMsgGroupDom) {
  335. currentMsgGroupDom = createMessageGroupDom(SLACK.context.users[msg.userId], msg.username);
  336. MSG_GROUPS.push(currentMsgGroupDom);
  337. chatFrag.appendChild(currentMsgGroupDom);
  338. }
  339. prevMsg = msg;
  340. prevMsgDom = dom;
  341. currentMsgGroupDom.content.appendChild(dom);
  342. }
  343. } else {
  344. msg.removeDom();
  345. }
  346. });
  347. var content = document.getElementById(R.id.currentRoom.content);
  348. //TODO lazy add dom if needed
  349. content.textContent = "";
  350. content.appendChild(chatFrag);
  351. //TODO scroll lock
  352. content.scrollTop = content.scrollHeight -content.clientHeight;
  353. if (window.hasFocus)
  354. markRoomAsRead(SELECTED_ROOM);
  355. }
  356. function chatClickDelegate(e) {
  357. var target = e.target
  358. ,getMessageId = function(e, target) {
  359. target = target || e.target;
  360. while (target !== e.currentTarget && target) {
  361. if (target.classList.contains(R.klass.msg.item)) {
  362. return target.id;
  363. }
  364. target = target.parentElement;
  365. }
  366. };
  367. while (target !== e.currentTarget && target) {
  368. if (target.classList.contains(R.klass.msg.hover.container)) {
  369. return;
  370. } else if (target.parentElement && target.classList.contains(R.klass.msg.attachment.actionItem)) {
  371. var messageId = getMessageId(e, target)
  372. ,attachmentIndex = target.dataset.attachmentIndex
  373. ,actionIndex = target.dataset.actionIndex;
  374. if (messageId && attachmentIndex !== undefined && actionIndex !== undefined) {
  375. messageId = parseFloat(messageId.split("_")[1]);
  376. var msg = SLACK.history[SELECTED_ROOM.id].getMessage(messageId);
  377. if (msg && msg.attachments[attachmentIndex] && msg.attachments[attachmentIndex].actions && msg.attachments[attachmentIndex].actions[actionIndex]) {
  378. confirmAction(SELECTED_ROOM.id, msg, msg.attachments[attachmentIndex], msg.attachments[attachmentIndex].actions[actionIndex]);
  379. }
  380. }
  381. } else if (target.parentElement && target.parentElement.classList.contains(R.klass.msg.hover.container)) {
  382. var messageId = getMessageId(e, target);
  383. if (messageId) {
  384. messageId = parseFloat(messageId.split("_")[1]);
  385. var msg = SLACK.history[SELECTED_ROOM.id].getMessage(messageId);
  386. if (msg && target.classList.contains(R.klass.msg.hover.reply)) {
  387. if (EDITING) {
  388. EDITING = null;
  389. onEditingUpdated();
  390. }
  391. if (REPLYING_TO !== msg) {
  392. REPLYING_TO = msg;
  393. onReplyingToUpdated();
  394. }
  395. } else if (msg && target.classList.contains(R.klass.msg.hover.reaction)) {
  396. EMOJI_BAR.spawn(document.body, function(emoji) {
  397. if (emoji)
  398. addReaction(SELECTED_ROOM.id, msg.id, emoji);
  399. });
  400. } else if (msg && target.classList.contains(R.klass.msg.hover.edit)) {
  401. if (REPLYING_TO) {
  402. REPLYING_TO = null;
  403. onReplyingToUpdated();
  404. }
  405. if (EDITING !== msg) {
  406. EDITING = msg;
  407. onEditingUpdated();
  408. }
  409. } else if (msg && target.classList.contains(R.klass.msg.hover.remove)) {
  410. //TODO promt confirm
  411. if (REPLYING_TO) {
  412. REPLYING_TO = null;
  413. onReplyingToUpdated();
  414. }
  415. if (EDITING) {
  416. EDITING = null;
  417. onEditingUpdated();
  418. }
  419. removeMsg(SELECTED_ROOM, msg);
  420. }
  421. }
  422. return;
  423. }
  424. target = target.parentElement;
  425. }
  426. }
  427. function confirmAction(roomId, msg, attachmentObject, actionObject) {
  428. var confirmed = function() {
  429. var payload = getActionPayload(roomId, msg, attachmentObject, actionObject);
  430. sendCommand(payload, msg.userId);
  431. };
  432. if (actionObject["confirm"]) {
  433. (new ConfirmDialog(actionObject["confirm"]["title"], actionObject["confirm"]["text"]))
  434. .setButtonText(actionObject["confirm"]["ok_text"], actionObject["confirm"]["dismiss_text"])
  435. .onConfirm(confirmed)
  436. .spawn();
  437. } else {
  438. confirmed();
  439. }
  440. }
  441. function focusInput() {
  442. document.getElementById(R.id.message.input).focus();
  443. }
  444. function setRoomFromHashBang() {
  445. var hashId = document.location.hash.substr(1)
  446. ,room = SLACK.context.channels[hashId];
  447. if (room && room !== SELECTED_ROOM)
  448. selectRoom(room);
  449. else {
  450. var user = SLACK.context.users[hashId];
  451. if (user && user.ims)
  452. selectRoom(user.ims);
  453. }
  454. }
  455. function updateAuthorAvatarImsOffset() {
  456. var chatDom = document.getElementById(R.id.currentRoom.content)
  457. ,chatTop = chatDom.getBoundingClientRect().top;
  458. MSG_GROUPS.forEach(function(group) {
  459. var imgDom = group.authorImg
  460. ,imgSize = imgDom.clientHeight
  461. ,domRect = group.getBoundingClientRect()
  462. ,_top = 0;
  463. imgDom.style.top = Math.max(0, Math.min(chatTop -domRect.top, domRect.height -imgSize -(imgSize /2))) +"px";
  464. });
  465. }
  466. document.addEventListener('DOMContentLoaded', function() {
  467. initLang();
  468. document.getElementById(R.id.currentRoom.content).addEventListener("click", chatClickDelegate);
  469. window.addEventListener("hashchange", function(e) {
  470. if (document.location.hash && document.location.hash[0] === '#') {
  471. setRoomFromHashBang();
  472. }
  473. });
  474. document.getElementById(R.id.message.file.cancel).addEventListener("click", function(e) {
  475. e.preventDefault();
  476. document.getElementById(R.id.message.file.error).classList.add(R.klass.hidden);
  477. document.getElementById(R.id.message.file.formContainer).classList.add(R.klass.hidden);
  478. document.getElementById(R.id.message.file.fileInput).value = "";
  479. return false;
  480. });
  481. document.getElementById(R.id.message.file.form).addEventListener("submit", function(e) {
  482. e.preventDefault();
  483. var fileInput = document.getElementById(R.id.message.file.fileInput)
  484. ,filename = fileInput.value;
  485. if (filename) {
  486. filename = filename.substr(filename.lastIndexOf('\\') +1);
  487. uploadFile(SELECTED_ROOM, filename, fileInput.files[0], function(errorMsg) {
  488. var error = document.getElementById(R.id.message.file.error);
  489. if (errorMsg) {
  490. error.textContent = errorMsg;
  491. error.classList.remove(R.klass.hidden);
  492. } else {
  493. error.classList.add(R.klass.hidden);
  494. document.getElementById(R.id.message.file.fileInput).value = "";
  495. document.getElementById(R.id.message.file.formContainer).classList.add(R.klass.hidden);
  496. }
  497. });
  498. }
  499. return false;
  500. });
  501. document.getElementById(R.id.message.file.bt).addEventListener("click", function(e) {
  502. e.preventDefault();
  503. if (SELECTED_ROOM) {
  504. document.getElementById(R.id.message.file.formContainer).classList.remove(R.klass.hidden);
  505. }
  506. return false;
  507. });
  508. document.getElementById(R.id.message.form).addEventListener("submit", function(e) {
  509. e.preventDefault();
  510. var input =document.getElementById(R.id.message.input);
  511. if (SELECTED_ROOM && input.value) {
  512. if (onTextEntered(input.value)) {
  513. input.value = "";
  514. if (REPLYING_TO) {
  515. REPLYING_TO = null;
  516. onReplyingToUpdated();
  517. }
  518. if (EDITING) {
  519. EDITING = null;
  520. onReplyingToUpdated();
  521. }
  522. document.getElementById(R.id.message.slashComplete).textContent = '';
  523. }
  524. }
  525. focusInput();
  526. return false;
  527. });
  528. window.addEventListener('blur', function() {
  529. window.hasFocus = false;
  530. });
  531. window.addEventListener('focus', function() {
  532. window.hasFocus = true;
  533. lastNotificationSpawn = 0;
  534. if (SELECTED_ROOM)
  535. markRoomAsRead(SELECTED_ROOM);
  536. focusInput();
  537. });
  538. document.getElementById(R.id.currentRoom.content).addEventListener('scroll', updateAuthorAvatarImsOffset);
  539. var lastKeyDown = 0;
  540. document.getElementById(R.id.message.input).addEventListener('input', function() {
  541. if (SELECTED_ROOM) {
  542. var now = Date.now();
  543. if (lastKeyDown + 3000 < now && (SLACK.context.self.presence || (SELECTED_ROOM instanceof PrivateMessageRoom))) {
  544. sendTyping(SELECTED_ROOM);
  545. lastKeyDown = now;
  546. }
  547. var commands = []
  548. ,input = this.value;
  549. if (this.value[0] === '/') {
  550. var endCmd = input.indexOf(' ')
  551. ,inputFinished = endCmd !== -1;
  552. endCmd = endCmd === -1 ? input.length : endCmd;
  553. var inputCmd = input.substr(0, endCmd);
  554. for (var i in SLACK.context.commands.data) {
  555. var currentCmd = SLACK.context.commands.data[i]
  556. if ((!inputFinished && currentCmd.name.substr(0, endCmd) === inputCmd) ||
  557. (inputFinished && currentCmd.name === inputCmd))
  558. commands.push(currentCmd);
  559. }
  560. }
  561. commands.sort(function(a, b) {
  562. return a.category.localeCompare(b.category) || a.name.localeCompare(b.name);
  563. });
  564. var slashDom = document.getElementById(R.id.message.slashComplete)
  565. ,slashFrag = document.createDocumentFragment()
  566. ,prevService;
  567. slashDom.textContent = '';
  568. for (var i =0, nbCmd = commands.length; i < nbCmd; i++) {
  569. var command = commands[i];
  570. if (prevService !== command.category) {
  571. prevService = command.category;
  572. slashFrag.appendChild(createSlashAutocompleteHeader(command.category));
  573. }
  574. slashFrag.appendChild(createSlashAutocompleteDom(command));
  575. }
  576. slashDom.appendChild(slashFrag);
  577. }
  578. });
  579. window.hasFocus = true;
  580. //Emoji closure
  581. (function() {
  582. var emojiButton = document.getElementById(R.id.message.emoji);
  583. if ('makeEmoji' in window) {
  584. var emojiDom = window['makeEmoji']('smile');
  585. if (emojiDom) {
  586. emojiButton.innerHTML = "<span class='" +R.klass.emoji.small +"'>" +emojiDom.outerHTML +"</span>";
  587. } else {
  588. emojiButton.style.backgroundImage = 'url("smile.svg")';
  589. }
  590. emojiDom = window['makeEmoji']('paperclip');
  591. if (emojiDom) {
  592. document.getElementById(R.id.message.file.bt).innerHTML = "<span class='" +R.klass.emoji.small +"'>" +emojiDom.outerHTML +"</span>";
  593. } else {
  594. document.getElementById(R.id.message.file.bt).style.backgroundImage = 'url("public/paperclip.svg")';
  595. }
  596. emojiButton.addEventListener("click", function() {
  597. EMOJI_BAR.spawn(document.body, function(e) {
  598. if (e) document.getElementById(R.id.message.input).value += ":"+e+":";
  599. focusInput();
  600. });
  601. });
  602. } else {
  603. emojiButton.classList.add(R.klass.hidden);
  604. }
  605. })();
  606. startPolling();
  607. });