editor ui: functionality of removing element while keeping its content
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 19 Aug 2013 08:00:52 +0000 (10:00 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 19 Aug 2013 08:00:52 +0000 (10:00 +0200)
modules/documentCanvas/canvas/documentElement.js
modules/documentCanvas/canvas/wlxmlManagers.js
modules/documentCanvas/commands.js
modules/documentToolbar/template.html

index 7ca7e59..f8806ae 100644 (file)
@@ -47,7 +47,7 @@ $.extend(DocumentElement.prototype, {
         this.$element = $(htmlElement);
     },
     bound: function() {
-        return this.canvas !== undefined;
+        return $.contains(document.documentElement, this.dom()[0]);
     },
     dom: function() {
         return this.$element;
index e70cfd2..e3addb2 100644 (file)
@@ -35,7 +35,7 @@ var DocumentElementWrapper = function(documentElement) {
         documentElement._container().toggle(toggle);
     }
 
-    var eventBus = documentElement.bound() ? documentElement.canvas.eventBus :
+    var eventBus = documentElement.canvas ? documentElement.canvas.eventBus :
         {trigger: function() {}};
     this.trigger = function() {
         eventBus.trigger.apply(eventBus, arguments);
index 955ba48..043d6b7 100644 (file)
@@ -132,6 +132,34 @@ commands.register('footnote', function(canvas, params) {
     canvas.setCurrentElement(asideElement);
 });
 
+commands.register('take-away-node', function(canvas) {
+    var position = canvas.getCursor().getPosition(),
+        element = position.element,
+        nodeElement = element ? element.parent() : canvas.getCurrentNodeElement();
+
+    if(!nodeElement || !(nodeElement.parent()))
+        return;
+
+
+    var range = nodeElement.unwrapContents();
+
+    if(element) {
+        var elementIsFirstChild = nodeElement.childIndex(element);
+        if(element.bound()) {
+            canvas.setCurrentElement(element, {caretTo: position.offset});
+        } else {
+            if(elementIsFirstChild) {
+                canvas.setCurrentElement(range.element1, {caretTo: 'end'});
+            } else {
+                canvas.setCurrentElement(range.element2, {caretTo: 'end'});
+            }
+        }
+    } else {
+        canvas.setCurrentElement(range.element1, {caretTo: 'start'});
+    }
+
+});
+
 
 return {
     run: function(name, params, canvas) {
index da4f456..7ba2bc5 100644 (file)
         <button data-name="new-node" data-btn-type="cmd" class="btn btn-mini"><i class="icon-plus"></i></button>
     </div>
     <div class="rng-module-documentToolbar-toolbarGroup">
-        <button data-name="unwrap-node" data-btn-type="cmd" class="btn btn-mini"><i class="icon-arrow-up"></i></button>
-        <button data-name="wrap-node" data-btn-type="cmd" class="btn btn-mini"><i class="icon-arrow-down"></i></button>
+        <button data-name="take-away-node" data-btn-type="cmd" class="btn btn-mini"><i class="icon-remove-circle"></i></button>
     </div>    
     <div class="rng-module-documentToolbar-toolbarGroup">
         <button data-name="list" data-btn-type="cmd" data-meta="bullets" class="btn btn-mini"><i class="icon-list"></i></button>
+        <button data-name="unwrap-node" data-btn-type="cmd" class="btn btn-mini"><i class="icon-arrow-up"></i></button>
+        <button data-name="wrap-node" data-btn-type="cmd" class="btn btn-mini"><i class="icon-arrow-down"></i></button>
     </div>
     <div class="rng-module-documentToolbar-toolbarGroup">
         <button data-name="footnote" data-btn-type="cmd" class="btn btn-mini"><i class="icon-comment"></i></button>