Merge remote-tracking branch 'github-open/open241' into open-master
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
"runs": [
|
||||
{
|
||||
"implementation": "StyleSheetLoader.js",
|
||||
"depends": [ "stylesheets[]", "$document" ]
|
||||
"depends": [ "stylesheets[]", "$document", "THEME" ]
|
||||
}
|
||||
],
|
||||
"stylesheets": [
|
||||
@@ -194,6 +194,11 @@
|
||||
{
|
||||
"key": "MCT_SCROLL_Y_ATTRIBUTE",
|
||||
"value": "mctScrollY"
|
||||
},
|
||||
{
|
||||
"key": "THEME",
|
||||
"value": "unspecified",
|
||||
"priority": "fallback"
|
||||
}
|
||||
],
|
||||
"containers": [
|
||||
|
||||
@@ -38,8 +38,9 @@ define(
|
||||
* @constructor
|
||||
* @param {object[]} stylesheets stylesheet extension definitions
|
||||
* @param $document Angular's jqLite-wrapped document element
|
||||
* @param {string} activeTheme the theme in use
|
||||
*/
|
||||
function StyleSheetLoader(stylesheets, $document) {
|
||||
function StyleSheetLoader(stylesheets, $document, activeTheme) {
|
||||
var head = $document.find('head'),
|
||||
document = $document[0];
|
||||
|
||||
@@ -62,8 +63,15 @@ define(
|
||||
head.append(link);
|
||||
}
|
||||
|
||||
// Stylesheets which specify themes should only be applied
|
||||
// when that theme has been declared.
|
||||
function matchesTheme(stylesheet) {
|
||||
return stylesheet.theme === undefined ||
|
||||
stylesheet.theme === activeTheme;
|
||||
}
|
||||
|
||||
// Add all stylesheets from extensions
|
||||
stylesheets.forEach(addStyleSheet);
|
||||
stylesheets.filter(matchesTheme).forEach(addStyleSheet);
|
||||
}
|
||||
|
||||
return StyleSheetLoader;
|
||||
|
||||
@@ -32,10 +32,11 @@ define(
|
||||
mockPlainDocument,
|
||||
mockHead,
|
||||
mockElement,
|
||||
testBundle,
|
||||
loader;
|
||||
|
||||
beforeEach(function () {
|
||||
var testBundle = {
|
||||
testBundle = {
|
||||
path: "a/b",
|
||||
resources: "c"
|
||||
};
|
||||
@@ -72,6 +73,40 @@ define(
|
||||
expect(mockElement.setAttribute)
|
||||
.toHaveBeenCalledWith('href', "a/b/c/d.css");
|
||||
});
|
||||
|
||||
describe("for themed stylesheets", function () {
|
||||
var testTheme = "test-theme";
|
||||
|
||||
beforeEach(function () {
|
||||
testStyleSheets = [{
|
||||
stylesheetUrl: "themed.css",
|
||||
bundle: testBundle,
|
||||
theme: testTheme
|
||||
}, {
|
||||
stylesheetUrl: "bad-theme.css",
|
||||
bundle: testBundle,
|
||||
theme: 'bad-theme'
|
||||
}];
|
||||
|
||||
loader = new StyleSheetLoader(
|
||||
testStyleSheets,
|
||||
mockDocument,
|
||||
testTheme
|
||||
);
|
||||
});
|
||||
|
||||
it("includes matching themes", function () {
|
||||
expect(mockElement.setAttribute)
|
||||
.toHaveBeenCalledWith('href', "a/b/c/themed.css");
|
||||
});
|
||||
|
||||
it("excludes mismatching themes", function () {
|
||||
expect(mockElement.setAttribute)
|
||||
.not.toHaveBeenCalledWith('href', "a/b/c/bad-theme.css");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user