X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/a3b1c058b5c4453838cb896aa3b8c3a803949ffb..1726f584bb8ff2770506aae2e77fe27fbfd5ab98:/src/editor/modules/documentCanvas/canvas/canvas.js?ds=inline
diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js
index 8c2e2e1..3a662e9 100644
--- a/src/editor/modules/documentCanvas/canvas/canvas.js
+++ b/src/editor/modules/documentCanvas/canvas/canvas.js
@@ -4,13 +4,16 @@ 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(wlxmlDocument, publisher) {
this.eventBus = _.extend({}, Backbone.Events);
+ this.wrapper = $('
').addClass('canvas-wrapper').attr('contenteditable', true);
+ this.wlxmlListener = wlxmlListener.create(this);
this.loadWlxmlDocument(wlxmlDocument);
this.publisher = publisher ? publisher : function() {};
};
@@ -21,30 +24,20 @@ $.extend(Canvas.prototype, {
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);
+ this.wlxmlDocument = 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();
},
@@ -71,6 +64,9 @@ $.extend(Canvas.prototype, {
}
observer.observe(canvas.d[0], config);
canvas.publisher('contentChanged');
+
+ var textElement = canvas.getDocumentElement(mutation.target);
+ textElement.data('wlxmlNode').setText(mutation.target.data);
}
});
});
@@ -272,7 +268,7 @@ $.extend(Canvas.prototype, {
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();
}
@@ -280,7 +276,7 @@ $.extend(Canvas.prototype, {
if(!(currentNodeElement && currentNodeElement.sameNode(nodeElementToLand))) {
_markAsCurrent(nodeElementToLand);
- this.publisher('currentNodeElementSet', nodeElementToLand);
+ this.publisher('currentNodeElementSet', nodeElementToLand.data('wlxmlNode'));
}
},