helpers.js 2.6 KB

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