X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/a421b30397eaa30b23a389cc9018ad29bf987a28..30363302f46e0ed1f6a4c214b2e04d7c8e12ae73:/src/editor/modules/documentCanvas/canvas/canvas.js diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index ed24cee..48f03de 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -33,6 +33,7 @@ $.extend(Canvas.prototype, { this.setupEventHandling(); this.wlxmlListener.listenTo(wlxmlDocument); + this.wlxmlDocument = wlxmlDocument; }, generateCanvasDOM: function(wlxmlNode) { @@ -64,8 +65,10 @@ $.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); + var textElement = canvas.getDocumentElement(mutation.target), + toSet = mutation.target.data !== utils.unicode.ZWS ? mutation.target.data : ''; + + textElement.data('wlxmlNode').setText(toSet); } }); }); @@ -109,6 +112,11 @@ $.extend(Canvas.prototype, { 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); }, @@ -229,6 +237,10 @@ $.extend(Canvas.prototype, { 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; @@ -267,7 +279,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(); }