- 1 :
/**
- 2 :
* @file stylesheet.js
- 3 :
* @module stylesheet
- 4 :
*/
- 5 :
import document from 'global/document';
- 6 :
- 7 :
/**
- 8 :
* Create a DOM style element given a className for it.
- 9 :
*
- 10 :
* @param {string} className
- 11 :
* The className to add to the created style element.
- 12 :
*
- 13 :
* @return {Element}
- 14 :
* The element that was created.
- 15 :
*/
- 16 :
export const createStyleElement = function(className) {
- 17 :
const style = document.createElement('style');
- 18 :
- 19 :
style.className = className;
- 20 :
- 21 :
return style;
- 22 :
};
- 23 :
- 24 :
/**
- 25 :
* Add text to a DOM element.
- 26 :
*
- 27 :
* @param {Element} el
- 28 :
* The Element to add text content to.
- 29 :
*
- 30 :
* @param {string} content
- 31 :
* The text to add to the element.
- 32 :
*/
- 33 :
export const setTextContent = function(el, content) {
- 34 :
if (el.styleSheet) {
- 35 :
el.styleSheet.cssText = content;
- 36 :
} else {
- 37 :
el.textContent = content;
- 38 :
}
- 39 :
};