Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] IE11 - callback createTreeWalker doesnt accept acceptNode #15157

Merged
merged 8 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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