Skip to content

Commit

Permalink
Drop IE and legacy Edge support (#800)
Browse files Browse the repository at this point in the history
Drop IE and legacy Edge support
  • Loading branch information
samclarke authored Feb 24, 2021
1 parent f3dc442 commit 29e74ea
Show file tree
Hide file tree
Showing 19 changed files with 146 additions and 421 deletions.
4 changes: 1 addition & 3 deletions example/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@

[ul][li]A simple list[/li][li]list item 2[/li][/ul]

If you are using IE9+ or any non-IE browser just type [b]:[/b]) and it should be converted into :) as you type.</textarea>
Just type [b]:[/b]) and it should be converted into :) as you type.</textarea>

<p>If you are using IE9+ or any other browser then it should automatically replace
:) and other emoticon codes with theit emoticon images.</p>
</div>

<div>
Expand Down
98 changes: 37 additions & 61 deletions src/formats/bbcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
var extend = utils.extend;
var each = utils.each;

var IE_VER = sceditor.ie;

// In IE < 11 a BR at the end of a block level element
// causes a double line break.
var IE_BR_FIX = IE_VER && IE_VER < 11;

var EMOTICON_DATA_ATTR = 'data-sceditor-emoticon';

var getEditorCommand = sceditor.command.get;
Expand Down Expand Up @@ -878,7 +872,7 @@
return;
}

if (IE_BR_FIX || (node.childNodes.length !== 1 ||
if ((node.childNodes.length !== 1 ||
!is(node.firstChild, 'br'))) {
while ((next = node.firstChild)) {
output.insertBefore(next, node);
Expand Down Expand Up @@ -1806,7 +1800,7 @@
function convertToHTML(tokens, isRoot) {
var undef, token, bbcode, content, html, needsBlockWrap,
blockWrapOpen, isInline, lastChild,
ret = [];
ret = '';

isInline = function (bbcode) {
return (!bbcode || (bbcode.isHtmlInline !== undef ?
Expand All @@ -1831,12 +1825,9 @@
isInline(bbcodeHandlers[lastChild.name]) &&
!bbcode.isPreFormatted &&
!bbcode.skipLastLineBreak) {
// Add placeholder br to end of block level elements
// in all browsers apart from IE < 9 which handle
// new lines differently and doesn't need one.
if (!IE_BR_FIX) {
content += '<br />';
}
// Add placeholder br to end of block level
// elements
content += '<br />';
}

if (!isFunction(bbcode.html)) {
Expand All @@ -1859,30 +1850,26 @@
}
} else if (token.type === TOKEN_NEWLINE) {
if (!isRoot) {
ret.push('<br />');
ret += '<br />';
continue;
}

// If not already in a block wrap then start a new block
if (!blockWrapOpen) {
ret.push('<div>');
ret += '<div>';
}

// Putting BR in a div in IE causes it
// to do a double line break.
if (!IE_BR_FIX) {
ret.push('<br />');
}
ret += '<br />';

// Normally the div acts as a line-break with by moving
// whatever comes after onto a new line.
// If this is the last token, add an extra line-break so it
// shows as there will be nothing after it.
if (!tokens.length) {
ret.push('<br />');
ret += '<br />';
}

ret.push('</div>\n');
ret += '</div>\n';
blockWrapOpen = false;
continue;
// content
Expand All @@ -1892,21 +1879,21 @@
}

if (needsBlockWrap && !blockWrapOpen) {
ret.push('<div>');
ret += '<div>';
blockWrapOpen = true;
} else if (!needsBlockWrap && blockWrapOpen) {
ret.push('</div>\n');
ret += '</div>\n';
blockWrapOpen = false;
}

ret.push(html);
ret += html;
}

if (blockWrapOpen) {
ret.push('</div>\n');
ret += '</div>\n';
}

return ret.join('');
return ret;
}

/**
Expand Down Expand Up @@ -1938,10 +1925,7 @@
function convertToBBCode(toks) {
var token, attr, bbcode, isBlock, isSelfClosing, quoteType,
breakBefore, breakStart, breakEnd, breakAfter,
// Create an array of strings which are joined together
// before being returned as this is faster in slow browsers.
// (Old versions of IE).
ret = [];
ret = '';

while (toks.length > 0) {
if (!(token = toks.shift())) {
Expand Down Expand Up @@ -1973,75 +1957,75 @@
base.opts.quoteType || QuoteType.auto;

if (!bbcode && token.type === TOKEN_OPEN) {
ret.push(token.val);
ret += token.val;

if (token.children) {
ret.push(convertToBBCode(token.children));
ret += convertToBBCode(token.children);
}

if (token.closing) {
ret.push(token.closing.val);
ret += token.closing.val;
}
} else if (token.type === TOKEN_OPEN) {
if (breakBefore) {
ret.push('\n');
ret += '\n';
}

// Convert the tag and it's attributes to BBCode
ret.push('[' + token.name);
ret += '[' + token.name;
if (token.attrs) {
if (token.attrs.defaultattr) {
ret.push('=', quote(
ret += '=' + quote(
token.attrs.defaultattr,
quoteType,
'defaultattr'
));
);

delete token.attrs.defaultattr;
}

for (attr in token.attrs) {
if (token.attrs.hasOwnProperty(attr)) {
ret.push(' ', attr, '=',
quote(token.attrs[attr], quoteType, attr));
ret += ' ' + attr + '=' +
quote(token.attrs[attr], quoteType, attr);
}
}
}
ret.push(']');
ret += ']';

if (breakStart) {
ret.push('\n');
ret += '\n';
}

// Convert the tags children to BBCode
if (token.children) {
ret.push(convertToBBCode(token.children));
ret += convertToBBCode(token.children);
}

// add closing tag if not self closing
if (!isSelfClosing && !bbcode.excludeClosing) {
if (breakEnd) {
ret.push('\n');
ret += '\n';
}

ret.push('[/' + token.name + ']');
ret += '[/' + token.name + ']';
}

if (breakAfter) {
ret.push('\n');
ret += '\n';
}

// preserve whatever was recognized as the
// closing tag if it is a self closing tag
if (token.closing && isSelfClosing) {
ret.push(token.closing.val);
ret += token.closing.val;
}
} else {
ret.push(token.val);
ret += token.val;
}
}

return ret.join('');
return ret;
}

/**
Expand Down Expand Up @@ -2371,7 +2355,6 @@

// If it's the last block of an inline that is the last
// child of a block then it shouldn't cause a line break
// except in IE < 11
// <block><inline><br></inline></block>
do {
parent = element.parentNode;
Expand All @@ -2384,10 +2367,7 @@
// If this block is:
// * Not the last child of a block level element
// * Is a <li> tag (lists are blocks)
// * Is IE < 11 and the tag is BR. IE < 11 never collapses BR
// tags.
if (!isLastBlockChild || tag === 'li' ||
(tag === 'br' && IE_BR_FIX)) {
if (!isLastBlockChild || tag === 'li') {
content += '\n';
}

Expand Down Expand Up @@ -2510,12 +2490,8 @@
if (nodeType === 1) {
// skip empty nlf elements (new lines automatically
// added after block level elements like quotes)
if (is(node, '.sceditor-nlf')) {
if (!firstChild || (!IE_BR_FIX &&
node.childNodes.length === 1 &&
/br/i.test(firstChild.nodeName))) {
return;
}
if (is(node, '.sceditor-nlf') && !firstChild) {
return;
}

// don't convert iframe contents
Expand Down
18 changes: 2 additions & 16 deletions src/formats/xhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
(function (sceditor) {
'use strict';

var IE_VER = sceditor.ie;

// In IE < 11 a BR at the end of a block level element
// causes a double line break.
var IE_BR_FIX = IE_VER && IE_VER < 11;

var dom = sceditor.dom;
var utils = sceditor.utils;

Expand Down Expand Up @@ -312,14 +306,7 @@
function serializeNode(node, parentIsPre) {
switch (node.nodeType) {
case 1: // element
var tagName = node.nodeName.toLowerCase();

// IE comment
if (tagName === '!') {
handleComment(node);
} else {
handleElement(node, parentIsPre);
}
handleElement(node, parentIsPre);
break;

case 3: // text
Expand Down Expand Up @@ -731,8 +718,7 @@
// skip empty nlf elements (new lines automatically
// added after block level elements like quotes)
if (is(node, '.sceditor-nlf')) {
if (!firstChild || (!IE_BR_FIX &&
node.childNodes.length === 1 &&
if (!firstChild || (node.childNodes.length === 1 &&
/br/i.test(firstChild.nodeName))) {
// Mark as empty,it will be removed by the next code
empty = true;
Expand Down
7 changes: 0 additions & 7 deletions src/icons/material.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@
if (!isSourceMode && currentNode) {
color = currentNode.ownerDocument
.queryCommandValue('forecolor');

// Needed for IE
if (parseInt(color) === color) {
// eslint-disable-next-line
color = ((color & 0x0000ff) << 16) | (color & 0x00ff00) | ((color & 0xff0000) >>> 16);
color = '#' + ('000000' + color.toString(16)).slice(-6);
}
}

dom.css(colorPath, 'fill', color);
Expand Down
7 changes: 0 additions & 7 deletions src/icons/monocons.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions src/lib/RangeHelper.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import * as dom from './dom.js';
import * as escape from './escape.js';
import { ie as IE_VER } from './browser.js';

// In IE < 11 a BR at the end of a block level element
// causes a line break. In all other browsers it's collapsed.
var IE_BR_FIX = IE_VER && IE_VER < 11;


/**
Expand Down Expand Up @@ -508,7 +503,7 @@ export default function RangeHelper(win, d, sanitize) {
// Check if cursor is set after a BR when the BR is the only
// child of the parent. In Firefox this causes a line break
// to occur when something is typed. See issue #321
if (!IE_BR_FIX && range.collapsed && container &&
if (range.collapsed && container &&
!dom.isInline(container, true)) {

lastChild = container.lastChild;
Expand Down
Loading

0 comments on commit 29e74ea

Please sign in to comment.