From 3be728bcd9eb0d970f3969fbe6bdb03f764fda1f Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Tue, 13 Aug 2019 18:25:41 -0300 Subject: [PATCH] =?UTF-8?q?[FIX]=20IE11=20-=20callback=20createTreeWalker?= =?UTF-8?q?=20doesnt=20accept=20acceptNo=E2=80=A6=20(#15157)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/emoji/client/emojiParser.js | 62 +++++++++++--------- app/markdown/lib/parser/original/markdown.js | 2 +- app/ui-utils/client/lib/isIE11.js | 15 +++++ imports/client/@rocket.chat/apps-engine | 1 + 4 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 app/ui-utils/client/lib/isIE11.js create mode 120000 imports/client/@rocket.chat/apps-engine diff --git a/app/emoji/client/emojiParser.js b/app/emoji/client/emojiParser.js index 00ef84402bee..d7f7980df11a 100644 --- a/app/emoji/client/emojiParser.js +++ b/app/emoji/client/emojiParser.js @@ -3,6 +3,7 @@ import { Meteor } from 'meteor/meteor'; import { Tracker } from 'meteor/tracker'; import { getUserPreference } from '../../utils'; +import { isIE11 } from '../../ui-utils/client/lib/isIE11'; import { callbacks } from '../../callbacks'; import { emoji } from '../lib/rocketchat'; @@ -32,41 +33,44 @@ Tracker.autorun(() => { const emojis = Array.from(checkEmojiOnly.querySelectorAll('.emoji:not(:empty), .emojione:not(:empty)')); - const walker = document.createTreeWalker( - checkEmojiOnly, - NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, - { - acceptNode: (node) => { - if (node.nodeType === Node.ELEMENT_NODE && ( - node.classList.contains('emojione') - || node.classList.contains('emoji') - )) { - return NodeFilter.FILTER_REJECT; - } - return NodeFilter.FILTER_ACCEPT; - }, - }, - ); - let hasText = false; - while (walker.nextNode()) { - if (walker.currentNode.nodeType === Node.TEXT_NODE && walker.currentNode.nodeValue.trim() !== '') { - hasText = true; - break; + if (!isIE11()) { + const filter = (node) => { + if (node.nodeType === Node.ELEMENT_NODE && ( + node.classList.contains('emojione') + || node.classList.contains('emoji') + )) { + return NodeFilter.FILTER_REJECT; + } + return NodeFilter.FILTER_ACCEPT; + }; + + const walker = document.createTreeWalker( + checkEmojiOnly, + NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, + filter + ); + + + while (walker.nextNode()) { + if (walker.currentNode.nodeType === Node.TEXT_NODE && walker.currentNode.nodeValue.trim() !== '') { + hasText = true; + break; + } } - } - - const emojiOnly = emojis.length && !hasText; - - if (emojiOnly) { - for (let i = 0, len = emojis.length; i < len; i++) { - const { classList } = emojis[i]; - classList.add('big'); + const emojiOnly = emojis.length && !hasText; + + if (emojiOnly) { + for (let i = 0, len = emojis.length; i < len; i++) { + const { classList } = emojis[i]; + classList.add('big'); + } + html = checkEmojiOnly.innerHTML; } - html = checkEmojiOnly.innerHTML; } + // apostrophe (') back to ' html = html.replace(/\'/g, '''); diff --git a/app/markdown/lib/parser/original/markdown.js b/app/markdown/lib/parser/original/markdown.js index 09517cd6fd4e..e0817c542f38 100644 --- a/app/markdown/lib/parser/original/markdown.js +++ b/app/markdown/lib/parser/original/markdown.js @@ -23,7 +23,7 @@ const parseNotEscaped = function(msg, message) { return token; }; - const schemes = settings.get('Markdown_SupportSchemesForLink').split(',').join('|'); + const schemes = (settings.get('Markdown_SupportSchemesForLink') || '').split(',').join('|'); if (settings.get('Markdown_Headers')) { // Support # Text for h1 diff --git a/app/ui-utils/client/lib/isIE11.js b/app/ui-utils/client/lib/isIE11.js new file mode 100644 index 000000000000..c494c5c63202 --- /dev/null +++ b/app/ui-utils/client/lib/isIE11.js @@ -0,0 +1,15 @@ +export const isIE11 = () => { + const { userAgent } = window.navigator; + const msieIdx = userAgent.indexOf('MSIE'); + + if (msieIdx > 0) { + return parseInt(userAgent.substring(msieIdx + 5, userAgent.indexOf('.', msieIdx))) === 11; + } + + // If MSIE detection fails, check the Trident engine version + if (navigator.userAgent.match(/Trident\/7\./)) { + return true; + } + + return false; +}; diff --git a/imports/client/@rocket.chat/apps-engine b/imports/client/@rocket.chat/apps-engine new file mode 120000 index 000000000000..9a368c3d1407 --- /dev/null +++ b/imports/client/@rocket.chat/apps-engine @@ -0,0 +1 @@ +../../../node_modules/@rocket.chat/apps-engine \ No newline at end of file