X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/4bd7ae43a9d3cd78105f174d1f92c1bc92d35f02..bc034b92ca42b68512daa81ae3306d0d351af04c:/src/editor/modules/documentCanvas/canvas/canvas.js?ds=sidebyside diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index 482afb9..830db75 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -4,44 +4,39 @@ define([ 'libs/backbone', 'modules/documentCanvas/canvas/documentElement', 'modules/documentCanvas/canvas/keyboard', -'modules/documentCanvas/canvas/utils' -], function($, _, Backbone, documentElement, keyboard, utils) { +'modules/documentCanvas/canvas/utils', +'modules/documentCanvas/canvas/wlxmlListener' +], function($, _, Backbone, documentElement, keyboard, utils, wlxmlListener) { 'use strict'; -var Canvas = function(wlxml, publisher) { +var Canvas = function(wlxmlDocument, publisher) { this.eventBus = _.extend({}, Backbone.Events); - this.loadWlxmlDocument(wlxml); + this.wrapper = $('
').addClass('canvas-wrapper').attr('contenteditable', true); + this.wlxmlListener = wlxmlListener.create(this); + this.loadWlxmlDocument(wlxmlDocument); this.publisher = publisher ? publisher : function() {}; }; $.extend(Canvas.prototype, { loadWlxmlDocument: function(wlxmlDocument) { + if(!wlxmlDocument) { + return false; + } + var canvasDOM = this.generateCanvasDOM(wlxmlDocument.root); - this.wrapper = $('
').addClass('canvas-wrapper').attr('contenteditable', true); + this.wrapper.empty(); this.wrapper.append(canvasDOM); this.d = this.wrapper.children(0); this.setupEventHandling(); + + this.wlxmlListener.listenTo(wlxmlDocument); }, generateCanvasDOM: function(wlxmlNode) { - // var element = this.createNodeElement2({ - // tag: wlxmlNode.getTagName(), - // klass: wlxmlNode.getClass(), //currentTag.attr('class'), - // meta: wlxmlNode.getMetaAttributes(), //meta, - // others: wlxmlNode.getOtherAttributes(), // ~ //others, - // rawChildren: wlxmlNode.contents(), - // prepopulateOnEmpty: true - // }); //->create2 - var element = documentElement.DocumentNodeElement.create(wlxmlNode, this); - - - ['orig-before', 'orig-after', 'orig-begin', 'orig-end'].forEach(function(attr) { - element.data(attr, ''); - }); return element.dom(); }, @@ -277,7 +272,7 @@ $.extend(Canvas.prototype, { if(!(currentNodeElement && currentNodeElement.sameNode(nodeElementToLand))) { _markAsCurrent(nodeElementToLand); - this.publisher('currentNodeElementSet', nodeElementToLand); + this.publisher('currentNodeElementSet', nodeElementToLand.data('wlxmlNode')); } }, @@ -550,8 +545,8 @@ $.extend(Cursor.prototype, { }) return { - fromXML: function(wlxmlNode, publisher) { - return new Canvas(wlxmlNode, publisher); + fromXMLDocument: function(wlxmlDocument, publisher) { + return new Canvas(wlxmlDocument, publisher); } };