c47b8bb4cc6444cf1b6263d5e2017007c2bfa8c0
[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(_.contains(['tag', 'class'], attr)) {
33                     manager.getNodeElement(manager.currentNode).attr('wlxml-'+attr, value);
34                 } else {
35                     // changing node meta attr
36                     manager.currentNode.setMetaAttr(attr, value);
37                 }
38                 sandbox.publish('contentChanged');
39             }
40         },
41         highlightNode: function(canvasNode) {
42             manager.highlightNode(canvasNode);
43         },
44         dimNode: function(canvasNode) {
45             manager.dimNode(canvasNode);
46         },
47         selectNode: function(canvasNode) {
48             if(!canvasNode.isSame(manager.currentNode))
49                 manager.selectNode(canvasNode, {movecaret: true});
50         },
51         toggleGrid: function(toggle) {
52             manager.toggleGrid(toggle);
53         },
54         insertNewNode: function(wlxmlTag, wlxmlClass) {
55             manager.insertNewNode(wlxmlTag, wlxmlClass);
56         },
57         command: function(command, meta) {
58             manager.command(command, meta);
59         }
60     };
61     
62 };
63
64 });