define([\r
'libs/jquery-1.9.1.min',\r
-'./wlxmlNode'\r
-], function($, wlxmlNode) {\r
+'./canvasNode'\r
+], function($, canvasNode) {\r
\r
'use strict';\r
\r
\r
canvas.dom.on('mouseover', '[wlxml-tag]', function(e) {\r
e.stopPropagation();\r
- manager.sandbox.publish('nodeHovered', new wlxmlNode.Node($(e.target)));\r
+ manager.sandbox.publish('nodeHovered', canvasNode.create($(e.target)));\r
});\r
canvas.dom.on('mouseout', '[wlxml-tag]', function(e) {\r
e.stopPropagation();\r
- manager.sandbox.publish('nodeBlured', new wlxmlNode.Node($(e.target)));\r
+ manager.sandbox.publish('nodeBlured', canvasNode.create($(e.target)));\r
});\r
canvas.dom.on('click', '[wlxml-tag]', function(e) {\r
e.stopPropagation();\r
console.log('clicked node type: '+e.target.nodeType);\r
- manager.selectNode(new wlxmlNode.Node($(e.target)));\r
+ manager.selectNode(canvasNode.create($(e.target)));\r
});\r
\r
canvas.dom.on('keyup', '#rng-module-documentCanvas-contentWrapper', function(e) {\r
anchor = anchor.parent();\r
if(!anchor.is('[wlxml-tag]'))\r
return;\r
- manager.selectNode(new wlxmlNode.Node(anchor));\r
+ manager.selectNode(canvasNode.create(anchor));\r
});\r
\r
canvas.dom.on('keydown', '#rng-module-documentCanvas-contentWrapper', function(e) {\r
}\r
};\r
\r
-Manager.prototype.selectNode = function(wlxmlNode, options) {\r
+Manager.prototype.selectNode = function(cnode, options) {\r
options = options || {};\r
- var nodeElement = this.getNodeElement(wlxmlNode)\r
+ var nodeElement = this.getNodeElement(cnode)\r
\r
- this.dimNode(wlxmlNode);\r
+ this.dimNode(cnode);\r
\r
this.canvas.dom.find('.rng-module-documentCanvas-currentNode').removeClass('rng-module-documentCanvas-currentNode');\r
nodeElement.addClass('rng-module-documentCanvas-currentNode');\r
this.movecaretToNode(nodeElement, options.movecaret);\r
}\r
\r
- this.currentNode = wlxmlNode;\r
- this.sandbox.publish('nodeSelected', wlxmlNode);\r
+ this.currentNode = cnode;\r
+ this.sandbox.publish('nodeSelected', cnode);\r
};\r
\r
-Manager.prototype.getNodeElement = function(wlxmlNode) {\r
- return this.canvas.dom.find('#'+wlxmlNode.id);\r
+Manager.prototype.insertNewNode = function(wlxmlTag, wlxmlClass) {\r
+ var selection = window.getSelection();\r
+\r
+ if(selection.getRangeAt(0).collapsed) {\r
+ \r
+ } else {\r
+ var offsetStart = selection.anchorOffset;\r
+ var offsetEnd = selection.focusOffset;\r
+ if(offsetStart > offsetEnd) {\r
+ var tmp = offsetStart;\r
+ offsetStart = offsetEnd;\r
+ offsetEnd = tmp;\r
+ }\r
+ var wrapper = canvasNode.create({tag: wlxmlTag, klass: wlxmlClass});\r
+ this.canvas.nodeWrap({inside: canvasNode.create($(selection.anchorNode).parent()),\r
+ _with: wrapper,\r
+ offsetStart: offsetStart,\r
+ offsetEnd: offsetEnd\r
+ });\r
+ this.selectNode(wrapper, {movecaret: 'end'});\r
+ }\r
+ \r
+ \r
+}\r
+\r
+Manager.prototype.getNodeElement = function(cnode) {\r
+ return this.canvas.dom.find('#'+cnode.getId());\r
};\r
\r
-Manager.prototype.highlightNode = function(wlxmlNode) {\r
- var nodeElement = this.getNodeElement(wlxmlNode);\r
+Manager.prototype.highlightNode = function(cnode) {\r
+ var nodeElement = this.getNodeElement(cnode);\r
if(!this.gridToggled) {\r
nodeElement.addClass('rng-common-hoveredNode');\r
var label = nodeElement.attr('wlxml-tag');\r
}\r
};\r
\r
-Manager.prototype.dimNode = function(wlxmlNode) {\r
- var nodeElement = this.getNodeElement(wlxmlNode);\r
+Manager.prototype.dimNode = function(cnode) {\r
+ var nodeElement = this.getNodeElement(cnode);\r
if(!this.gridToggled) {\r
nodeElement.removeClass('rng-common-hoveredNode');\r
nodeElement.find('.rng-module-documentCanvas-hoveredNodeTag').remove();\r
else {\r
node = this.canvas.dom.find('[wlxml-class|="p"]')\r
}\r
- this.selectNode(new wlxmlNode.Node(node), {movecaret: true});\r
+ this.selectNode(canvasNode.create(node), {movecaret: true});\r
};\r
\r
Manager.prototype.movecaretToNode = function(nodeElement, where) {\r
+ if(!nodeElement.length)\r
+ return;\r
var range = document.createRange();\r
range.selectNodeContents(nodeElement[0]);\r
\r
Manager.prototype.onEnterKey = function(e) {\r
e.preventDefault();\r
var pos = getCursorPosition();\r
- var insertedNode;\r
+ var contextNode = this.canvas.getNodeById(pos.parentNode.attr('id'));\r
+ var newNode;\r
+\r
if(pos.isAtEnd) {\r
- insertedNode = this.canvas.insertNode({place: 'after', context: {id: pos.parentNode.attr('id')}, tag: pos.parentNode.attr('wlxml-tag'), klass: pos.parentNode.attr('wlxml-class')});\r
+ newNode = canvasNode.create({tag: pos.parentNode.attr('wlxml-tag'), klass: pos.parentNode.attr('wlxml-class')});\r
+ this.canvas.nodeInsertAfter({node: newNode, after: this.canvas.getNodeById(pos.parentNode.attr('id'))});\r
} else {\r
- insertedNode = this.canvas.splitNode({node: {id: pos.parentNode.attr('id')}, textNodeIdx: pos.textNodeIndex, offset: pos.textNodeOffset});\r
+ newNode = this.canvas.nodeSplit({node: contextNode, textNodeIdx: pos.textNodeIndex, offset: pos.textNodeOffset});\r
}\r
- if(insertedNode.length)\r
- this.selectNode(new wlxmlNode.Node(insertedNode), {movecaret: true});\r
+ if(newNode)\r
+ this.selectNode(newNode, {movecaret: true});\r
this.sandbox.publish('contentChanged');\r
};\r
\r
}\r
if(len === 0) {\r
e.preventDefault();\r
- var toRemove = new wlxmlNode.Node(pos.textNode);\r
- var prevNode = this.canvas.getPreviousNode({node:toRemove});\r
- this.canvas.removeNode({node: toRemove}); // jesli nie ma tekstu, to anchor nie jest tex nodem\r
+ var toRemove = canvasNode.create(pos.textNode);\r
+ var prevNode = this.canvas.getPrecedingNode({node:toRemove});\r
+ this.canvas.nodeRemove({node: toRemove}); // jesli nie ma tekstu, to anchor nie jest tex nodem\r
this.selectNode(prevNode, {movecaret: 'end'});\r
}\r
}\r
var pos = getCursorPosition();\r
\r
if(command === 'createList') {\r
- var node = new wlxmlNode.Node(pos.parentNode);\r
- if(window.getSelection().getRangeAt().collapsed && this.canvas.insideList({pointer: node})) {\r
- this.canvas.removeList({pointer: node});\r
+ var node = canvasNode.create(pos.parentNode);\r
+ if(window.getSelection().getRangeAt(0).collapsed && this.canvas.nodeInsideList({node: node})) {\r
+ this.canvas.listRemove({pointer: node});\r
this.selectNode(node, {movecaret: 'end'});\r
this.sandbox.publish('contentChanged');\r
}\r
else {\r
- if(!this.canvas.insideList({pointer: node})) {\r
- this.canvas.createList({start: new wlxmlNode.Node(pos.parentNode), end: new wlxmlNode.Node(pos.focusNode)});\r
- this.selectNode(new wlxmlNode.Node(pos.parentNode), {movecaret: 'end'});\r
+ //if(!this.canvas.nodeInsideList({node: node})) {\r
+ this.canvas.listCreate({start: node, end: canvasNode.create(pos.focusNode), type: meta});\r
+ this.selectNode(node, {movecaret: 'end'});\r
this.sandbox.publish('contentChanged');\r
- }\r
+ //}\r
}\r
}\r
\r