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

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-12-14 08:43:03 -07:00
define(function () {
2016-10-17 22:06:48 -07:00
'use strict';
2015-12-14 08:43:03 -07:00
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
2016-10-17 22:06:48 -07:00
if (url.indexOf('://') === -1) {
2015-12-26 11:35:53 -07:00
url = config.baseUrl + url;
}
2015-12-14 08:43:03 -07:00
2016-10-17 22:06:48 -07:00
if (importedFiles.indexOf(url) === -1) {
2015-12-26 11:35:53 -07:00
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
2016-07-07 14:31:40 -07:00
if (config.urlArgs) {
2016-10-17 22:06:48 -07:00
if (url.toLowerCase().indexOf('bower_') === -1 || url.toLowerCase().indexOf('emby-webcomponents') !== -1) {
2016-07-07 14:31:40 -07:00
url = url + config.urlArgs(cssId, url);
}
2015-12-26 11:35:53 -07:00
}
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) {
2016-10-17 22:06:48 -07:00
if (name.substr(name.length - 5, 5) === '.html') {
2015-12-26 11:35:53 -07:00
name = name.substr(0, name.length - 5);
2016-10-17 22:06:48 -07:00
}
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
});