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 = ''; + }); }); 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() {