2
0

helpers.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. window.open(require.toUrl('helios/index.html'), "Helios", "menubar=no, width=1000, height=600");
  9. };
  10. Object.defineProperty(exports, "vm", {
  11. value: vm,
  12. enumerable: true, configurable: true, writable: false
  13. });
  14. Object.defineProperty(exports, "globals", {
  15. value: globals,
  16. enumerable: true, configurable: true, writable: false
  17. });
  18. Object.defineProperty(exports, "nil", {
  19. value: nil,
  20. enumerable: true, configurable: true, writable: false
  21. });
  22. function mixinToSettings(source) {
  23. var settings = globals.SmalltalkSettings;
  24. Object.keys(source).forEach(function (key) {
  25. settings[key] = source[key];
  26. });
  27. }
  28. function settingsInLocalStorage() {
  29. var global = new Function('return this')(),
  30. storage = 'localStorage' in global && global.localStorage;
  31. if (storage) {
  32. var fromStorage;
  33. try {
  34. fromStorage = JSON.parse(storage.getItem('amber.SmalltalkSettings'));
  35. } catch (ex) {
  36. // pass
  37. }
  38. mixinToSettings(fromStorage || {});
  39. if (typeof window !== "undefined") {
  40. requirejs(['jquery'], function ($) {
  41. $(window).on('beforeunload', function () {
  42. storage.setItem('amber.SmalltalkSettings', JSON.stringify(globals.SmalltalkSettings));
  43. });
  44. });
  45. }
  46. }
  47. }
  48. exports.initialize = function (options) {
  49. globals.SmalltalkSettings['transport.defaultAmdNamespace'] = vm.defaultAmdNamespace;
  50. settingsInLocalStorage();
  51. if (exports.defaultAmdNamespace) {
  52. console.warn("`smalltalk.defaultAmdNamespace = 'namespace';` is deprecated. Please use `smalltalk.initialize({'transport.defaultAmdNamespace': 'namespace'});` instead.");
  53. globals.SmalltalkSettings['transport.defaultAmdNamespace'] = globals.SmalltalkSettings['transport.defaultAmdNamespace'] || exports.defaultAmdNamespace;
  54. }
  55. mixinToSettings(options || {});
  56. console.warn("smalltalk.ClassName is deprecated. Please use smalltalk.globals.ClassName instead.");
  57. return vm.initialize();
  58. };
  59. // Backward compatibility, deprecated
  60. Object.defineProperty(exports, "smalltalk", {
  61. value: vm,
  62. enumerable: true, configurable: true, writable: false
  63. });
  64. exports.defaultAmdNamespace = null;
  65. // Exports
  66. return exports;
  67. });