From 6716b9fbdc2ca11b058b3cf3700f5751b1cfb431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 28 Nov 2016 13:34:33 -0500 Subject: [PATCH 1/2] add id to location href w/o hashes when setting clip paths urls --- src/components/drawing/index.js | 6 +++++- test/jasmine/tests/drawing_test.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/components/drawing/index.js b/src/components/drawing/index.js index eab586463fc..9aa4af4bc36 100644 --- a/src/components/drawing/index.js +++ b/src/components/drawing/index.js @@ -568,6 +568,10 @@ drawing.setClipUrl = function(s, localId) { var url = '#' + localId, base = d3.select('base'); - if(base.size() && base.attr('href')) url = window.location.href + url; + // add id to location href w/o hashes if any) + if(base.size() && base.attr('href')) { + url = window.location.href.split('#')[0] + url; + } + s.attr('clip-path', 'url(' + url + ')'); }; diff --git a/test/jasmine/tests/drawing_test.js b/test/jasmine/tests/drawing_test.js index 0394715de5e..7930007a72b 100644 --- a/test/jasmine/tests/drawing_test.js +++ b/test/jasmine/tests/drawing_test.js @@ -49,4 +49,21 @@ describe('Drawing.setClipUrl', function() { base.remove(); }); + + it('should append window URL w/o hash to clip-path if is present', function() { + var base = d3.select('body') + .append('base') + .attr('href', 'https://plot.ly/#hash'); + + window.location.hash = 'hash'; + + Drawing.setClipUrl(this.g, 'id4'); + + var expected = 'url(' + window.location.href.split('#')[0] + '#id4)'; + + expect(this.g.attr('clip-path')).toEqual(expected); + + base.remove(); + window.location.hash = ''; + }); }); From 3cc12539755101213d9acc103322f6174cd3fe6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 28 Nov 2016 14:25:36 -0500 Subject: [PATCH 2/2] test: adapt test for (possible) trailing url hashes --- test/jasmine/tests/plot_interact_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jasmine/tests/plot_interact_test.js b/test/jasmine/tests/plot_interact_test.js index 34032945d7c..d6a0efda994 100644 --- a/test/jasmine/tests/plot_interact_test.js +++ b/test/jasmine/tests/plot_interact_test.js @@ -657,7 +657,7 @@ describe('plot svg clip paths', function() { .attr('href', 'https://plot.ly'); // grab window URL - var href = window.location.href; + var href = window.location.href.split('#')[0]; plot().then(function() {