X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/9eb5d6423cea01acb7589519480465394882ab7c..1dcfdcafd9fd0ff3af5dc39619a3a953f4377a11:/modules/documentCanvas/documentCanvas.js?ds=sidebyside diff --git a/modules/documentCanvas/documentCanvas.js b/modules/documentCanvas/documentCanvas.js index fb67c0d..7500e35 100644 --- a/modules/documentCanvas/documentCanvas.js +++ b/modules/documentCanvas/documentCanvas.js @@ -1,60 +1,72 @@ -// Module that implements main WYSIWIG edit area - -define([ -'libs/underscore-min', -'./transformations', -'./wlxmlNode', -'./canvas', -'./canvasManager', -'libs/text!./template.html'], function(_, transformations, wlxmlNode, Canvas, CanvasManager, template) { - -'use strict'; - -return function(sandbox) { - - var canvas = new Canvas.Canvas(); - var manager = new CanvasManager(canvas, sandbox); - - /* public api */ - return { - start: function() { sandbox.publish('ready'); }, - getView: function() { - return canvas.dom; - }, - setDocument: function(xml) { - canvas.setXML(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(wlxmlNode) { - manager.highlightNode(wlxmlNode); - }, - dimNode: function(wlxmlNode) { - manager.dimNode(wlxmlNode); - }, - selectNode: function(wlxmlNode) { - if(!wlxmlNode.is(manager.currentNode)) - manager.selectNode(wlxmlNode, {movecaret: true}); - }, - toggleGrid: function(toggle) { - manager.toggleGrid(toggle); - }, - insertNewNode: function(wlxmlTag, wlxmlClass) { - manager.insertNewNode(wlxmlTag, wlxmlClass); - }, - wrapSelectionWithNewNode: function(wlxmlTag, wlxmlClass) { - manager.wrapSelectionWithNewNode(wlxmlTag, wlxmlClass); - } - } - -}; - +// 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