+ return documentElement.wrap(this.d.get(0), this); //{wlxmlTag: this.d.prop('tagName')};
+ },
+
+ wrapText: function(params) {
+ params = _.extend({textNodeIdx: 0}, params);
+ if(typeof params.textNodeIdx === 'number')
+ params.textNodeIdx = [params.textNodeIdx];
+
+ var childrenInside = params.inside.children(),
+ idx1 = Math.min.apply(Math, params.textNodeIdx),
+ idx2 = Math.max.apply(Math, params.textNodeIdx),
+ textNode1 = childrenInside[idx1],
+ textNode2 = childrenInside[idx2],
+ sameNode = textNode1.sameNode(textNode2),
+ prefixOutside = textNode1.getText().substr(0, params.offsetStart),
+ prefixInside = textNode1.getText().substr(params.offsetStart),
+ suffixInside = textNode2.getText().substr(0, params.offsetEnd),
+ suffixOutside = textNode2.getText().substr(params.offsetEnd)
+ ;
+
+ var wrapperElement = documentElement.DocumentNodeElement.create({tag: params._with.tag, klass: params._with.klass});
+ textNode1.after(wrapperElement);
+ textNode1.detach();
+
+ if(prefixOutside.length > 0)
+ wrapperElement.before({text:prefixOutside});
+ if(sameNode) {
+ var core = textNode1.getText().substr(params.offsetStart, params.offsetEnd - params.offsetStart);
+ wrapperElement.append({text: core});
+ } else {
+ textNode2.detach();
+ if(prefixInside.length > 0)
+ wrapperElement.append({text: prefixInside});
+ for(var i = idx1 + 1; i < idx2; i++) {
+ wrapperElement.append(childrenInside[i]);
+ }
+ if(suffixInside.length > 0)
+ wrapperElement.append({text: suffixInside});
+ }
+ if(suffixOutside.length > 0)
+ wrapperElement.after({text: suffixOutside});
+ return wrapperElement;
+ },
+ getDocumentElement: function(from) {
+ if(from instanceof HTMLElement || from instanceof Text) {
+ return documentElement.wrap(from, this);
+ }
+ },
+ list: {}
+});
+
+$.extend(Canvas.prototype.list, {
+ create: function(params) {
+ if(!(params.element1.parent().sameNode(params.element2.parent())))
+ return false;
+
+ var parent = params.element1.parent();
+
+ 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';
+ var canvas = this;
+ 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 = documentElement.DocumentNodeElement.create({tag: 'div', klass: 'list-items' + (params.type === 'enum' ? '-enum' : '')});
+
+ var toret;
+ if(parent.is('list')) {
+ listElement.wrapWithNodeElement({tag: 'div', klass: 'item'});
+ 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',
+ i;
+
+ if(idx1 > idx2) {
+ var tmp = idx1; idx1 = idx2; idx2 = tmp;
+ }