-
Notifications
You must be signed in to change notification settings - Fork 11
/
docs-load-css.js
31 lines (30 loc) · 1.28 KB
/
docs-load-css.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// We need to dynamically load on demand the CSS because when the doc opens examples in Plunkr, it doesn't copy the
// external files over.
jQuery(document).ready(function() {
var styles = jQuery(document).find('link[rel="stylesheet"]');
var loaded = false;
styles.each(function() {
var url = this.href;
var file = url.split('/')[url.split('/').length-1];
if (file === 'ods-widgets.css' || file === 'ods-widgets.min.css') {
loaded = true;
return;
}
});
if (!loaded) {
// Assume it is in the same place as ods-widgets.js
var scripts = jQuery(document).find('script');
scripts.each(function() {
var url = this.src;
var file = url.split('/')[url.split('/').length-1];
if (file === 'ods-widgets.js' || file === 'ods-widgets.min.js') {
var root = url.substring(0, url.length - file.length);
if (root.endsWith('/grunt-scripts/')) {
// In the doc builds, the styles are not in the same folder
root = root.replace(/\/grunt-scripts\/$/, '/css/');
}
jQuery('head').append('<link rel="stylesheet" href="' + root + 'ods-widgets.min.css"></link>');
}
});
}
});