2015-01-15 01:01:52 +00:00
|
|
|
/*global define*/
|
|
|
|
|
|
|
|
define(
|
2015-01-15 01:23:18 +00:00
|
|
|
[],
|
|
|
|
function () {
|
2015-01-15 01:01:52 +00:00
|
|
|
"use strict";
|
|
|
|
|
2015-01-15 01:23:18 +00:00
|
|
|
/**
|
|
|
|
* The StyleSheetLoader adds links to style sheets exposed from
|
|
|
|
* various bundles as extensions of category `stylesheets`.
|
|
|
|
* @constructor
|
|
|
|
* @param {object[]} stylesheets stylesheet extension definitions
|
|
|
|
* @param $document Angular's jqLite-wrapped document element
|
|
|
|
*/
|
2015-01-15 01:01:52 +00:00
|
|
|
function StyleSheetLoader(stylesheets, $document) {
|
2015-01-15 01:23:18 +00:00
|
|
|
var head = $document.find('head'),
|
|
|
|
document = $document[0];
|
2015-01-15 01:01:52 +00:00
|
|
|
|
2015-01-15 01:23:18 +00:00
|
|
|
// Procedure for adding a single stylesheet
|
2015-01-15 01:01:52 +00:00
|
|
|
function addStyleSheet(stylesheet) {
|
2015-01-15 01:23:18 +00:00
|
|
|
// Create a link element, and construct full path
|
|
|
|
var link = document.createElement('link'),
|
2015-01-15 01:01:52 +00:00
|
|
|
path = [
|
|
|
|
stylesheet.bundle.path,
|
|
|
|
stylesheet.bundle.resources,
|
|
|
|
stylesheet.stylesheetUrl
|
|
|
|
].join("/");
|
|
|
|
|
2015-01-15 01:23:18 +00:00
|
|
|
// Initialize attributes on the link
|
|
|
|
link.setAttribute("rel", "stylesheet");
|
|
|
|
link.setAttribute("type", "text/css");
|
|
|
|
link.setAttribute("href", path);
|
2015-01-15 01:01:52 +00:00
|
|
|
|
2015-01-15 01:23:18 +00:00
|
|
|
// Append the link to the head element
|
2015-01-15 01:01:52 +00:00
|
|
|
head.append(link);
|
|
|
|
}
|
|
|
|
|
2015-01-15 01:23:18 +00:00
|
|
|
// Add all stylesheets from extensions
|
2015-01-15 01:01:52 +00:00
|
|
|
stylesheets.forEach(addStyleSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
return StyleSheetLoader;
|
|
|
|
}
|
|
|
|
);
|