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