From 3716b1a3b9ab0daca701792e64be7bb1698bab09 Mon Sep 17 00:00:00 2001 From: Ezequiel Bergamaschi Date: Wed, 21 May 2014 23:51:51 -0300 Subject: [PATCH] text editor with position done --- .../main/javascript/MultilineTextEditor.js | 21 ++++++++----------- mindplot/src/main/javascript/TextEditor.js | 19 ++++++++--------- web2d/src/main/javascript/Element.js | 4 ++++ .../src/main/javascript/peer/svg/TextPeer.js | 4 ++++ 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/mindplot/src/main/javascript/MultilineTextEditor.js b/mindplot/src/main/javascript/MultilineTextEditor.js index 1fa65df6..4e5133b7 100644 --- a/mindplot/src/main/javascript/MultilineTextEditor.js +++ b/mindplot/src/main/javascript/MultilineTextEditor.js @@ -182,30 +182,27 @@ mindplot.MultilineTextEditor = new Class({ font.size = nodeText.getHtmlFontSize(); font.color = nodeText.getColor(); this._setStyle(font); - + var me = this; // Set editor's initial size var displayFunc = function () { // Position the editor and set the size... var textShape = topic.getTextShape(); - $('#textContainer').position({ - my: "left top", - at: "left bottom", - of: $(textShape)[0] -// collision: "fit" - }); + me._containerElem.css('display', 'block'); - this._containerElem.css('display', 'block'); + //FIXME: Im not sure if this is best way... + var shapePosition = textShape.getNativePosition(); + me._containerElem.offset(shapePosition); // Set editor's initial text ... var text = $defined(defaultText) ? defaultText : topic.getText(); - this._setText(text); + me._setText(text); // Set the element focus and select the current text ... - var inputElem = this._getTextareaElem(); - this._positionCursor(inputElem, !$defined(defaultText)); + var inputElem = me._getTextareaElem(); + me._positionCursor(inputElem, !$defined(defaultText)); - }.bind(this); + }; this._timeoutId = displayFunc.delay(10); }, diff --git a/mindplot/src/main/javascript/TextEditor.js b/mindplot/src/main/javascript/TextEditor.js index 2c4ef9e6..d41a3504 100644 --- a/mindplot/src/main/javascript/TextEditor.js +++ b/mindplot/src/main/javascript/TextEditor.js @@ -147,25 +147,24 @@ mindplot.TextEditor = new Class({ var text = $defined(defaultText) ? defaultText : topic.getText(); this._setText(text); + var me = this; // Set editor's initial size var displayFunc = function() { // Position the editor and set the size... - var textShape = this._topic.getTextShape(); - textShape.positionRelativeTo(this._containerElem, { - position: {x: 'left',y:'top'}, - edge: {x: 'left', y: 'top'} - }); - this._containerElem.setStyle('display', 'block'); + var textShape = me._topic.getTextShape(); + me._containerElem.css('display', 'block'); + + me._containerElem.offset(textShape.getNativePosition()); // Set size ... var elemSize = topic.getSize(); - this._setEditorSize(elemSize.width, elemSize.height); + me._setEditorSize(elemSize.width, elemSize.height); - var textareaElem = this._getTextareaElem(); + var textareaElem = me._getTextareaElem(); textareaElem.focus(); - this._positionCursor(textareaElem, !$defined(defaultText)); + me._positionCursor(textareaElem, !$defined(defaultText)); - }.bind(this); + }; displayFunc.delay(10); }, diff --git a/web2d/src/main/javascript/Element.js b/web2d/src/main/javascript/Element.js index f567d472..fc36910d 100644 --- a/web2d/src/main/javascript/Element.js +++ b/web2d/src/main/javascript/Element.js @@ -137,6 +137,10 @@ web2d.Element = new Class({ return this._peer.getPosition(); }, + getNativePosition: function() { + return this._peer.getNativePosition(); + }, + /* * Defines the element stroke properties. * width: stroke width diff --git a/web2d/src/main/javascript/peer/svg/TextPeer.js b/web2d/src/main/javascript/peer/svg/TextPeer.js index 684c3454..0cbafe68 100644 --- a/web2d/src/main/javascript/peer/svg/TextPeer.js +++ b/web2d/src/main/javascript/peer/svg/TextPeer.js @@ -76,6 +76,10 @@ web2d.peer.svg.TextPeer = new Class({ return this._position; }, + getNativePosition: function() { + return $(this._native).position(); + }, + setFont: function (font, size, style, weight) { if ($defined(font)) { this._font = new web2d.Font(font, this);