From: Jan Szejko Date: Wed, 9 Mar 2016 12:42:08 +0000 (+0100) Subject: fix selecting nodes with no text & allow deleting images X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/695d1a0067346347cf36bedab8fdce7ae39d5270?ds=inline;hp=83c3d33472c6828f617ffde4bea861e7cd403e79 fix selecting nodes with no text & allow deleting images --- diff --git a/src/editor/plugins/core/img/box.html b/src/editor/plugins/core/img/box.html index e07a7f3..9294581 100644 --- a/src/editor/plugins/core/img/box.html +++ b/src/editor/plugins/core/img/box.html @@ -1,7 +1,7 @@
<%= text %>
-- - <%= gettext('change') %> + <%= gettext('change') %> + <%= gettext('remove') %>
diff --git a/src/editor/plugins/core/img/imgElement.js b/src/editor/plugins/core/img/imgElement.js index 622c127..0ec3ca5 100644 --- a/src/editor/plugins/core/img/imgElement.js +++ b/src/editor/plugins/core/img/imgElement.js @@ -91,23 +91,20 @@ _.extend(linkElement, { doc = this.wlxmlNode.document; el.wlxmlNode.document.transaction(function() { - var f = el.canvas.getSelection().toDocumentFragment(), - prefLen = 0, - ret; - - if(el.wlxmlNode.isPrecededByTextNode()) { - prefLen = el.wlxmlNode.prev().getText().length; - } - - ret = el.wlxmlNode.unwrapContent(); - return doc.createFragment(doc.CaretFragment, {node: ret.element1, offset: prefLen + f.offset}); + //var f = el.canvas.getSelection().toDocumentFragment(), + // prefLen = 0, + // ret; + // + //if(el.wlxmlNode.isPrecededByTextNode()) { + // prefLen = el.wlxmlNode.prev().getText().length; + //} + // + //ret = el.wlxmlNode.unwrapContent(); + //return doc.createFragment(doc.CaretFragment, {node: ret.element1, offset: prefLen + f.offset}); + el.wlxmlNode.detach(); }, { metadata: { - description: gettext('Remove link'), - fragment: doc.createFragment(doc.CaretFragment, {node: el.wlxmlNode.contents()[0], offset:0}) - }, - success: function(ret) { - el.canvas.select(ret); + description: gettext('Remove link') } }); }, diff --git a/src/wlxml/wlxml.js b/src/wlxml/wlxml.js index ef70d3d..1837e14 100644 --- a/src/wlxml/wlxml.js +++ b/src/wlxml/wlxml.js @@ -238,6 +238,12 @@ $.extend(WLXMLDocument.prototype, { metadataNode.remove(); }); nativeNode.normalize(); + $(nativeNode).find('*').each(function() { + if (this.childNodes.length === 0) { + var fakeTextNode = window.document.createTextNode(""); + this.appendChild(fakeTextNode); + } + }); $(nativeNode).find(':not(iframe)').addBack().contents() .filter(function() {return this.nodeType === Node.TEXT_NODE;}) @@ -247,7 +253,8 @@ $.extend(WLXMLDocument.prototype, { elParent = el.parent(), hasSpanParent = elParent.prop('tagName') === 'SPAN', hasSpanBefore = el.prev().length && $(el.prev()).prop('tagName') === 'SPAN', - hasSpanAfter = el.next().length && $(el.next()).prop('tagName') === 'SPAN'; + hasSpanAfter = el.next().length && $(el.next()).prop('tagName') === 'SPAN', + onlyChild = el.is(':only-child'); var addInfo = function(toAdd, where, transformed, original) { @@ -288,7 +295,7 @@ $.extend(WLXMLDocument.prototype, { } } - if(!text.transformed) { + if(!text.transformed && !onlyChild) { addInfo(text.original, 'below'); el.remove(); return true; // continue