});\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
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
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