bootstrap.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * Kicks off less and compiles any stylesheets
  3. * used in the browser distributed version of less
  4. * to kick-start less using the browser api
  5. */
  6. /*global window, document */
  7. // shim Promise if required
  8. require('promise/polyfill.js');
  9. var options = window.less || {};
  10. require("./add-default-options")(window, options);
  11. var less = module.exports = require("./index")(window, options);
  12. window.less = less;
  13. var css, head, style;
  14. // Always restore page visibility
  15. function resolveOrReject(data) {
  16. if (data.filename) {
  17. console.warn(data);
  18. }
  19. if (!options.async) {
  20. head.removeChild(style);
  21. }
  22. }
  23. if (options.onReady) {
  24. if (/!watch/.test(window.location.hash)) {
  25. less.watch();
  26. }
  27. // Simulate synchronous stylesheet loading by blocking page rendering
  28. if (!options.async) {
  29. css = 'body { display: none !important }';
  30. head = document.head || document.getElementsByTagName('head')[0];
  31. style = document.createElement('style');
  32. style.type = 'text/css';
  33. if (style.styleSheet) {
  34. style.styleSheet.cssText = css;
  35. } else {
  36. style.appendChild(document.createTextNode(css));
  37. }
  38. head.appendChild(style);
  39. }
  40. less.registerStylesheetsImmediately();
  41. less.pageLoadFinished = less.refresh(less.env === 'development').then(resolveOrReject, resolveOrReject);
  42. }