From 687d7c2c73574998febf0f5be9ccbff7ad0009ab Mon Sep 17 00:00:00 2001 From: Niels van Hoorn Date: Fri, 7 Jul 2017 17:05:06 +0200 Subject: [PATCH] Fixed bug where measuring element was created before the dom is ready --- framer/TextLayer.coffee | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/framer/TextLayer.coffee b/framer/TextLayer.coffee index 0e3ee56f4..045e6a588 100644 --- a/framer/TextLayer.coffee +++ b/framer/TextLayer.coffee @@ -11,14 +11,14 @@ _measureElement = null getMeasureElement = (constraints={}) -> - if not _measureElement + shouldCreateElement = not _measureElement + if shouldCreateElement _measureElement = document.createElement("div") _measureElement.id = "_measureElement" _measureElement.style.position = "fixed" _measureElement.style.visibility = "hidden" _measureElement.style.top = "-10000px" _measureElement.style.left = "-10000px" - window.document.body.appendChild(_measureElement) while _measureElement.hasChildNodes() _measureElement.removeChild(_measureElement.lastChild) @@ -30,6 +30,13 @@ getMeasureElement = (constraints={}) -> else _measureElement.style.width = "#{constraints.width}px" if constraints.width _measureElement.style.height = "#{constraints.height}px" if constraints.height + + # This is a trick to call this function before the document ready event + if not window.document.body + document.write(_measureElement.outerHTML) + _textSizeNode = document.getElementById("_measureElement") + else + window.document.body.appendChild(_measureElement) return _measureElement class InlineStyle