};\r
\r
Canvas.prototype.nodeWrap = function(options) {\r
- var element = $(this.content.find('#' + options.inside.getId()).get(0));\r
-\r
- var elementContents = element.contents();\r
- if(elementContents.length !== 1 || elementContents.get(0).nodeType != 3)\r
- return false;\r
- var textElement = elementContents.get(0);\r
-\r
- var prefix = textElement.data.substr(0, options.offsetStart);\r
- var suffix = textElement.data.substr(options.offsetEnd);\r
- var core = textElement.data.substr(options.offsetStart, options.offsetEnd - options.offsetStart);\r
- options._with.setContent(core);\r
-\r
- $(textElement).replaceWith(options._with.dom);\r
- options._with.dom.before(prefix);\r
- options._with.dom.after(suffix);\r
+ options = _.extend({textNodeIdx: 0}, options);\r
+ if(typeof options.textNodeIdx === 'number')\r
+ options.textNodeIdx = [options.textNodeIdx];\r
+ \r
+ var container = $(this.content.find('#' + options.inside.getId()).get(0)),\r
+ containerContent = container.contents(),\r
+ idx1 = Math.min.apply(Math, options.textNodeIdx),\r
+ idx2 = Math.max.apply(Math, options.textNodeIdx),\r
+ textNode1 = $(containerContent.get(idx1)),\r
+ textNode2 = $(containerContent.get(idx2)),\r
+ sameNode = textNode1.get(0) === textNode2.get(0),\r
+ prefixOutside = textNode1.text().substr(0, options.offsetStart),\r
+ prefixInside = textNode1.text().substr(options.offsetStart),\r
+ suffixInside = textNode2.text().substr(0, options.offsetEnd),\r
+ suffixOutside = textNode2.text().substr(options.offsetEnd)\r
+ ;\r
+ \r
+ textNode1.after(options._with.dom);\r
+ textNode1.detach();\r
+ \r
+ options._with.dom.before(prefixOutside);\r
+ if(sameNode) {\r
+ var core = textNode1.text().substr(options.offsetStart, options.offsetEnd - options.offsetStart);\r
+ options._with.setContent(core);\r
+ } else {\r
+ textNode2.detach();\r
+ options._with.dom.append(prefixInside);\r
+ for(var i = idx1 + 1; i < idx2; i++) {\r
+ options._with.dom.append(containerContent[i]);\r
+ }\r
+ options._with.dom.append(suffixInside);\r
+ }\r
+ options._with.dom.after(suffixOutside);\r
};\r
\r
Canvas.prototype.nodeSplit = function(options) {\r
var node = this;\r
if(passed)\r
succeedingNodes.push(node);\r
- if(node.isSameNode(textNode.get(0)))\r
+ if(node === textNode.get(0))\r
passed = true;\r
});\r
\r
Canvas.prototype.listCreate = function(options) {\r
var element1 = $(this.content.find('#' + options.start.getId()).get(0));\r
var element2 = $(this.content.find('#' + options.end.getId()).get(0));\r
- if(!element1.parent().get(0).isSameNode(element2.parent().get(0)))\r
+ if(!element1.parent().get(0) === element2.parent().get(0))\r
return false;\r
\r
var parent = element1.parent();\r
var canvas = this;\r
parent.contents().each(function() {\r
var node = this;\r
- if(node.isSameNode(element1.get(0)))\r
+ if(node === element1.get(0))\r
place = 'inside';\r
if(place === 'inside') {\r
var $node;\r
$node.attr('wlxml-class', 'item');\r
nodesToWrap.push($node);\r
}\r
- if(node.isSameNode(element2.get(0)))\r
+ if(node === element2.get(0))\r
return false;\r
});\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" class="canvas-silent-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