var Canvas = function(html) {\r
this.dom = $(template);\r
this.content = this.dom.find('#rng-module-documentCanvas-content');\r
+ this.setHTML(html);\r
+};\r
+\r
+Canvas.prototype.setHTML = function(html) {\r
if(html) {\r
this.content.html(html);\r
}\r
return toret;\r
};\r
\r
+Canvas.prototype.getNodeById = function(id) {\r
+ return canvasNode.create($(this.content.find('#' +id)));\r
+}\r
+\r
Canvas.prototype.nodeAppend = function(options) {\r
var element; // = $(this.content.find('#' + options.context.id).get(0));\r
if(options.to === 'root') {\r
return false;\r
});\r
\r
- var list = canvasNode.create({tag: 'div', klass: 'list-items'}).dom; //this._createNode('div', 'list-items');\r
- element1.before(list);\r
+ var list = canvasNode.create({tag: 'div', klass: 'list-items' + (options.type === 'enum' ? '-enum' : '')}).dom; //this._createNode('div', 'list-items');\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
Canvas.prototype.listRemove = function(options) {\r
var pointerElement = $(this.content.find('#' + options.pointer.getId()));\r
var listElement = options.pointer.getClass() === 'list-items' ? pointerElement : \r
- pointerElement.parent('[wlxml-class="list-items"][wlxml-tag]');\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
};\r
\r
Canvas.prototype.nodeInsideList = function(options) {\r
- if(options.pointer) {\r
- if(options.pointer.getClass() === 'list-items' || options.pointer.getClass() === 'item')\r
+ if(options.node) {\r
+ if(options.node.isOfClass('list-items') || options.node.isOfClass('item'))\r
return true;\r
- var pointerElement = $(this.content.find('#' + options.pointer.getId()));\r
- return pointerElement.parents('list-items, item').length > 0;\r
+ var pointerElement = $(this.content.find('#' + options.node.getId()));\r
+ return pointerElement.parents('[wlxml-class=list-items], [wlxml-class=item]').length > 0;\r
}\r
return false;\r
};\r