Skip to content

Commit 18a836d

Browse files
authored
Merge pull request #1203 from plotly/clip-path-hash
add id to location href w/o hashes when setting clip paths urls
2 parents 4d243a9 + 3cc1253 commit 18a836d

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/components/drawing/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,10 @@ drawing.setClipUrl = function(s, localId) {
568568
var url = '#' + localId,
569569
base = d3.select('base');
570570

571-
if(base.size() && base.attr('href')) url = window.location.href + url;
571+
// add id to location href w/o hashes if any)
572+
if(base.size() && base.attr('href')) {
573+
url = window.location.href.split('#')[0] + url;
574+
}
575+
572576
s.attr('clip-path', 'url(' + url + ')');
573577
};

test/jasmine/tests/drawing_test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,21 @@ describe('Drawing.setClipUrl', function() {
4949

5050
base.remove();
5151
});
52+
53+
it('should append window URL w/o hash to clip-path if <base> is present', function() {
54+
var base = d3.select('body')
55+
.append('base')
56+
.attr('href', 'https://plot.ly/#hash');
57+
58+
window.location.hash = 'hash';
59+
60+
Drawing.setClipUrl(this.g, 'id4');
61+
62+
var expected = 'url(' + window.location.href.split('#')[0] + '#id4)';
63+
64+
expect(this.g.attr('clip-path')).toEqual(expected);
65+
66+
base.remove();
67+
window.location.hash = '';
68+
});
5269
});

test/jasmine/tests/plot_interact_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ describe('plot svg clip paths', function() {
657657
.attr('href', 'https://plot.ly');
658658

659659
// grab window URL
660-
var href = window.location.href;
660+
var href = window.location.href.split('#')[0];
661661

662662
plot().then(function() {
663663

0 commit comments

Comments
 (0)