-}\r
-\r
-Canvas.prototype.getPreviousNode = function(options) {\r
- var element = $(this.content.find('#' + options.node.id).get(0));\r
- var prev = element.prev()\r
- if(prev.length === 0)\r
- prev = element.parent();\r
- return new wlxmlNode.Node(prev);\r
-}\r
-\r
-Canvas.prototype._createNode = function(wlxmlTag, wlxmlClass) {\r
- var toBlock = ['div', 'document', 'section', 'header'];\r
- var htmlTag = _.contains(toBlock, wlxmlTag) ? 'div' : 'span';\r
- var toret = $('<' + htmlTag + '>');\r
- toret.attr('wlxml-tag', wlxmlTag);\r
- if(wlxmlClass)\r
- toret.attr('wlxml-class', wlxmlClass);\r
- toret.attr('id', 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}));\r
- return toret;\r
- };\r
-\r
-Canvas.prototype.insertNode = function(options) {\r
- var element = $(this.content.find('#' + options.context.id).get(0));\r
- if(options.place == 'after') {\r
- var node = this._createNode(options.tag, options.klass);\r
- element[options.place](node);\r
- return node;\r
- }\r
- else if(options.place == 'wrapText') {\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
- var newNode = this._createNode(options.tag, options.klass);\r
- newNode.text(core);\r
- $(textElement).replaceWith(newNode);\r
- newNode.before(prefix);\r
- newNode.after(suffix);\r
- return newNode;\r