1
0

amber.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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();
  8. smalltalk.Browser._open();
  9. });
  10. For detailed explanation of amber loading, see:
  11. https://github.com/amber-smalltalk/amber/wiki/How-to-load-amber
  12. */
  13. var require;
  14. require = function (require) {
  15. // To be able to use its path and attrubutes
  16. // to map other parts of Amber, this code must find its <script> tag.
  17. // It first looks for id 'amber-path-mapper'.
  18. // When loading amber.js asynchronously, you must include this id,
  19. // or the code can not reliably find its <script>.
  20. var me = document.getElementById("amber-path-mapper");
  21. if (!me || me.tagName.toLowerCase() !== "script") {
  22. // If <script> with 'amber-path-mapper' id is not present,
  23. // (this id is not necessary for inline <script> tag in HTML),
  24. // it uses the "find the last <script> tag present in the moment" method.
  25. var scripts = document.getElementsByTagName("script");
  26. me = scripts[scripts.length - 1];
  27. }
  28. var src = me.src;
  29. // strip the last two elements from the URL
  30. // e.g. http://app.com/amber/support/amber.js -> http://app.com/amber
  31. var amber_home = resolveViaDOM(src).replace(/\/[^\/]+\/[^\/]+$/, "");
  32. // In case of nonstandard deployment, you can specify libraries placement directly ...
  33. var library_home = me.hasAttribute('data-libs') && me.getAttribute('data-libs');
  34. // ... otherwise, this heuristics is used:
  35. if (!library_home) {
  36. // At the present moment, bower tries to have flat hierarchy,
  37. // which leads to two possible scenarios:
  38. // 1. amber itself was deployed via bower,
  39. // its libraries are at the same bower dir
  40. // where amber itself is placed
  41. // 2. amber was deployed in different fashion,
  42. // its libraries are included by bower locally, inside amber
  43. // The detection is done by looking for '/bower_components/' in amber path.
  44. var match = amber_home.match(/^(.*\/bower_components)\//);
  45. library_home = match ? match[1] : amber_home + '/bower_components';
  46. }
  47. function resolveViaDOM(url) {
  48. var a = document.createElement("a");
  49. a.href = url;
  50. return a.href;
  51. }
  52. var config = {
  53. paths: {
  54. 'amber': amber_home + '/support',
  55. 'amber_vm': amber_home + '/support',
  56. 'amber_css': amber_home + '/css',
  57. 'amber_lib': library_home,
  58. 'amber_core': amber_home + '/js',
  59. 'amber_core/_source': amber_home + '/st',
  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_lib/codemirror/addon/hint/show-hint': {
  83. deps: [ '../../lib/codemirror' ]
  84. },
  85. 'ensure-console': {
  86. exports: 'console'
  87. }
  88. }
  89. };
  90. // This is to allow both alternatives of loading:
  91. // before require.js as well as after require.js
  92. // See http://requirejs.org/docs/api.html#config for details
  93. // of usage of 'require' global to allow to pre-define configuration
  94. // before require.js is loaded.
  95. if (require) {
  96. require.config(config);
  97. return require;
  98. } else {
  99. return config;
  100. }
  101. }(require);