jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/requirehtml.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-12-14 08:43:03 -07:00
define(function () {
2015-12-26 11:35:53 -07:00
var importedFiles = [];
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
return {
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
load: function (cssId, req, load, config) {
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
// Somehow if the url starts with /html, require will get all screwed up since this extension is also called html
cssId = cssId.replace('js/requirehtml', 'html');
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
var url = cssId + '.html';
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
if (url.indexOf('http') != 0 && url.indexOf('file:') != 0) {
url = config.baseUrl + url;
}
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
if (importedFiles.indexOf(url) == -1) {
importedFiles.push(url);
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
var link = document.createElement('link');
link.rel = 'import';
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
if (url.toLowerCase().indexOf('bower_') == -1) {
url = url + "?" + config.urlArgs;
}
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
link.onload = load;
link.href = url;
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
document.head.appendChild(link);
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
return;
}
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
load();
},
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
normalize: function (name, normalize) {
if (name.substr(name.length - 5, 5) == '.html')
name = name.substr(0, name.length - 5);
2015-12-14 08:43:03 -07:00
2015-12-26 11:35:53 -07:00
return normalize(name);
}
};
2015-12-14 08:43:03 -07:00
});