X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/f7c97ef38dc00ec9b5358ae0bf959a5e6f99271c..d67ed5177c7b434beb026aab16a91333e295a914:/modules/documentCanvas/documentCanvas.js diff --git a/modules/documentCanvas/documentCanvas.js b/modules/documentCanvas/documentCanvas.js index a4dcf37..7500e35 100644 --- a/modules/documentCanvas/documentCanvas.js +++ b/modules/documentCanvas/documentCanvas.js @@ -1,59 +1,72 @@ -// Module that implements main WYSIWIG edit area - -define([ -'libs/underscore-min', -'./transformations', -'./canvas', -'./canvasManager', -'libs/text!./template.html'], function(_, transformations, Canvas, CanvasManager, template) { - -'use strict'; - -return function(sandbox) { - - var canvas = Canvas.create(); - var manager = new CanvasManager(canvas, sandbox); - - /* public api */ - return { - start: function() { sandbox.publish('ready'); }, - getView: function() { - return canvas.dom; - }, - setDocument: function(xml) { - canvas.setHTML(transformations.fromXML.getHTMLTree(xml)); - sandbox.publish('documentSet'); - }, - getDocument: function() { - return canvas.toXML(); - }, - modifyCurrentNode: function(attr, value) { - if(manager.currentNode) { - manager.getNodeElement(manager.currentNode).attr('wlxml-'+attr, value); - sandbox.publish('contentChanged'); - } - }, - highlightNode: function(canvasNode) { - manager.highlightNode(canvasNode); - }, - dimNode: function(canvasNode) { - manager.dimNode(canvasNode); - }, - selectNode: function(canvasNode) { - if(!canvasNode.isSame(manager.currentNode)) - manager.selectNode(canvasNode, {movecaret: true}); - }, - toggleGrid: function(toggle) { - manager.toggleGrid(toggle); - }, - insertNewNode: function(wlxmlTag, wlxmlClass) { - manager.insertNewNode(wlxmlTag, wlxmlClass); - }, - command: function(command, meta) { - manager.command(command, meta); - } - } - -}; - +// Module that implements main WYSIWIG edit area + +define([ +'libs/underscore-min', +'./transformations', +'./canvas', +'./canvasManager', +'./canvas/canvas', +'libs/text!./template.html'], function(_, transformations, Canvas, CanvasManager, canvas3, template) { + +'use strict'; + +return function(sandbox) { + + var canvas = canvas3.fromXML(''); //canvasCanvas.create(); + var manager; + var canvasWrapper = $(template); + + /* public api */ + return { + start: function() { sandbox.publish('ready'); }, + getView: function() { + return canvasWrapper; + }, + setDocument: function(xml) { + canvas.loadWlxml(xml); //canvas.setHTML(transformations.fromXML.getHTMLTree(xml)); + canvasWrapper.find('#rng-module-documentCanvas-content').empty().append(canvas.doc().dom()); + manager = new CanvasManager(canvas, sandbox); + sandbox.publish('documentSet'); + }, + getDocument: function() { + return transformations.toXML.getXML(canvas.getContent()); + }, + modifyCurrentNode: function(attr, value) { + if(manager.currentNode) { + if(attr === 'tag') { + manager.getNodeElement(manager.currentNode).attr('wlxml-'+attr, value); + } + else if(attr === 'class') { + manager.currentNode.setClass(value); + } else { + // changing node meta attr + manager.currentNode.setMetaAttr(attr, value); + } + sandbox.publish('contentChanged'); + sandbox.publish('currentNodeChanged', manager.currentNode); + } + }, + highlightNode: function(canvasNode) { + manager.highlightNode(canvasNode); + }, + dimNode: function(canvasNode) { + manager.dimNode(canvasNode); + }, + selectNode: function(canvasNode) { + if(!canvasNode.isSame(manager.currentNode)) + manager.selectNode(canvasNode, {movecaret: true}); + }, + toggleGrid: function(toggle) { + manager.toggleGrid(toggle); + }, + insertNewNode: function(wlxmlTag, wlxmlClass) { + manager.insertNewNode(wlxmlTag, wlxmlClass); + }, + command: function(command, meta) { + manager.command(command, meta); + } + }; + +}; + }); \ No newline at end of file