Skip to content

Commit

Permalink
Merge pull request #327 from claire-lee/ie-list-fix
Browse files Browse the repository at this point in the history
Fixing IE logic for list item deletion
  • Loading branch information
Oliver Pulges committed May 12, 2016
2 parents e4ca710 + 07899e8 commit e6e9fdf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ wysihtml5.polyfills = function(win, doc) {
};
}

// closest and matches polyfill
// closest, matches, and remove polyfill
// https://github.com/jonathantneal/closest
(function (ELEMENT) {
ELEMENT.matches = ELEMENT.matches || ELEMENT.mozMatchesSelector || ELEMENT.msMatchesSelector || ELEMENT.oMatchesSelector || ELEMENT.webkitMatchesSelector || function matches(selector) {
Expand Down Expand Up @@ -124,7 +124,14 @@ wysihtml5.polyfills = function(win, doc) {

return element;
};
}(Element.prototype));

ELEMENT.remove = ELEMENT.remove || function remove() {
if (this.parentNode) {
this.parentNode.removeChild(this);
}
};

}(win.Element.prototype));

// Element.classList for ie8-9 (toggle all IE)
// source http://purl.eligrey.com/github/classList.js/blob/master/classList.js
Expand Down
10 changes: 9 additions & 1 deletion src/views/composer.observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@
var selection = composer.selection.getSelection(),
aNode = selection.anchorNode,
listNode, prevNode, firstNode,
isInBeginnig = composer.selection.caretIsFirstInSelection();
isInBeginnig = composer.selection.caretIsFirstInSelection(),
prevNode,
intermediaryNode;

// Fix caret at the beginnig of first textNode in LI
if (aNode.nodeType === 3 && selection.anchorOffset === 0 && aNode === aNode.parentNode.firstChild) {
Expand All @@ -132,10 +134,16 @@
prevNode = domNode(aNode).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
if (!prevNode && aNode.parentNode && (aNode.parentNode.nodeName === "UL" || aNode.parentNode.nodeName === "OL")) {
prevNode = domNode(aNode.parentNode).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
intermediaryNode = aNode.parentNode;
}
if (prevNode) {
firstNode = aNode.firstChild;
domNode(aNode).transferContentTo(prevNode, true);

if (intermediaryNode && intermediaryNode.children.length === 0){
intermediaryNode.remove();
}

if (firstNode) {
composer.selection.setBefore(firstNode);
} else if (prevNode) {
Expand Down

0 comments on commit e6e9fdf

Please sign in to comment.