integration wip: lists - creating, unnesting
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 11 Jul 2013 10:33:26 +0000 (12:33 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 11 Jul 2013 10:46:37 +0000 (12:46 +0200)
modules/documentCanvas/canvas/canvas.js
modules/documentCanvas/canvasManager.js

index 5ff19bd..1bd2f15 100644 (file)
@@ -115,6 +115,11 @@ $.extend(Canvas.prototype, {
             wrapperElement.after({text: suffixOutside});
         return wrapperElement;
     },
             wrapperElement.after({text: suffixOutside});
         return wrapperElement;
     },
+    getDocumentElement: function(from) {
+        if(from instanceof HTMLElement) {
+           return documentElement.wrap(from, this);
+        }
+    },
     list: {}
 });
 
     list: {}
 });
 
@@ -234,6 +239,12 @@ $.extend(Canvas.prototype.list, {
 
             reference.after(toAdd);
         }
 
             reference.after(toAdd);
         }
+    },
+    areItemsOfTheSameList: function(params) {
+        var e1 = params.element1,
+            e2 = params.element2;
+        return e1.parent().sameNode(e2.parent())
+            && e1.parent().is('list');
     }
 });
 
     }
 });
 
index 26bc4fa..95e1d91 100644 (file)
@@ -229,25 +229,19 @@ Manager.prototype.onBackspaceKey = function(e) {
 };
 
 Manager.prototype.command = function(command, meta) {
 };
 
 Manager.prototype.command = function(command, meta) {
-    var pos = getCursorPosition();
-    
+    var selection  = window.getSelection(),
+        node1 = $(selection.anchorNode).parent()[0],
+        node2 = $(selection.focusNode).parent()[0],
+        element1 = this.canvas.getDocumentElement(node1),
+        element2 = this.canvas.getDocumentElement(node2);
     if(command === 'createList') {
     if(command === 'createList') {
-        var node = canvasNode.create(pos.parentNode);
-        if(window.getSelection().getRangeAt(0).collapsed && this.canvas.nodeInsideList({node: node})) {
-            this.canvas.listRemove({pointer: node});
-            this.selectNode(node, {movecaret: 'end'});
-            this.sandbox.publish('contentChanged');
-        }
-        else {
-            //if(!this.canvas.nodeInsideList({node: node})) {
-                this.canvas.listCreate({start: node, end: canvasNode.create(pos.focusNode), type: meta});
-                this.selectNode(node, {movecaret: 'end'});
-                this.sandbox.publish('contentChanged');
-            //}
-        }
+        this.canvas.list.create({element1: element1, element2: element2});
     } else if(command === 'unwrap-node') {
     } else if(command === 'unwrap-node') {
-        this.canvas.nodeUnwrap({node: canvasNode.create(pos.parentNode)});
-        this.sandbox.publish('contentChanged');
+        // this.canvas.nodeUnwrap({node: canvasNode.create(pos.parentNode)});
+        // this.sandbox.publish('contentChanged');
+        if(this.canvas.list.areItemsOfTheSameList({element1: element1, element2: element2})) {
+            this.canvas.list.extractItems({element1: element1, element2: element2});
+        }
     }
 
 };
     }
 
 };