2
0

amber.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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(amber) {
  7. amber.initialize({"transport.defaultAmdNamespace": "com_example_myproject"});
  8. amber.globals.Browser._open(); // for legacy IDE
  9. amber.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. 'mousewheel': library_home + '/jquery-mousewheel/jquery.mousewheel'
  64. },
  65. map: {
  66. '*': {
  67. 'css': 'amber_lib/require-css/css'
  68. }
  69. },
  70. shim: {
  71. 'jquery-ui': {
  72. deps: [ 'jquery' ]
  73. },
  74. 'amber_lib/bootstrap/js/bootstrap': {
  75. deps: [ 'jquery', 'css!amber_lib/bootstrap/css/bootstrap' ]
  76. },
  77. 'amber_lib/codemirror/lib/codemirror': {
  78. deps: [ 'css!amber_lib/codemirror/lib/codemirror' ]
  79. },
  80. 'amber_lib/jquery-tabby/jquery.textarea': {
  81. deps: [ 'jquery' ]
  82. },
  83. 'amber_core/IDE': {
  84. deps: [ 'amber_lib/codemirror/mode/smalltalk/smalltalk' ]
  85. },
  86. 'amber_lib/codemirror/mode/smalltalk/smalltalk': {
  87. deps: [ '../../lib/codemirror' ]
  88. },
  89. 'amber_lib/codemirror/addon/hint/show-hint': {
  90. deps: [ '../../lib/codemirror' ]
  91. },
  92. 'ensure-console': {
  93. exports: 'console'
  94. }
  95. }
  96. };
  97. // This is to allow both alternatives of loading:
  98. // before require.js as well as after require.js
  99. // See http://requirejs.org/docs/api.html#config for details
  100. // of usage of 'require' global to allow to pre-define configuration
  101. // before require.js is loaded.
  102. if (require) {
  103. require.config(config);
  104. return require;
  105. } else {
  106. return config;
  107. }
  108. }(require);