};\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
\r
var toret;\r
if(parentNode && parentNode.isOfClass('list-items')) {\r
- list.wrap('<div wlxml-tag="div" wlxml-class="item">');\r
+ list.wrap('<div wlxml-tag="div" wlxml-class="item" class="canvas-silent-item">');\r
toret = list.parent();\r
} else {\r
toret = list;\r