2
0

helpers.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. define("amber/helpers", ["amber/boot", "require"], function (boot, require) {
  2. var globals = boot.globals,
  3. exports = Object.create(globals), // backward compatibility, use {} later
  4. vm = boot.vm,
  5. nil = boot.vm;
  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, "vm", {
  15. value: vm,
  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. var global = new Function('return this')(),
  34. 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. requirejs(['jquery'], function ($) {
  45. $(window).on('beforeunload', function () {
  46. storage.setItem('amber.SmalltalkSettings', JSON.stringify(globals.SmalltalkSettings));
  47. });
  48. });
  49. }
  50. }
  51. }
  52. exports.initialize = function (options) {
  53. globals.SmalltalkSettings['transport.defaultAmdNamespace'] = vm.defaultAmdNamespace;
  54. settingsInLocalStorage();
  55. if (exports.defaultAmdNamespace) {
  56. console.warn("`smalltalk.defaultAmdNamespace = 'namespace';` is deprecated. Please use `smalltalk.initialize({'transport.defaultAmdNamespace': 'namespace'});` instead.");
  57. globals.SmalltalkSettings['transport.defaultAmdNamespace'] = globals.SmalltalkSettings['transport.defaultAmdNamespace'] || exports.defaultAmdNamespace;
  58. }
  59. mixinToSettings(options || {});
  60. console.warn("smalltalk.ClassName is deprecated. Please use smalltalk.globals.ClassName instead.");
  61. return vm.initialize();
  62. };
  63. // Backward compatibility, deprecated
  64. Object.defineProperty(exports, "smalltalk", {
  65. value: vm,
  66. enumerable: true, configurable: true, writable: false
  67. });
  68. exports.defaultAmdNamespace = null;
  69. // Exports
  70. return exports;
  71. });