1
0

helpers.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. define(["amber/boot", "require"], function (boot, require) {
  2. var globals = boot.globals,
  3. exports = {},
  4. api = boot.api,
  5. nil = boot.nilAsReceiver;
  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 'bower install 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: nil,
  24. enumerable: true, configurable: true, writable: false
  25. });
  26. function mixinToSettings (source) {
  27. var settings = globals.SmalltalkSettings;
  28. Object.keys(source).forEach(function (key) {
  29. settings[key] = source[key];
  30. });
  31. }
  32. function settingsInLocalStorage () {
  33. //jshint evil:true
  34. var storage = 'localStorage' in global && global.localStorage;
  35. if (storage) {
  36. var fromStorage;
  37. try {
  38. fromStorage = JSON.parse(storage.getItem('amber.SmalltalkSettings'));
  39. } catch (ex) {
  40. // pass
  41. }
  42. mixinToSettings(fromStorage || {});
  43. if (typeof window !== "undefined") {
  44. window.addEventListener('beforeunload', function () {
  45. storage.setItem('amber.SmalltalkSettings', JSON.stringify(globals.SmalltalkSettings));
  46. });
  47. }
  48. }
  49. }
  50. exports.initialize = function (options) {
  51. return new Promise(function (resolve) {
  52. globals.SmalltalkSettings['transport.defaultAmdNamespace'] = api.defaultAmdNamespace;
  53. settingsInLocalStorage();
  54. mixinToSettings(options || {});
  55. resolve(api.initialize());
  56. });
  57. };
  58. exports.loadPackages = function (modules) {
  59. return new Promise(function (resolve, reject) {
  60. require(modules, resolve, reject);
  61. }).then(function () {
  62. return globals.Smalltalk._postLoad();
  63. });
  64. };
  65. // Exports
  66. return exports;
  67. });