canvas api: removing list
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 24 Jun 2013 10:40:16 +0000 (12:40 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 24 Jun 2013 10:40:16 +0000 (12:40 +0200)
modules/documentCanvas/canvas.js
modules/documentCanvas/tests/canvas.test.js
modules/documentCanvas/transformations.js

index 5de60f4..5db5e78 100644 (file)
@@ -15,8 +15,8 @@ var Canvas = function(xml) {
 }\r
 \r
 Canvas.prototype.setXML = function(xml) {\r
 }\r
 \r
 Canvas.prototype.setXML = function(xml) {\r
-    this.xml = xml;\r
-    this.content.html(transformations.fromXML.getHTMLTree(xml));  \r
+    this.xml = $.trim(xml);\r
+    this.content.html(transformations.fromXML.getHTMLTree(this.xml));  \r
 }\r
 \r
 Canvas.prototype.toXML = function() {\r
 }\r
 \r
 Canvas.prototype.toXML = function() {\r
@@ -161,8 +161,17 @@ Canvas.prototype.createList = function(options) {
         node.remove();\r
         list.append(node);\r
     });\r
         node.remove();\r
         list.append(node);\r
     });\r
+}\r
+\r
+Canvas.prototype.removeList = function(options) {\r
+    var pointerElement = $(this.content.find('#' + options.pointer.id));\r
+    var listElement = options.pointer.klass === 'list-items' ? pointerElement : \r
+        pointerElement.parent('[wlxml-class="list-items"][wlxml-tag]');\r
     \r
     \r
-    \r
+    listElement.find('[wlxml-class=item]').each(function() {\r
+        $(this).attr('wlxml-class', '');\r
+    });;\r
+    listElement.children().unwrap();\r
     \r
 }\r
 \r
     \r
 }\r
 \r
index 7515309..35f0d85 100644 (file)
@@ -136,6 +136,28 @@ define([
                 </section>');\r
 \r
         });\r
                 </section>');\r
 \r
         });\r
+        \r
+        test('remove list', function() {\r
+            var xml = '\\r
+                <section>\\r
+                    <div class="list.items">\\r
+                        <div class="item">Alice</div>\\r
+                        <div class="item">has</div>\\r
+                        <div class="item">a cat</div>\\r
+                    </div>\\r
+                    <div>some text</div>\\r
+                </section>';\r
+           var c = new canvas.Canvas(xml);\r
+           var item = c.getNode({klass: 'item'})[1];\r
+           c.removeList({pointer: item});\r
+           assert.xmlEqual(c.toXML(), '\\r
+                <section>\\r
+                    <div>Alice</div>\\r
+                    <div>has</div>\\r
+                    <div>a cat</div>\\r
+                    <div>some text</div>\\r
+                </section>');\r
+        });\r
     });\r
 \r
 });
\ No newline at end of file
     });\r
 \r
 });
\ No newline at end of file
index 44ab78a..d245818 100644 (file)
@@ -76,7 +76,8 @@ define(['libs/jquery-1.9.1.min'], function($) {
                     var wlxmlName = split.splice(1).join('-');\r
                     var value = wlxmlName === 'class' ? attr.value.replace(/-/g, '.') : attr.value;\r
                     console.log(name + ': ' + value);\r
                     var wlxmlName = split.splice(1).join('-');\r
                     var value = wlxmlName === 'class' ? attr.value.replace(/-/g, '.') : attr.value;\r
                     console.log(name + ': ' + value);\r
-                    toret.attr(wlxmlName, value);\r
+                    if(value.length && value.length > 0)\r
+                        toret.attr(wlxmlName, value);\r
                 }\r
                     \r
                 toret.append(div.contents());\r
                 }\r
                     \r
                 toret.append(div.contents());\r