Skip to content

Commit

Permalink
Improve Cannot delete contenteditable=false elements in IE10 #271
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Pulges committed Dec 8, 2015
1 parent 5149bae commit 76a85d8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
25 changes: 25 additions & 0 deletions src/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,31 @@ wysihtml5.polyfills = function(win, doc) {
} else {
F();
}

// CustomEvent for ie9 and up
function nativeCustomEventSupported() {
try {
var p = new CustomEvent('cat', {detail: {foo: 'bar'}});
return 'cat' === p.type && 'bar' === p.detail.foo;
} catch (e) {}
return false;
}
var customEventSupported = nativeCustomEventSupported();

// Polyfills CustomEvent object for IE9 and up
(function() {
if (!customEventSupported && "CustomEvent" in window) {
function CustomEvent(event, params) {
params = params || {bubbles: false, cancelable: false, detail: undefined};
var evt = doc.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
}
CustomEvent.prototype = win.Event.prototype;
win.CustomEvent = CustomEvent;
customEventSupported = true;
}
})();
};

wysihtml5.polyfills(window, document);
5 changes: 5 additions & 0 deletions src/selection/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,11 @@
startOffset = (sel.isBackwards()) ? sel.focusOffset : sel.anchorOffset,
rng = this.createRange(), endNode, inTmpCaret;

// If start is textnode and all is whitespace before caret. Set start offset to 0
if (startNode && startNode.nodeType === 3 && (/^\s*$/).test(startNode.data.slice(0, startOffset))) {
startOffset = 0;
}

// Escape temproray helper nodes if selection in them
inTmpCaret = wysihtml5.dom.getParentElement(startNode, { query: '._wysihtml5-temp-caret-fix' }, 1);
if (inTmpCaret) {
Expand Down
11 changes: 6 additions & 5 deletions src/views/composer.observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
return true;
}
try {
var ev = new CustomEvent("wysihtml5:uneditable:delete");
var ev = new CustomEvent("wysihtml5:uneditable:delete", {bubbles: true, cancelable: false});
before.node.dispatchEvent(ev);
} catch (err) {}
before.node.parentNode.removeChild(before.node);
Expand Down Expand Up @@ -154,18 +154,19 @@
element = composer.element;

if (selection.isCollapsed()) {
if (fixDeleteInTheBeginningOfLi(composer)) {
if (handleUneditableDeletion(composer)) {
event.preventDefault();
return;
} else if (fixDeleteInTheBeginningOfBlock(composer)) {
}
if (fixDeleteInTheBeginningOfLi(composer)) {
event.preventDefault();
return;
}
if (fixLastBrDeletionInTable(composer)) {
if (fixDeleteInTheBeginningOfBlock(composer)) {
event.preventDefault();
return;
}
if (handleUneditableDeletion(composer)) {
if (fixLastBrDeletionInTable(composer)) {
event.preventDefault();
return;
}
Expand Down

0 comments on commit 76a85d8

Please sign in to comment.