Skip to content

Commit

Permalink
5.22.0
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Sep 3, 2016
1 parent dba5822 commit b1b0e87
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 38 deletions.
2 changes: 1 addition & 1 deletion dist/css/themes/flat.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@
color: #fff; }

.medium-editor-placeholder:after {
color: #fff; }
color: #9ccea6; }
2 changes: 1 addition & 1 deletion dist/css/themes/flat.min.css

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

90 changes: 60 additions & 30 deletions dist/js/medium-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1430,11 +1430,15 @@ MediumEditor.extensions = {};
},

cleanupTags: function (el, tags) {
tags.forEach(function (tag) {
if (el.nodeName.toLowerCase() === tag) {
el.parentNode.removeChild(el);
}
});
if (tags.indexOf(el.nodeName.toLowerCase()) !== -1) {
el.parentNode.removeChild(el);
}
},

unwrapTags: function (el, tags) {
if (tags.indexOf(el.nodeName.toLowerCase()) !== -1) {
MediumEditor.util.unwrap(el, document);
}
},

// get the closest parent
Expand Down Expand Up @@ -2465,7 +2469,10 @@ MediumEditor.extensions = {};
// Helpers for event handling

attachDOMEvent: function (targets, event, listener, useCapture) {
targets = MediumEditor.util.isElement(targets) || [window, document].indexOf(targets) > -1 ? [targets] : targets;
var win = this.base.options.contentWindow,
doc = this.base.options.ownerDocument;

targets = MediumEditor.util.isElement(targets) || [win, doc].indexOf(targets) > -1 ? [targets] : targets;

Array.prototype.forEach.call(targets, function (target) {
target.addEventListener(event, listener, useCapture);
Expand All @@ -2474,8 +2481,11 @@ MediumEditor.extensions = {};
},

detachDOMEvent: function (targets, event, listener, useCapture) {
var index, e;
targets = MediumEditor.util.isElement(targets) || [window, document].indexOf(targets) > -1 ? [targets] : targets;
var index, e,
win = this.base.options.contentWindow,
doc = this.base.options.ownerDocument;

targets = MediumEditor.util.isElement(targets) || [win, doc].indexOf(targets) > -1 ? [targets] : targets;

Array.prototype.forEach.call(targets, function (target) {
index = this.indexOfListener(target, event, listener, useCapture);
Expand Down Expand Up @@ -2643,23 +2653,23 @@ MediumEditor.extensions = {};

// Helper method to call all listeners to execCommand
var callListeners = function (args, result) {
if (doc.execCommand.listeners) {
doc.execCommand.listeners.forEach(function (listener) {
listener({
command: args[0],
value: args[2],
args: args,
result: result
});
if (doc.execCommand.listeners) {
doc.execCommand.listeners.forEach(function (listener) {
listener({
command: args[0],
value: args[2],
args: args,
result: result
});
}
},
});
}
},

// Create a wrapper method for execCommand which will:
// 1) Call document.execCommand with the correct arguments
// 2) Loop through any listeners and notify them that execCommand was called
// passing extra info on the call
// 3) Return the result
// Create a wrapper method for execCommand which will:
// 1) Call document.execCommand with the correct arguments
// 2) Loop through any listeners and notify them that execCommand was called
// passing extra info on the call
// 3) Return the result
wrapper = function () {
var result = doc.execCommand.orig.apply(this, arguments);

Expand Down Expand Up @@ -2834,10 +2844,10 @@ MediumEditor.extensions = {};
// For clicks, we need to know if the mousedown that caused the click happened inside the existing focused element
// or one of the extension elements. If so, we don't want to focus another element
if (hadFocus &&
eventObj.type === 'click' &&
this.lastMousedownTarget &&
(MediumEditor.util.isDescendant(hadFocus, this.lastMousedownTarget, true) ||
isElementDescendantOfExtension(this.base.extensions, this.lastMousedownTarget))) {
eventObj.type === 'click' &&
this.lastMousedownTarget &&
(MediumEditor.util.isDescendant(hadFocus, this.lastMousedownTarget, true) ||
isElementDescendantOfExtension(this.base.extensions, this.lastMousedownTarget))) {
toFocus = hadFocus;
}

Expand All @@ -2855,7 +2865,7 @@ MediumEditor.extensions = {};

// Check if the target is external (not part of the editor, toolbar, or any other extension)
var externalEvent = !MediumEditor.util.isDescendant(hadFocus, target, true) &&
!isElementDescendantOfExtension(this.base.extensions, target);
!isElementDescendantOfExtension(this.base.extensions, target);

if (toFocus !== hadFocus) {
// If element has focus, and focus is going outside of editor
Expand Down Expand Up @@ -5196,6 +5206,13 @@ MediumEditor.extensions = {};
*/
cleanTags: ['meta'],

/* unwrapTags: [Array]
* list of element tag names to unwrap (remove the element tag but retain its child elements)
* during paste when __cleanPastedHTML__ is `true` or when
* calling `cleanPaste(text)` or `pasteHTML(html, options)` helper methods.
*/
unwrapTags: [],

init: function () {
MediumEditor.Extension.prototype.init.apply(this, arguments);

Expand Down Expand Up @@ -5479,7 +5496,8 @@ MediumEditor.extensions = {};
pasteHTML: function (html, options) {
options = MediumEditor.util.defaults({}, options, {
cleanAttrs: this.cleanAttrs,
cleanTags: this.cleanTags
cleanTags: this.cleanTags,
unwrapTags: this.unwrapTags
});

var elList, workEl, i, fragmentBody, pasteBlock = this.document.createDocumentFragment();
Expand All @@ -5501,6 +5519,7 @@ MediumEditor.extensions = {};

MediumEditor.util.cleanupAttrs(workEl, options.cleanAttrs);
MediumEditor.util.cleanupTags(workEl, options.cleanTags);
MediumEditor.util.unwrapTags(workEl, options.unwrapTags);
}

MediumEditor.util.insertHTMLCommand(this.document, fragmentBody.innerHTML.replace(/ /g, ' '));
Expand Down Expand Up @@ -6612,6 +6631,17 @@ MediumEditor.extensions = {};
MediumEditor.selection.moveCursor(this.options.ownerDocument, p);

event.preventDefault();
} else if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.BACKSPACE) &&
MediumEditor.util.isMediumEditorElement(node.parentElement) &&
!node.previousElementSibling &&
node.nextElementSibling &&
isEmpty.test(node.innerHTML)) {

// when cursor is in the first element, it's empty and user presses backspace,
// do delete action instead to get rid of the first element and move caret to 2nd
event.preventDefault();
MediumEditor.selection.moveCursor(this.options.ownerDocument, node.nextSibling);
node.parentElement.removeChild(node);
}
}

Expand Down Expand Up @@ -7768,7 +7798,7 @@ MediumEditor.parseVersionString = function (release) {

MediumEditor.version = MediumEditor.parseVersionString.call(this, ({
// grunt-bump looks for this:
'version': '5.21.1'
'version': '5.22.0'
}).version);

return MediumEditor;
Expand Down
8 changes: 4 additions & 4 deletions dist/js/medium-editor.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medium-editor",
"version": "5.21.1",
"version": "5.22.0",
"author": "Davi Ferreira <hi@daviferreira.com>",
"contributors": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/js/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ MediumEditor.parseVersionString = function (release) {

MediumEditor.version = MediumEditor.parseVersionString.call(this, ({
// grunt-bump looks for this:
'version': '5.21.1'
'version': '5.22.0'
}).version);

0 comments on commit b1b0e87

Please sign in to comment.