mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
* start custom theming adf * demo shell cleaning * login mdl cleaning * uploader mdl cleaning * prebuilt themes * theme picker in demo shell * clean custom colors and mdl * fix rebase errors * theming from color style guide * dev default theme orange purple * fix color accent inverted in picker * fix test and add colors classes * fix tag component theming issues * fix datatable theming * add theming guides
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import {Injectable} from '@angular/core';
|
|
|
|
/**
|
|
* Class for managing stylesheets. Stylesheets are loaded into named slots so that they can be
|
|
* removed or changed later.
|
|
*/
|
|
@Injectable()
|
|
export class StyleManager {
|
|
/**
|
|
* Set the stylesheet with the specified key.
|
|
*/
|
|
setStyle(key: string, href: string) {
|
|
getLinkElementForKey(key).setAttribute('href', href);
|
|
}
|
|
|
|
/**
|
|
* Remove the stylesheet with the specified key.
|
|
*/
|
|
removeStyle(key: string) {
|
|
const existingLinkElement = getExistingLinkElementByKey(key);
|
|
if (existingLinkElement) {
|
|
document.head.removeChild(existingLinkElement);
|
|
}
|
|
}
|
|
}
|
|
|
|
function getLinkElementForKey(key: string) {
|
|
return getExistingLinkElementByKey(key) || createLinkElementWithKey(key);
|
|
}
|
|
|
|
function getExistingLinkElementByKey(key: string) {
|
|
return document.head.querySelector(`link[rel="stylesheet"].${getClassNameForKey(key)}`);
|
|
}
|
|
|
|
function createLinkElementWithKey(key: string) {
|
|
const linkEl = document.createElement('link');
|
|
linkEl.setAttribute('rel', 'stylesheet');
|
|
linkEl.classList.add(getClassNameForKey(key));
|
|
document.head.appendChild(linkEl);
|
|
return linkEl;
|
|
}
|
|
|
|
function getClassNameForKey(key: string) {
|
|
return `style-manager-${key}`;
|
|
}
|