From: Aleksander Ɓukasz Date: Mon, 24 Jun 2013 10:40:16 +0000 (+0200) Subject: canvas api: removing list X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/3501d4ca6ca516663162da0cd2bd1e12b8491450?ds=inline;hp=52f3927cfc1af1e9eaa469b73a33c9575ef710d8 canvas api: removing list --- diff --git a/modules/documentCanvas/canvas.js b/modules/documentCanvas/canvas.js index 5de60f4..5db5e78 100644 --- a/modules/documentCanvas/canvas.js +++ b/modules/documentCanvas/canvas.js @@ -15,8 +15,8 @@ var Canvas = function(xml) { } Canvas.prototype.setXML = function(xml) { - this.xml = xml; - this.content.html(transformations.fromXML.getHTMLTree(xml)); + this.xml = $.trim(xml); + this.content.html(transformations.fromXML.getHTMLTree(this.xml)); } Canvas.prototype.toXML = function() { @@ -161,8 +161,17 @@ Canvas.prototype.createList = function(options) { node.remove(); list.append(node); }); +} + +Canvas.prototype.removeList = function(options) { + var pointerElement = $(this.content.find('#' + options.pointer.id)); + var listElement = options.pointer.klass === 'list-items' ? pointerElement : + pointerElement.parent('[wlxml-class="list-items"][wlxml-tag]'); - + listElement.find('[wlxml-class=item]').each(function() { + $(this).attr('wlxml-class', ''); + });; + listElement.children().unwrap(); } diff --git a/modules/documentCanvas/tests/canvas.test.js b/modules/documentCanvas/tests/canvas.test.js index 7515309..35f0d85 100644 --- a/modules/documentCanvas/tests/canvas.test.js +++ b/modules/documentCanvas/tests/canvas.test.js @@ -136,6 +136,28 @@ define([ '); }); + + test('remove list', function() { + var xml = '\ +
\ +
\ +
Alice
\ +
has
\ +
a cat
\ +
\ +
some text
\ +
'; + var c = new canvas.Canvas(xml); + var item = c.getNode({klass: 'item'})[1]; + c.removeList({pointer: item}); + assert.xmlEqual(c.toXML(), '\ +
\ +
Alice
\ +
has
\ +
a cat
\ +
some text
\ +
'); + }); }); }); \ No newline at end of file diff --git a/modules/documentCanvas/transformations.js b/modules/documentCanvas/transformations.js index 44ab78a..d245818 100644 --- a/modules/documentCanvas/transformations.js +++ b/modules/documentCanvas/transformations.js @@ -76,7 +76,8 @@ define(['libs/jquery-1.9.1.min'], function($) { var wlxmlName = split.splice(1).join('-'); var value = wlxmlName === 'class' ? attr.value.replace(/-/g, '.') : attr.value; console.log(name + ': ' + value); - toret.attr(wlxmlName, value); + if(value.length && value.length > 0) + toret.attr(wlxmlName, value); } toret.append(div.contents());