Skip to content

add id to location href w/o hashes when setting clip paths urls #1203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ')');
};
17 changes: 17 additions & 0 deletions test/jasmine/tests/drawing_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,21 @@ describe('Drawing.setClipUrl', function() {

base.remove();
});

it('should append window URL w/o hash to clip-path if <base> 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 = '';
});
});
2 changes: 1 addition & 1 deletion test/jasmine/tests/plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down