From d9c91d958dfa9d25b422e36b3a9a151aba8bb81e Mon Sep 17 00:00:00 2001 From: Lee Howett Date: Thu, 31 May 2018 12:23:20 -0700 Subject: [PATCH] Randomized id for svg filters --- core/block_render_svg_horizontal.js | 4 +++- core/block_render_svg_vertical.js | 8 ++++++-- core/block_svg.js | 3 ++- core/inject.js | 6 ++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/core/block_render_svg_horizontal.js b/core/block_render_svg_horizontal.js index a74dea0b66..103112ee20 100644 --- a/core/block_render_svg_horizontal.js +++ b/core/block_render_svg_horizontal.js @@ -335,7 +335,9 @@ Blockly.BlockSvg.prototype.updateColour = function() { */ Blockly.BlockSvg.prototype.highlightForReplacement = function(add) { if (add) { - this.svgPath_.setAttribute('filter', 'url(#blocklyReplacementGlowFilter)'); + var replacementGlowFilterId = this.workspace.options.replacementGlowFilterId + || 'blocklyReplacementGlowFilter'; + this.svgPath_.setAttribute('filter', 'url(#' + replacementGlowFilterId + ')'); Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_), 'blocklyReplaceable'); } else { diff --git a/core/block_render_svg_vertical.js b/core/block_render_svg_vertical.js index 6a638114f0..c9bcc4bbff 100644 --- a/core/block_render_svg_vertical.js +++ b/core/block_render_svg_vertical.js @@ -560,7 +560,9 @@ Blockly.BlockSvg.prototype.updateColour = function() { */ Blockly.BlockSvg.prototype.highlightForReplacement = function(add) { if (add) { - this.svgPath_.setAttribute('filter', 'url(#blocklyReplacementGlowFilter)'); + var replacementGlowFilterId = this.workspace.options.replacementGlowFilterId + || 'blocklyReplacementGlowFilter'; + this.svgPath_.setAttribute('filter', 'url(#' + replacementGlowFilterId + ')'); Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_), 'blocklyReplaceable'); } else { @@ -585,8 +587,10 @@ Blockly.BlockSvg.prototype.highlightShapeForInput = function(conn, add) { return; } if (add) { + var replacementGlowFilterId = this.workspace.options.replacementGlowFilterId + || 'blocklyReplacementGlowFilter'; input.outlinePath.setAttribute('filter', - 'url(#blocklyReplacementGlowFilter)'); + 'url(#' + replacementGlowFilterId + ')'); Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_), 'blocklyReplaceable'); } else { diff --git a/core/block_svg.js b/core/block_svg.js index c12e1447cd..c8fb32601d 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -231,7 +231,8 @@ Blockly.BlockSvg.prototype.setGlowStack = function(isGlowingStack) { // Update the applied SVG filter if the property has changed var svg = this.getSvgRoot(); if (this.isGlowingStack_ && !svg.hasAttribute('filter')) { - svg.setAttribute('filter', 'url(#blocklyStackGlowFilter)'); + var stackGlowFilterId = this.workspace.options.stackGlowFilterId || 'blocklyStackGlowFilter'; + svg.setAttribute('filter', 'url(#' + stackGlowFilterId + ')'); } else if (!this.isGlowingStack_ && svg.hasAttribute('filter')) { svg.removeAttribute('filter'); } diff --git a/core/inject.js b/core/inject.js index bcc08c4ee5..bb1390c3d0 100644 --- a/core/inject.js +++ b/core/inject.js @@ -132,7 +132,7 @@ Blockly.createDom_ = function(container, options) { // Instead use a gaussian blur, and then set all alpha to 1 with a transfer. var stackGlowFilter = Blockly.utils.createSvgElement('filter', { - 'id': 'blocklyStackGlowFilter', + 'id': 'blocklyStackGlowFilter' + rnd, 'height': '160%', 'width': '180%', y: '-30%', @@ -180,7 +180,7 @@ Blockly.createDom_ = function(container, options) { // Filter for replacement marker var replacementGlowFilter = Blockly.utils.createSvgElement('filter', { - 'id': 'blocklyReplacementGlowFilter', + 'id': 'blocklyReplacementGlowFilter' + rnd, 'height': '160%', 'width': '180%', y: '-30%', @@ -253,6 +253,8 @@ Blockly.createDom_ = function(container, options) { 'stroke': '#cc0' }, disabledPattern); + options.stackGlowFilterId = stackGlowFilter.id; + options.replacementGlowFilterId = replacementGlowFilter.id; options.disabledPatternId = disabledPattern.id; options.gridPattern = Blockly.Grid.createDom(rnd, options.gridOptions, defs);