Wrapping in node text with subnodes
[fnpeditor.git] / modules / documentCanvas / documentCanvas.js
1 // Module that implements main WYSIWIG edit area\r
2 \r
3 define([\r
4 'libs/underscore-min',\r
5 './transformations', \r
6 './canvas',\r
7 './canvasManager',\r
8 'libs/text!./template.html'], function(_, transformations, Canvas, CanvasManager, template) {\r
9 \r
10 'use strict';\r
11 \r
12 return function(sandbox) {\r
13 \r
14     var canvas = Canvas.create();\r
15     var manager = new CanvasManager(canvas, sandbox);\r
16 \r
17     /* public api */\r
18     return {\r
19         start: function() { sandbox.publish('ready'); },\r
20         getView: function() { \r
21             return canvas.dom;\r
22         },\r
23         setDocument: function(xml) {\r
24             canvas.setHTML(transformations.fromXML.getHTMLTree(xml));\r
25             sandbox.publish('documentSet');\r
26         },\r
27         getDocument: function() {\r
28             return transformations.toXML.getXML(canvas.getContent())\r
29         },\r
30         modifyCurrentNode: function(attr, value) {\r
31             if(manager.currentNode) {\r
32                 manager.getNodeElement(manager.currentNode).attr('wlxml-'+attr, value);\r
33                 sandbox.publish('contentChanged');\r
34             }\r
35         },\r
36         highlightNode: function(canvasNode) {\r
37             manager.highlightNode(canvasNode);\r
38         },\r
39         dimNode: function(canvasNode) {\r
40             manager.dimNode(canvasNode);\r
41         },\r
42         selectNode: function(canvasNode) {\r
43             if(!canvasNode.isSame(manager.currentNode))\r
44                 manager.selectNode(canvasNode, {movecaret: true});\r
45         },\r
46         toggleGrid: function(toggle) {\r
47             manager.toggleGrid(toggle);\r
48         },\r
49         insertNewNode: function(wlxmlTag, wlxmlClass) {\r
50             manager.insertNewNode(wlxmlTag, wlxmlClass);\r
51         },\r
52         command: function(command, meta) {\r
53             manager.command(command, meta);\r
54         }\r
55     }\r
56     \r
57 };\r
58 \r
59 });