2
0

helpers.js 2.5 KB

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