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