Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

web-loaders.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. 'use strict';
  2. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  3. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  4. var Loader = require('./loader');
  5. var _require = require('./precompiled-loader.js'),
  6. PrecompiledLoader = _require.PrecompiledLoader;
  7. var WebLoader = /*#__PURE__*/function (_Loader) {
  8. _inheritsLoose(WebLoader, _Loader);
  9. function WebLoader(baseURL, opts) {
  10. var _this;
  11. _this = _Loader.call(this) || this;
  12. _this.baseURL = baseURL || '.';
  13. opts = opts || {}; // By default, the cache is turned off because there's no way
  14. // to "watch" templates over HTTP, so they are re-downloaded
  15. // and compiled each time. (Remember, PRECOMPILE YOUR
  16. // TEMPLATES in production!)
  17. _this.useCache = !!opts.useCache; // We default `async` to false so that the simple synchronous
  18. // API can be used when you aren't doing anything async in
  19. // your templates (which is most of the time). This performs a
  20. // sync ajax request, but that's ok because it should *only*
  21. // happen in development. PRECOMPILE YOUR TEMPLATES.
  22. _this.async = !!opts.async;
  23. return _this;
  24. }
  25. var _proto = WebLoader.prototype;
  26. _proto.resolve = function resolve(from, to) {
  27. throw new Error('relative templates not support in the browser yet');
  28. };
  29. _proto.getSource = function getSource(name, cb) {
  30. var _this2 = this;
  31. var useCache = this.useCache;
  32. var result;
  33. this.fetch(this.baseURL + '/' + name, function (err, src) {
  34. if (err) {
  35. if (cb) {
  36. cb(err.content);
  37. } else if (err.status === 404) {
  38. result = null;
  39. } else {
  40. throw err.content;
  41. }
  42. } else {
  43. result = {
  44. src: src,
  45. path: name,
  46. noCache: !useCache
  47. };
  48. _this2.emit('load', name, result);
  49. if (cb) {
  50. cb(null, result);
  51. }
  52. }
  53. }); // if this WebLoader isn't running asynchronously, the
  54. // fetch above would actually run sync and we'll have a
  55. // result here
  56. return result;
  57. };
  58. _proto.fetch = function fetch(url, cb) {
  59. // Only in the browser please
  60. if (typeof window === 'undefined') {
  61. throw new Error('WebLoader can only by used in a browser');
  62. }
  63. var ajax = new XMLHttpRequest();
  64. var loading = true;
  65. ajax.onreadystatechange = function () {
  66. if (ajax.readyState === 4 && loading) {
  67. loading = false;
  68. if (ajax.status === 0 || ajax.status === 200) {
  69. cb(null, ajax.responseText);
  70. } else {
  71. cb({
  72. status: ajax.status,
  73. content: ajax.responseText
  74. });
  75. }
  76. }
  77. };
  78. url += (url.indexOf('?') === -1 ? '?' : '&') + 's=' + new Date().getTime();
  79. ajax.open('GET', url, this.async);
  80. ajax.send();
  81. };
  82. return WebLoader;
  83. }(Loader);
  84. module.exports = {
  85. WebLoader: WebLoader,
  86. PrecompiledLoader: PrecompiledLoader
  87. };