Skip to content

Commit

Permalink
[FIX] IE11 - callback createTreeWalker doesnt accept acceptNo… (#15157)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored and sampaiodiego committed Aug 13, 2019
1 parent af0bcc8 commit 3be728b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 30 deletions.
62 changes: 33 additions & 29 deletions app/emoji/client/emojiParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 &#39;
html = html.replace(/\'/g, '&#39;');

Expand Down
2 changes: 1 addition & 1 deletion app/markdown/lib/parser/original/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions app/ui-utils/client/lib/isIE11.js
Original file line number Diff line number Diff line change
@@ -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;
};
1 change: 1 addition & 0 deletions imports/client/@rocket.chat/apps-engine

0 comments on commit 3be728b

Please sign in to comment.