'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(wlxmlDocument, publisher) {
this.eventBus = _.extend({}, Backbone.Events);
this.wrapper = $('<div>').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) {
- wlxmlDocument = wlxmlDocument || this.wlxmlDocument;
if(!wlxmlDocument) {
return false;
}
+
var canvasDOM = this.generateCanvasDOM(wlxmlDocument.root);
this.wrapper.empty();
this.d = this.wrapper.children(0);
this.setupEventHandling();
- var canvas = this;
-
- if(this.wlxmlDocument !== wlxmlDocument) {
- wlxmlDocument.on('change', function(event) {
- var canvasNode = utils.findCanvasElement(event.meta.node);
- if(event.type === 'nodeAttrChange' && event.meta.attr === 'class') {
- canvasNode.setWlxmlClass(event.meta.newVal);
- }
-
- });
- }
- this.wlxmlDocument = wlxmlDocument;
+ this.wlxmlListener.listenTo(wlxmlDocument);
},
generateCanvasDOM: function(wlxmlNode) {
}
observer.observe(canvas.d[0], config);
canvas.publisher('contentChanged');
+
+ var textElement = canvas.getDocumentElement(mutation.target);
+ textElement.data('wlxmlNode').setText(mutation.target.data);
}
});
});
if(params.caretTo || !textElementToLand.sameNode(this.getCursor().getPosition().element))
this._moveCaretToTextElement(textElementToLand, params.caretTo); // as method on element?
if(!(textElementToLand.sameNode(currentTextElement)))
- this.publisher('currentTextElementSet', textElementToLand);
+ this.publisher('currentTextElementSet', textElementToLand.data('wlxmlNode'));
} else {
document.getSelection().removeAllRanges();
}