Skip to content

Commit

Permalink
Fix style matching in Firefox 67
Browse files Browse the repository at this point in the history
(Ported from PR google/blockly#2485, which is by @NeilFraser.
 Description from that PR follows:)

Chrome returns ‘transform: translate(107px, 0px);’ whereas Firefox now
returns ‘transform: translate(107px);’ if the y value is 0.  This is
consistent with existing behaviour in the translate SVG attribute.

The comment in our code specifically states:
// Accounts for same exceptions as XY_REGEX_
Yet that was not true at all.

This PR makes the y argument optional (as falsely described in the
comment).  It also merges the 2D and 3D regeps together to simplify the
code.
  • Loading branch information
towerofnix committed May 24, 2019
1 parent d9e7bb7 commit 9b3d0e5
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,7 @@ Blockly.utils.getRelativeXY = function(element) {
// Then check for style = transform: translate(...) or translate3d(...)
var style = element.getAttribute('style');
if (style && style.indexOf('translate') > -1) {
var styleComponents = style.match(Blockly.utils.getRelativeXY.XY_2D_REGEX_);
// Try transform3d if 2d transform wasn't there.
if (!styleComponents) {
styleComponents = style.match(Blockly.utils.getRelativeXY.XY_3D_REGEX_);
}
var styleComponents = style.match(Blockly.utils.getRelativeXY.XY_STYLE_REGEX_);
if (styleComponents) {
xy.x += parseFloat(styleComponents[1]);
if (styleComponents[3]) {
Expand Down Expand Up @@ -251,7 +247,7 @@ Blockly.utils.getScale_ = function(element) {
* @private
*/
Blockly.utils.getRelativeXY.XY_REGEX_ =
/translate\(\s*([-+\d.e]+)([ ,]\s*([-+\d.e]+)\s*\))?/;
/translate\(\s*([-+\d.e]+)([ ,]\s*([-+\d.e]+)\s*)?/;


/**
Expand All @@ -263,22 +259,14 @@ Blockly.utils.getRelativeXY.XY_REGEX_ =
Blockly.utils.getScale_REGEXP_ = /scale\(\s*([-+\d.e]+)\s*\)/;

/**
* Static regex to pull the x,y,z values out of a translate3d() style property.
* Accounts for same exceptions as XY_REGEXP_.
* @type {!RegExp}
* @private
*/
Blockly.utils.getRelativeXY.XY_3D_REGEX_ =
/transform:\s*translate3d\(\s*([-+\d.e]+)px([ ,]\s*([-+\d.e]+)\s*)px([ ,]\s*([-+\d.e]+)\s*)px\)?/;

/**
* Static regex to pull the x,y,z values out of a translate3d() style property.
* Static regex to pull the x,y values out of a translate3d() or translate3d()
* style property.
* Accounts for same exceptions as XY_REGEXP_.
* @type {!RegExp}
* @private
*/
Blockly.utils.getRelativeXY.XY_2D_REGEX_ =
/transform:\s*translate\(\s*([-+\d.e]+)px([ ,]\s*([-+\d.e]+)\s*)px\)?/;
Blockly.utils.getRelativeXY.XY_STYLE_REGEX_ =
/transform:\s*translate(?:3d)?\(\s*([-+\d.e]+)\s*px([ ,]\s*([-+\d.e]+)\s*px)?/;

/**
* Helper method for creating SVG elements.
Expand Down

0 comments on commit 9b3d0e5

Please sign in to comment.