fix selecting nodes with no text & allow deleting images
authorJan Szejko <j-sz@o2.pl>
Wed, 9 Mar 2016 12:42:08 +0000 (13:42 +0100)
committerJan Szejko <j-sz@o2.pl>
Wed, 9 Mar 2016 12:42:08 +0000 (13:42 +0100)
src/editor/plugins/core/img/box.html
src/editor/plugins/core/img/imgElement.js
src/wlxml/wlxml.js

index e07a7f3..9294581 100644 (file)
@@ -1,7 +1,7 @@
 <div link-box style="white-space: nowrap">
     <a link target="blank" href="<%= url %>"><%= text %></a> <br/>--
     <span>
 <div link-box style="white-space: nowrap">
     <a link target="blank" href="<%= url %>"><%= text %></a> <br/>--
     <span>
-        <a class="change" href="#"><%= gettext('change') %></a> <!-- |
-        <a class="delete" href="#"><%= gettext('remove') %></a> -->
+        <a class="change" href="#"><%= gettext('change') %></a>
+        <a class="delete" href="#"><%= gettext('remove') %></a>
     </span>
 </div>
     </span>
 </div>
index 622c127..0ec3ca5 100644 (file)
@@ -91,23 +91,20 @@ _.extend(linkElement, {
             doc = this.wlxmlNode.document;
 
         el.wlxmlNode.document.transaction(function() {
             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: {
         }, {
             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')
             }
         });
     },
             }
         });
     },
index ef70d3d..1837e14 100644 (file)
@@ -238,6 +238,12 @@ $.extend(WLXMLDocument.prototype, {
             metadataNode.remove();
         });
         nativeNode.normalize();
             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;})
 
         $(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',
                     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) {
 
 
                 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
                     addInfo(text.original, 'below');
                     el.remove();
                     return true; // continue