nested list wip
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 27 Jun 2013 14:38:39 +0000 (16:38 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 27 Jun 2013 14:38:39 +0000 (16:38 +0200)
modules/documentCanvas/canvas.js
modules/documentCanvas/canvasManager.js
modules/documentCanvas/nodes.less
modules/documentCanvas/tests/canvas.test.js

index 0585d12..be5323a 100644 (file)
@@ -161,7 +161,19 @@ Canvas.prototype.listCreate = function(options) {
     });\r
     \r
     var list = canvasNode.create({tag: 'div', klass: 'list-items' + (options.type === 'enum' ? '-enum' : '')}).dom; //this._createNode('div', 'list-items');\r
-    element1.before(list);\r
+    \r
+    var parentNode = options.start.parent();\r
+    \r
+    var toret;\r
+    if(parentNode && parentNode.isOfClass('list-items')) {\r
+        list.wrap('<div wlxml-tag="div" wlxml-class="item">');\r
+        toret = list.parent();\r
+    } else {\r
+        toret = list;\r
+    }\r
+        \r
+    \r
+    element1.before(toret);\r
     \r
     nodesToWrap.forEach(function(node) {\r
         node.remove();\r
@@ -174,9 +186,19 @@ Canvas.prototype.listRemove = function(options) {
     var listElement = options.pointer.getClass() === 'list-items' ? pointerElement : \r
         pointerElement.parents('[wlxml-class|="list-items"][wlxml-tag]');\r
     \r
-    listElement.find('[wlxml-class=item]').each(function() {\r
-        $(this).removeAttr('wlxml-class');\r
-    });\r
+    var nested = false;\r
+    if(listElement.length > 1) {\r
+        listElement = $(listElement[0]);\r
+        nested = true;\r
+    }\r
+    \r
+    if(nested) {\r
+        listElement.unwrap();\r
+    } else {\r
+        listElement.find('[wlxml-class=item]').each(function() {\r
+            $(this).removeAttr('wlxml-class');\r
+        });\r
+    }\r
     listElement.children().unwrap();\r
 };\r
 \r
index da9b941..a42eee6 100644 (file)
@@ -223,11 +223,11 @@ Manager.prototype.command = function(command, meta) {
             this.sandbox.publish('contentChanged');\r
         }\r
         else {\r
-            if(!this.canvas.nodeInsideList({node: node})) {\r
+            //if(!this.canvas.nodeInsideList({node: node})) {\r
                 this.canvas.listCreate({start: node, end: canvasNode.create(pos.focusNode), type: meta});\r
                 this.selectNode(node, {movecaret: 'end'});\r
                 this.sandbox.publish('contentChanged');\r
-            }\r
+            //}\r
         }\r
     }\r
 \r
index 2f51045..af084a7 100644 (file)
@@ -74,6 +74,12 @@ span[wlxml-tag] {
     }\r
 }\r
 \r
+[wlxml-class="item"] {\r
+    > [wlxml-class="list-items"] {\r
+        display: block;\r
+    }\r
+}\r
+\r
 \r
 [wlxml-class="list-items-enum"] {\r
 \r
index fc842e5..57fb308 100644 (file)
@@ -186,5 +186,64 @@ define([
             assert.ok(c.nodeInsideList({node: c.findNodes({klass: 'item'})[1]}), 'item is inside a list');\r
             assert.ok(c.nodeInsideList({node: c.findNodes({tag: 'span'})[0]}), 'things nested in item are inside a list');\r
         });\r
+        \r
+        test('moving items to nested list', function() {\r
+            var listHTML = utils.cleanUp('\\r
+                    <div wlxml-tag="div" wlxml-class="list-items">\\r
+                        <div wlxml-tag="div" wlxml-class="item">alice</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">cat</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">dog</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">bee</div>\\r
+                    </div>');\r
+            var c = canvas.create(listHTML);\r
+            var items = c.findNodes({klass: 'item'});\r
+            var cat_item = items[1];\r
+            var dog_item = items[2];\r
+            \r
+            c.listCreate({start: cat_item, end: dog_item});\r
+            \r
+            assertDomEqual(c.getContent(), utils.cleanUp('\\r
+                    <div wlxml-tag="div" wlxml-class="list-items">\\r
+                        <div wlxml-tag="div" wlxml-class="item">alice</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">\\r
+                            <div wlxml-tag="div" wlxml-class="list-items">\\r
+                                <div wlxml-tag="div" wlxml-class="item">cat</div>\\r
+                                <div wlxml-tag="div" wlxml-class="item">dog</div>\\r
+                            </div>\\r
+                        </div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">bee</div>\\r
+                    </div>'\r
+            ));\r
+        });\r
+        \r
+        test('removing nested list', function() {\r
+            var nestedList = utils.cleanUp('\\r
+                    <div wlxml-tag="div" wlxml-class="list-items">\\r
+                        <div wlxml-tag="div" wlxml-class="item">alice</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">\\r
+                            <div wlxml-tag="div" wlxml-class="list-items">\\r
+                                <div wlxml-tag="div" wlxml-class="item">cat</div>\\r
+                                <div wlxml-tag="div" wlxml-class="item">dog</div>\\r
+                            </div>\\r
+                        </div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">bee</div>\\r
+                    </div>');\r
+                    \r
+            var c = canvas.create(nestedList);\r
+            var dog_item = c.findNodes('[wlxml-class=list-items] [wlxml-class=list-items] > div')[1];\r
+            assert.equal(dog_item.getContent(), 'dog');\r
+            \r
+            c.listRemove({pointer: dog_item});\r
+            \r
+            assertDomEqual(c.getContent(), utils.cleanUp('\\r
+                    <div wlxml-tag="div" wlxml-class="list-items">\\r
+                        <div wlxml-tag="div" wlxml-class="item">alice</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">cat</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">dog</div>\\r
+                        <div wlxml-tag="div" wlxml-class="item">bee</div>\\r
+                    </div>'));\r
+            \r
+            \r
+        });\r
     });\r
 });
\ No newline at end of file