+/* global document:false, window:false, Node:false, gettext */
+
+var logger = logging.getLogger('canvas');
+
+var TextHandler = function(canvas) {this.canvas = canvas; this.buffer = null;};
+$.extend(TextHandler.prototype, {
+ handle: function(node, text) {
+ this.setText(text, node);
+ // return;
+ // if(!this.node) {
+ // this.node = node;
+ // }
+ // if(this.node.sameNode(node)) {
+ // this._ping(text);
+ // } else {
+ // this.flush();
+ // this.node = node;
+ // this._ping(text);
+ // }
+ },
+ _ping: _.throttle(function(text) {
+ this.buffer = text;
+ this.flush();
+ }, 1000),
+ flush: function() {
+ if(this.buffer !== null) {
+ this.setText(this.buffer, this.node);
+ this.buffer = null;
+ }
+ },
+ setText: function(text, node) {
+ //this.canvas.wlxmlDocument.transform('setText', {node:node, text: text});
+ node.document.transaction(function() {
+ node.setText(text);
+ }, {
+ metadata:{
+ description: gettext('Changing text')
+ }
+ });
+
+ }
+
+});
+
+var ElementsRegister = function() {
+ this._register = {
+ '': ElementsRegister.createCanvasElementType(genericElement, documentElement.DocumentNodeElement)
+ };
+
+}
+_.extend(ElementsRegister, {
+ createCanvasElementType: function(elementPrototype, inheritFrom) {
+ var Constructor = function() {
+ if(!this.super) {
+ this.super = inheritFrom.prototype;
+ }
+ inheritFrom.apply(this, Array.prototype.slice.call(arguments, 0));
+
+ };
+ Constructor.prototype = Object.create(inheritFrom.prototype);
+ _.extend(Constructor.prototype, elementPrototype);
+ return Constructor;
+ }
+});
+_.extend(ElementsRegister.prototype, {
+ register: function(klass, elementPrototype) {
+ this._register[klass] = ElementsRegister.createCanvasElementType(elementPrototype, this.getFactoryFor(''));
+ },
+ getFactoryFor: function(klass) {
+ var Factory;
+ wlxml.getClassHierarchy(klass).reverse().some(function(klass) {
+ Factory = this._register[klass];
+ if(Factory) {
+ return true;
+ }
+ }.bind(this));
+ return Factory;
+ }
+});
+