X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/e64e37a2fbe6d64b2513133d34370f0d1a63f7b9..8254ff82e19d41b2a66a4549165b924084ed6a52:/modules/documentCanvas/documentCanvas.js diff --git a/modules/documentCanvas/documentCanvas.js b/modules/documentCanvas/documentCanvas.js index cc4964b..7500e35 100644 --- a/modules/documentCanvas/documentCanvas.js +++ b/modules/documentCanvas/documentCanvas.js @@ -1,63 +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); - }, - 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