jshintrc tweak - allowing multistrings
[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                 manager.getNodeElement(manager.currentNode).attr('wlxml-'+attr, value);
33                 sandbox.publish('contentChanged');
34             }
35         },
36         highlightNode: function(canvasNode) {
37             manager.highlightNode(canvasNode);
38         },
39         dimNode: function(canvasNode) {
40             manager.dimNode(canvasNode);
41         },
42         selectNode: function(canvasNode) {
43             if(!canvasNode.isSame(manager.currentNode))
44                 manager.selectNode(canvasNode, {movecaret: true});
45         },
46         toggleGrid: function(toggle) {
47             manager.toggleGrid(toggle);
48         },
49         insertNewNode: function(wlxmlTag, wlxmlClass) {
50             manager.insertNewNode(wlxmlTag, wlxmlClass);
51         },
52         command: function(command, meta) {
53             manager.command(command, meta);
54         }
55     };
56     
57 };
58
59 });