hackmd-styles.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * GROWI styles loader for HackMD
  3. *
  4. * This file will be transpiled as a single JS
  5. * and should be load from HackMD head via 'lib/routes/hackmd.js' route
  6. *
  7. * USAGE:
  8. * <script src="${hostname of GROWI}/_hackmd/load-styles"></script>
  9. *
  10. * @author Yuki Takei <yuki@weseek.co.jp>
  11. */
  12. /* eslint-disable no-console */
  13. const styles = '{{styles}}'; // will be replaced by swig
  14. /**
  15. * Insert link tag to load style file
  16. */
  17. function insertStyle() {
  18. const element = document.createElement('style');
  19. element.type = 'text/css';
  20. element.appendChild(document.createTextNode(styles));
  21. document.getElementsByTagName('head')[0].appendChild(element);
  22. }
  23. /**
  24. * main
  25. */
  26. (function() {
  27. // check HackMD is in iframe
  28. if (window === window.parent) {
  29. console.log('[GROWI] Loading styles for HackMD is not processed because currently not in iframe');
  30. return;
  31. }
  32. console.log('[HackMD] Loading GROWI styles for HackMD...');
  33. insertStyle();
  34. console.log('[HackMD] GROWI styles for HackMD has successfully loaded.');
  35. }());