From f81a5bd11ae64a4fade4db94fa3c0b175eae7263 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 26 Aug 2015 14:08:03 +0100 Subject: [PATCH] Expand regex to handle IE's scientific notation. --- core/utils.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/core/utils.js b/core/utils.js index 4f1bdfb63..bc59cfc2b 100644 --- a/core/utils.js +++ b/core/utils.js @@ -266,12 +266,7 @@ Blockly.getRelativeXY_ = function(element) { } // Second, check for transform="translate(...)" attribute. var transform = element.getAttribute('transform'); - // Note that Firefox and IE (9,10) return 'translate(12)' instead of - // 'translate(12, 0)'. - // Note that IE (9,10) returns 'translate(16 8)' instead of - // 'translate(16, 8)'. - var r = transform && - transform.match(/translate\(\s*([-\d.]+)([ ,]\s*([-\d.]+)\s*\))?/); + var r = transform && transform.match(Blockly.getRelativeXY_.XY_REGEXP_); if (r) { xy.x += parseFloat(r[1]); if (r[3]) { @@ -281,6 +276,18 @@ Blockly.getRelativeXY_ = function(element) { return xy; }; +/** + * Static regex to pull the x,y values out of an SVG translate() directive. + * Note that Firefox and IE (9,10) return 'translate(12)' instead of + * 'translate(12, 0)'. + * Note that IE (9,10) returns 'translate(16 8)' instead of 'translate(16, 8)'. + * Note that IE has been reported to return scientific notation (0.123456e-42). + * @type {!RegExp} + * @private + */ +Blockly.getRelativeXY_.XY_REGEXP_ = + /translate\(\s*([-+\d.e]+)([ ,]\s*([-+\d.e]+)\s*\))?/; + /** * Return the absolute coordinates of the top-left corner of this element, * scales that after canvas SVG element, if it's a descendant.