integration wip: highlight/dim/select node via family tree
[fnpeditor.git] / src / editor / modules / documentCanvas / canvas / canvas.js
index 97ad592..b0d461b 100644 (file)
@@ -13,9 +13,9 @@ define([
 var Canvas = function(wlxmlDocument, publisher) {
     this.eventBus = _.extend({}, Backbone.Events);
     this.wrapper = $('<div>').addClass('canvas-wrapper').attr('contenteditable', true);
 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() {};
     this.loadWlxmlDocument(wlxmlDocument);
     this.publisher = publisher ? publisher : function() {};
-    this.wlxmlListener = wlxmlListener.create(this);
 };
 
 $.extend(Canvas.prototype, {
 };
 
 $.extend(Canvas.prototype, {
@@ -33,6 +33,7 @@ $.extend(Canvas.prototype, {
         this.setupEventHandling();
 
         this.wlxmlListener.listenTo(wlxmlDocument);
         this.setupEventHandling();
 
         this.wlxmlListener.listenTo(wlxmlDocument);
+        this.wlxmlDocument = wlxmlDocument;
     },
 
     generateCanvasDOM: function(wlxmlNode) {
     },
 
     generateCanvasDOM: function(wlxmlNode) {
@@ -63,6 +64,9 @@ $.extend(Canvas.prototype, {
                     }
                     observer.observe(canvas.d[0], config);
                     canvas.publisher('contentChanged');
                     }
                     observer.observe(canvas.d[0], config);
                     canvas.publisher('contentChanged');
+
+                    var textElement = canvas.getDocumentElement(mutation.target);
+                    textElement.data('wlxmlNode').setText(mutation.target.data);
                 }
             });
         });
                 }
             });
         });
@@ -106,6 +110,11 @@ $.extend(Canvas.prototype, {
         return documentElement.DocumentNodeElement.fromHTMLElement(this.d.get(0), this); //{wlxmlTag: this.d.prop('tagName')};
     },
 
         return documentElement.DocumentNodeElement.fromHTMLElement(this.d.get(0), this); //{wlxmlTag: this.d.prop('tagName')};
     },
 
+    toggleElementHighlight: function(node, toggle) {
+        var element = utils.findCanvasElement(node);
+        element.toggleHighlight(toggle);
+    },
+
     createNodeElement: function(params) {
         return documentElement.DocumentNodeElement.create(params, this);
     },
     createNodeElement: function(params) {
         return documentElement.DocumentNodeElement.create(params, this);
     },
@@ -226,6 +235,10 @@ $.extend(Canvas.prototype, {
 
 
     setCurrentElement: function(element, params) {
 
 
     setCurrentElement: function(element, params) {
+        if(!(element instanceof documentElement.DocumentElement)) {
+            element = utils.findCanvasElement(element);
+        }
+
         params = _.extend({caretTo: 'end'}, params);
         var findFirstDirectTextChild = function(e, nodeToLand) {
             var byBrowser = this.getCursor().getPosition().element;
         params = _.extend({caretTo: 'end'}, params);
         var findFirstDirectTextChild = function(e, nodeToLand) {
             var byBrowser = this.getCursor().getPosition().element;
@@ -264,7 +277,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)))
             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();
         }
         } else {
             document.getSelection().removeAllRanges();
         }