summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-12-07 15:51:58 +0200
committerAlon Levy <alon@pobox.com>2014-12-07 15:51:58 +0200
commitbfc6e8df881b2a7f9fa610e691d329f6ebdad7ca (patch)
tree12deaf1ada1a7d6966222bf964c1966b9bafb2cc
parentb7e6b948b6ae1cc2f3cbf9523a4b6eab6e7993fe (diff)
measure: don't do the crazy computed css copy. use minus height trick. Fixes #194
-rw-r--r--index.html3
-rw-r--r--src/rz_core.js30
2 files changed, 16 insertions, 17 deletions
diff --git a/index.html b/index.html
index a97f7d4c..b1fd37ca 100644
--- a/index.html
+++ b/index.html
@@ -11,7 +11,8 @@
</head>
<body>
-
+ <span id="measure-node" class="graph nodetext" style="position: absolute; display: inline; top: -300px; left: 0px;">suicide squade, attack!</span>
+ <span id="measure-link" class="graph linklabel" style="position: absolute; display: inline; top: -300px; left: 0px;">those who are about to cry, we kaput you.</span>
<div class="top-bar">
<h3 class="doc-title">Server test</h3>
<div class="user-area">
diff --git a/src/rz_core.js b/src/rz_core.js
index ad6755b3..39440385 100644
--- a/src/rz_core.js
+++ b/src/rz_core.js
@@ -30,15 +30,8 @@ var node_text_dx = 15,
* edit_link(@sibling, @link)
*/
var svgInput = (function() {
- var measure_span;
-
- function createMeasureSpan(parent) {
- measure_span = document.createElement('span');
- measure_span.setAttribute('id', 'measure');
- measure_span.style.display = 'inline';
- measure_span.style.visibility = 'hidden';
- parent.appendChild(measure_span);
- }
+ var measure_node = $('#measure-node')[0],
+ measure_link = $('#measure-link')[0];
function appendForeignElementInputWithID(base, elemid, width, height)
{
@@ -55,16 +48,21 @@ var svgInput = (function() {
fo.appendChild(body);
base.appendChild(fo);
input.setAttribute('id', elemid);
- createMeasureSpan(body);
return input;
}
- function measure(e, text)
+ function measure(e_raw, text)
{
- measure_span.style.cssText = window.getComputedStyle(e).cssText;
- measure_span.style.visibility = 'none';
- measure_span.innerHTML = text;
- return measure_span.getBoundingClientRect().width; // $().width() works too
+ var span,
+ e = $(e_raw);
+
+ if (e.attr('class').indexOf('nodetext') == -1) {
+ span = measure_link;
+ } else {
+ span = measure_node;
+ }
+ span.innerHTML = text;
+ return span.getBoundingClientRect().width; // $().width() works too
}
function onkeydown(e) {
@@ -98,7 +96,7 @@ var svgInput = (function() {
};
function resize_measure(e) {
- resize(measure(e.target, $(e.target).val()) + 30);
+ resize(measure(e.target.parentNode.parentNode.parentNode.querySelector('text'), $(e.target).val()) + 30);
}
function resize(new_width) {