1
0

amber.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Amber package loading.
  2. Load this script as well as require.js (works in any order;
  3. either defines 'require', thus passing config, if loaded prior require.js;
  4. or calls require.config, if loaded post require.js).
  5. Usage example:
  6. require(['amber/devel'], function(smalltalk) {
  7. smallralk.initialize({"transport.defaultAmdNamespace": "com_example_myproject"});
  8. smalltalk.globals.Browser._open(); // for legacy IDE
  9. smalltalk.popupHelios(); // for Helios IDE
  10. });
  11. For detailed explanation of amber loading, see:
  12. https://github.com/amber-smalltalk/amber/wiki/How-to-load-amber
  13. */
  14. var require;
  15. require = function (require) {
  16. // To be able to use its path and attrubutes
  17. // to map other parts of Amber, this code must find its <script> tag.
  18. // It first looks for id 'amber-path-mapper'.
  19. // When loading amber.js asynchronously, you must include this id,
  20. // or the code can not reliably find its <script>.
  21. var me = document.getElementById("amber-path-mapper");
  22. if (!me || me.tagName.toLowerCase() !== "script") {
  23. // If <script> with 'amber-path-mapper' id is not present,
  24. // (this id is not necessary for inline <script> tag in HTML),
  25. // it uses the "find the last <script> tag present in the moment" method.
  26. var scripts = document.getElementsByTagName("script");
  27. me = scripts[scripts.length - 1];
  28. }
  29. var src = me.src;
  30. // strip the last two elements from the URL
  31. // e.g. http://app.com/amber/support/amber.js -> http://app.com/amber
  32. var amber_home = resolveViaDOM(src).replace(/\/[^\/]+\/[^\/]+$/, "");
  33. // In case of nonstandard deployment, you can specify libraries placement directly ...
  34. var library_home = me.hasAttribute('data-libs') && me.getAttribute('data-libs');
  35. // ... otherwise, this heuristics is used:
  36. if (!library_home) {
  37. // At the present moment, bower tries to have flat hierarchy,
  38. // which leads to two possible scenarios:
  39. // 1. amber itself was deployed via bower,
  40. // its libraries are at the same bower dir
  41. // where amber itself is placed
  42. // 2. amber was deployed in different fashion,
  43. // its libraries are included by bower locally, inside amber
  44. // The detection is done by looking for '/bower_components/' in amber path.
  45. var match = amber_home.match(/^(.*\/bower_components)\//);
  46. library_home = match ? match[1] : amber_home + '/bower_components';
  47. }
  48. function resolveViaDOM(url) {
  49. var a = document.createElement("a");
  50. a.href = url;
  51. return a.href;
  52. }
  53. var config = {
  54. paths: {
  55. 'amber': amber_home + '/support',
  56. 'amber_vm': amber_home + '/support',
  57. 'amber_css': amber_home + '/css',
  58. 'amber_lib': library_home,
  59. 'amber_core': amber_home + '/src',
  60. 'amber_helios/html': amber_home,
  61. 'jquery': library_home + '/jquery/jquery.min',
  62. 'jquery-ui': library_home + '/jquery-ui/ui/minified/jquery-ui.min'
  63. },
  64. map: {
  65. '*': {
  66. 'css': 'amber_lib/require-css/css'
  67. }
  68. },
  69. shim: {
  70. 'jquery-ui': {
  71. deps: [ 'jquery' ]
  72. },
  73. 'amber_lib/bootstrap/js/bootstrap': {
  74. deps: [ 'jquery', 'css!amber_lib/bootstrap/css/bootstrap' ]
  75. },
  76. 'amber_lib/codemirror/lib/codemirror': {
  77. deps: [ 'css!amber_lib/codemirror/lib/codemirror' ]
  78. },
  79. 'amber_lib/jquery-tabby/jquery.textarea': {
  80. deps: [ 'jquery' ]
  81. },
  82. 'amber_core/IDE': {
  83. deps: [ 'amber_lib/codemirror/mode/smalltalk/smalltalk' ]
  84. },
  85. 'amber_lib/codemirror/mode/smalltalk/smalltalk': {
  86. deps: [ '../../lib/codemirror' ]
  87. },
  88. 'amber_lib/codemirror/addon/hint/show-hint': {
  89. deps: [ '../../lib/codemirror' ]
  90. },
  91. 'ensure-console': {
  92. exports: 'console'
  93. }
  94. }
  95. };
  96. // This is to allow both alternatives of loading:
  97. // before require.js as well as after require.js
  98. // See http://requirejs.org/docs/api.html#config for details
  99. // of usage of 'require' global to allow to pre-define configuration
  100. // before require.js is loaded.
  101. if (require) {
  102. require.config(config);
  103. return require;
  104. } else {
  105. return config;
  106. }
  107. }(require);