From: Aleksander Ɓukasz Date: Thu, 27 Jun 2013 14:38:39 +0000 (+0200) Subject: nested list wip X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/59425d79741dd5746a76dab417aade4986c88d99?ds=sidebyside nested list wip --- diff --git a/modules/documentCanvas/canvas.js b/modules/documentCanvas/canvas.js index 0585d12..be5323a 100644 --- a/modules/documentCanvas/canvas.js +++ b/modules/documentCanvas/canvas.js @@ -161,7 +161,19 @@ Canvas.prototype.listCreate = function(options) { }); var list = canvasNode.create({tag: 'div', klass: 'list-items' + (options.type === 'enum' ? '-enum' : '')}).dom; //this._createNode('div', 'list-items'); - element1.before(list); + + var parentNode = options.start.parent(); + + var toret; + if(parentNode && parentNode.isOfClass('list-items')) { + list.wrap('
'); + toret = list.parent(); + } else { + toret = list; + } + + + element1.before(toret); nodesToWrap.forEach(function(node) { node.remove(); @@ -174,9 +186,19 @@ Canvas.prototype.listRemove = function(options) { var listElement = options.pointer.getClass() === 'list-items' ? pointerElement : pointerElement.parents('[wlxml-class|="list-items"][wlxml-tag]'); - listElement.find('[wlxml-class=item]').each(function() { - $(this).removeAttr('wlxml-class'); - }); + var nested = false; + if(listElement.length > 1) { + listElement = $(listElement[0]); + nested = true; + } + + if(nested) { + listElement.unwrap(); + } else { + listElement.find('[wlxml-class=item]').each(function() { + $(this).removeAttr('wlxml-class'); + }); + } listElement.children().unwrap(); }; diff --git a/modules/documentCanvas/canvasManager.js b/modules/documentCanvas/canvasManager.js index da9b941..a42eee6 100644 --- a/modules/documentCanvas/canvasManager.js +++ b/modules/documentCanvas/canvasManager.js @@ -223,11 +223,11 @@ Manager.prototype.command = function(command, meta) { this.sandbox.publish('contentChanged'); } else { - if(!this.canvas.nodeInsideList({node: node})) { + //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'); - } + //} } } diff --git a/modules/documentCanvas/nodes.less b/modules/documentCanvas/nodes.less index 2f51045..af084a7 100644 --- a/modules/documentCanvas/nodes.less +++ b/modules/documentCanvas/nodes.less @@ -74,6 +74,12 @@ span[wlxml-tag] { } } +[wlxml-class="item"] { + > [wlxml-class="list-items"] { + display: block; + } +} + [wlxml-class="list-items-enum"] { diff --git a/modules/documentCanvas/tests/canvas.test.js b/modules/documentCanvas/tests/canvas.test.js index fc842e5..57fb308 100644 --- a/modules/documentCanvas/tests/canvas.test.js +++ b/modules/documentCanvas/tests/canvas.test.js @@ -186,5 +186,64 @@ define([ assert.ok(c.nodeInsideList({node: c.findNodes({klass: 'item'})[1]}), 'item is inside a list'); assert.ok(c.nodeInsideList({node: c.findNodes({tag: 'span'})[0]}), 'things nested in item are inside a list'); }); + + test('moving items to nested list', function() { + var listHTML = utils.cleanUp('\ +
\ +
alice
\ +
cat
\ +
dog
\ +
bee
\ +
'); + var c = canvas.create(listHTML); + var items = c.findNodes({klass: 'item'}); + var cat_item = items[1]; + var dog_item = items[2]; + + c.listCreate({start: cat_item, end: dog_item}); + + assertDomEqual(c.getContent(), utils.cleanUp('\ +
\ +
alice
\ +
\ +
\ +
cat
\ +
dog
\ +
\ +
\ +
bee
\ +
' + )); + }); + + test('removing nested list', function() { + var nestedList = utils.cleanUp('\ +
\ +
alice
\ +
\ +
\ +
cat
\ +
dog
\ +
\ +
\ +
bee
\ +
'); + + var c = canvas.create(nestedList); + var dog_item = c.findNodes('[wlxml-class=list-items] [wlxml-class=list-items] > div')[1]; + assert.equal(dog_item.getContent(), 'dog'); + + c.listRemove({pointer: dog_item}); + + assertDomEqual(c.getContent(), utils.cleanUp('\ +
\ +
alice
\ +
cat
\ +
dog
\ +
bee
\ +
')); + + + }); }); }); \ No newline at end of file