1
0

helpers.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. define(["./boot", "./junk-drawer", "require"], function (boot, $goodies, require) {
  2. var globals = boot.globals,
  3. exports = {},
  4. extend = $goodies.extend,
  5. api = boot.api;
  6. // API
  7. exports.popupHelios = function () {
  8. require(['helios/index'], function (helios) {
  9. helios.popup();
  10. }, function (err) {
  11. window.alert("Error loading helios.\nIf not present, you can install it with 'npm install @ambers/helios --save-dev'.\nThe error follows:\n" + err);
  12. });
  13. };
  14. Object.defineProperty(exports, "api", {
  15. value: api,
  16. enumerable: true, configurable: true, writable: false
  17. });
  18. Object.defineProperty(exports, "globals", {
  19. value: globals,
  20. enumerable: true, configurable: true, writable: false
  21. });
  22. Object.defineProperty(exports, "$nil", {
  23. value: boot.nilAsReceiver,
  24. enumerable: true, configurable: true, writable: false
  25. });
  26. Object.defineProperty(exports, "nil", {
  27. value: boot.nilAsValue,
  28. enumerable: true, configurable: true, writable: false
  29. });
  30. function settingsInLocalStorage () {
  31. //jshint evil:true
  32. var storage = 'localStorage' in global && global.localStorage;
  33. if (storage) {
  34. var fromStorage;
  35. try {
  36. fromStorage = JSON.parse(storage.getItem('amber.SmalltalkSettings'));
  37. } catch (ex) {
  38. // pass
  39. }
  40. extend(globals.SmalltalkSettings, fromStorage || {});
  41. if (typeof window !== "undefined") {
  42. window.addEventListener('beforeunload', function () {
  43. storage.setItem('amber.SmalltalkSettings', JSON.stringify(globals.SmalltalkSettings));
  44. });
  45. }
  46. }
  47. }
  48. exports.initialize = function (options) {
  49. return new Promise(function (resolve) {
  50. globals.SmalltalkSettings['transport.defaultAmdNamespace'] = "amber/core";
  51. api.amdRequire = require; // TODO better
  52. settingsInLocalStorage();
  53. extend(globals.SmalltalkSettings, options || {});
  54. resolve(api.initialize());
  55. });
  56. };
  57. exports.loadPackages = function (modules) {
  58. return new Promise(function (resolve, reject) {
  59. require(modules, resolve, reject);
  60. }).then(function () {
  61. return globals.Smalltalk._postLoad();
  62. });
  63. };
  64. exports.beClean = function () {
  65. return globals.Smalltalk._beClean();
  66. };
  67. // Exports
  68. return exports;
  69. });