Skip to content
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

Fix for broken clip mask in Safari when a base path is set #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ var defaultOptions = {
maskNames: {
aboveThreshold: 'ct-threshold-mask-above',
belowThreshold: 'ct-threshold-mask-below'
}
},
basePath: ""
};
```

## Fix for Safari with `<base href="/" />`

In Safari if `<base href="/" />` is set, the clip mask won't work. To fix this
set the `basePath` in options to the absolute path.
7 changes: 4 additions & 3 deletions dist/chartist-plugin-threshold.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
maskNames: {
aboveThreshold: 'ct-threshold-mask-above',
belowThreshold: 'ct-threshold-mask-below'
}
},
basePath: ''
};

function createMasks(data, options) {
Expand Down Expand Up @@ -100,15 +101,15 @@
.parent()
.elem(data.element._node.cloneNode(true))
.attr({
mask: 'url(#' + options.maskNames.aboveThreshold + ')'
mask: 'url(' + options.basePath + '#' + options.maskNames.aboveThreshold + ')'
})
.addClass(options.classNames.aboveThreshold);

// Use the original line path, mask it with the lower mask rect below the threshold and add the class
// for blow threshold
data.element
.attr({
mask: 'url(#' + options.maskNames.belowThreshold + ')'
mask: 'url(' + options.basePath + '#' + options.maskNames.belowThreshold + ')'
})
.addClass(options.classNames.belowThreshold);
}
Expand Down
6 changes: 3 additions & 3 deletions dist/chartist-plugin-threshold.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/chartist-plugin-threshold.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/scripts/chartist-plugin-threshold.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
maskNames: {
aboveThreshold: 'ct-threshold-mask-above',
belowThreshold: 'ct-threshold-mask-below'
}
},
basePath: ''
};

function createMasks(data, options) {
Expand Down Expand Up @@ -84,15 +85,15 @@
.parent()
.elem(data.element._node.cloneNode(true))
.attr({
mask: 'url(#' + options.maskNames.aboveThreshold + ')'
mask: 'url(' + options.basePath + '#' + options.maskNames.aboveThreshold + ')'
})
.addClass(options.classNames.aboveThreshold);

// Use the original line path, mask it with the lower mask rect below the threshold and add the class
// for blow threshold
data.element
.attr({
mask: 'url(#' + options.maskNames.belowThreshold + ')'
mask: 'url(' + options.basePath + '#' + options.maskNames.belowThreshold + ')'
})
.addClass(options.classNames.belowThreshold);
}
Expand Down