vue-material/src/core/components/mdTheme/dom.js
Matthew Pietz a6678ab620 Refactor Theme Engine (#646)
- Optimize parseStyle method to run a single RegExp replace
- Abstract DOM manipulation to check for VUE_ENV first
- Add theme name to <md-theme> element when it would render its own tag
- Recompute styles when a new set of selectors is added (via styles.push)
- Use computed property to find closest themed ancestor for mixin
- Only grab md-name attribute from an md-theme component (<md-table-edit>
  uses the md-name attribute for <input> tags)
2017-05-07 19:46:49 -03:00

38 lines
1 KiB
JavaScript

export var changeHtmlMetaColor;
export var createNewStyleElement;
if (process.env.VUE_ENV !== 'server') {
changeHtmlMetaColor = (color, themeClass, previousClass) => {
var elem = document.querySelector('meta[name="theme-color"]');
if (elem) {
elem.setAttribute('content', color);
} else {
elem = document.createElement('meta');
elem.setAttribute('name', 'theme-color');
elem.setAttribute('content', color);
document.head.appendChild(elem);
}
document.body.classList.remove(previousClass);
document.body.classList.add(themeClass);
};
createNewStyleElement = (style, styleId) => {
const head = document.head;
const styleElement = head.querySelector('#' + styleId);
if (!styleElement) {
const newTag = document.createElement('style');
newTag.type = 'text/css';
newTag.id = styleId;
newTag.textContent = style;
head.appendChild(newTag);
} else {
styleElement.textContent = style;
}
};
}