- },
-
- toXML: function() {
- var parent = $('<div>'),
- parts = this.doc().toXML(0);
- parent.append(parts);
- return parent.html();
- }
-});
-
-$.extend(Canvas.prototype.list, {
- create: function(params) {
- if(!(params.element1.parent().sameNode(params.element2.parent())))
- return false;
-
- var parent = params.element1.parent(),
- canvas = params.element1.canvas;
-
- if(parent.childIndex(params.element1) > parent.childIndex(params.element2)) {
- var tmp = params.element1;
- params.element1 = params.element2;
- params.element2 = tmp;
- }
-
- var elementsToWrap = [];
-
- var place = 'before';
- parent.children().some(function(element) {
- var _e = element;
- if(element.sameNode(params.element1))
- place = 'inside';
- if(place === 'inside') {
- if(element instanceof documentElement.DocumentTextElement) {
- element = element.wrapWithNodeElement({tag: 'div', klass: 'list.item'});
- if(element.children()[0].sameNode(params.element1))
- params.element1 = element;
- }
- element.setWlxmlClass('item');
- elementsToWrap.push(element);
- }
- if(_e.sameNode(params.element2))
- return true;
- });
-
- var listElement = canvas.createNodeElement({tag: 'div', klass: 'list-items' + (params.type === 'enum' ? '-enum' : '')});
- var toret;
- if(parent.is('list')) {
- var item = listElement.wrapWithNodeElement({tag: 'div', klass: 'item'});
- item.exec('toggleBullet', false);
- toret = listElement.parent();
- } else {
- toret = listElement;
- }
-
- params.element1.before(toret);
-
- elementsToWrap.forEach(function(element) {
- element.detach();
- listElement.append(element);
- });
- },
- extractItems: function(params) {
- params = _.extend({merge: true}, params);
- var list = params.element1.parent();
- if(!list.is('list') || !(list.sameNode(params.element2.parent())))
- return false;
-
- var idx1 = list.childIndex(params.element1),
- idx2 = list.childIndex(params.element2),
- precedingItems = [],
- extractedItems = [],
- succeedingItems = [],
- items = list.children(),
- listIsNested = list.parent().getWlxmlClass() === 'item',
- canvas = params.element1.canvas,
- i;
-
- if(idx1 > idx2) {
- var tmp = idx1; idx1 = idx2; idx2 = tmp;