2
0

helpers.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. api = boot.api,
  5. nil = boot.nil;
  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 global = new Function('return this')(),
  35. storage = 'localStorage' in global && global.localStorage;
  36. if (storage) {
  37. var fromStorage;
  38. try {
  39. fromStorage = JSON.parse(storage.getItem('amber.SmalltalkSettings'));
  40. } catch (ex) {
  41. // pass
  42. }
  43. mixinToSettings(fromStorage || {});
  44. if (typeof window !== "undefined") {
  45. requirejs(['jquery'], function ($) {
  46. $(window).on('beforeunload', function () {
  47. storage.setItem('amber.SmalltalkSettings', JSON.stringify(globals.SmalltalkSettings));
  48. });
  49. });
  50. }
  51. }
  52. }
  53. exports.initialize = function (options) {
  54. globals.SmalltalkSettings['transport.defaultAmdNamespace'] = api.defaultAmdNamespace;
  55. settingsInLocalStorage();
  56. if (exports.defaultAmdNamespace) {
  57. console.warn("`smalltalk.defaultAmdNamespace = 'namespace';` is deprecated. Please use `smalltalk.initialize({'transport.defaultAmdNamespace': 'namespace'});` instead.");
  58. globals.SmalltalkSettings['transport.defaultAmdNamespace'] = globals.SmalltalkSettings['transport.defaultAmdNamespace'] || exports.defaultAmdNamespace;
  59. }
  60. mixinToSettings(options || {});
  61. console.warn("smalltalk.ClassName is deprecated. Please use smalltalk.globals.ClassName instead.");
  62. return api.initialize();
  63. };
  64. // Backward compatibility, deprecated
  65. Object.defineProperty(exports, "smalltalk", {
  66. value: api,
  67. enumerable: true, configurable: true, writable: false
  68. });
  69. Object.defineProperty(exports, "vm", {
  70. value: api,
  71. enumerable: true, configurable: true, writable: false
  72. });
  73. exports.defaultAmdNamespace = null;
  74. // Exports
  75. return exports;
  76. });