anchor = anchor.parent();\r
todel.remove();\r
}\r
+ if(anchorOffset > 0 && anchorOffset < anchor.text().length) {\r
+ if(wlxmlTag === null && wlxmlClass === null) {\r
+ return this.splitWithNewNode(anchor);\r
+ }\r
+ return this.wrapSelectionWithNewNode(wlxmlTag, wlxmlClass);\r
+ }\r
var newNode = this._createNode(wlxmlTag || anchor.attr('wlxml-tag'), wlxmlClass || anchor.attr('wlxml-class'));\r
if(anchorOffset === 0)\r
anchor.before(newNode)\r
isDirty = true;\r
},\r
wrapSelectionWithNewNode: function(wlxmlTag, wlxmlClass) {\r
- \r
var selection = window.getSelection();\r
if(selection.anchorNode === selection.focusNode && selection.anchorNode.nodeType === Node.TEXT_NODE) {\r
var startOffset = selection.anchorOffset;\r
var suffix = node.data.substr(endOffset);\r
var core = node.data.substr(startOffset, endOffset - startOffset);\r
var newNode = this._createNode(wlxmlTag, wlxmlClass);\r
- newNode.text(core);\r
+ newNode.text(core || 'test');\r
$(node).replaceWith(newNode);\r
newNode.before(prefix);\r
newNode.after(suffix);\r
isDirty = true;\r
}\r
},\r
+ splitWithNewNode: function(node) {\r
+ var selection = window.getSelection();\r
+ if(selection.anchorNode === selection.focusNode && selection.anchorNode.nodeType === Node.TEXT_NODE) {\r
+ var startOffset = selection.anchorOffset;\r
+ var endOffset = selection.focusOffset;\r
+ if(startOffset > endOffset) {\r
+ var tmp = startOffset;\r
+ startOffset = endOffset;\r
+ endOffset = tmp;\r
+ }\r
+ var anchor = selection.anchorNode;\r
+ var prefix = anchor.data.substr(0, startOffset);\r
+ var suffix = anchor.data.substr(endOffset);\r
+ var prefixNode = this._createNode(node.attr('wlxml-tag'), node.attr('wlxml-class'));\r
+ var newNode = this._createNode(node.attr('wlxml-tag'), node.attr('wlxml-class'));\r
+ var suffixNode = this._createNode(node.attr('wlxml-tag'), node.attr('wlxml-class'));\r
+ prefixNode.text(prefix);\r
+ suffixNode.text(suffix);\r
+ node.replaceWith(newNode);\r
+ newNode.before(prefixNode);\r
+ newNode.after(suffixNode);\r
+ mediator.nodeCreated(newNode);\r
+ isDirty = true;\r
+ }\r
+ },\r
getMetaData: function() {\r
var toret = {};\r
this.metaTable.find('tr').each(function() {\r