-\r
- var element = $(this.content.find('#' + options.inside.getId()).get(0));\r
-\r
- var elementContents = element.contents();\r
- if(elementContents.length === 0 || \r
- elementContents.length - 1 < options.textNodeIdx || \r
- elementContents.get(options.textNodeIdx).nodeType != 3)\r
- return false;\r
- var textElement = elementContents.get(options.textNodeIdx);\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
+ 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