1
0

amber.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. var me = document.getElementById("amber-path-mapper");
  16. if (!me || me.tagName.toLowerCase() !== "script") {
  17. var scripts = document.getElementsByTagName("script");
  18. me = scripts[scripts.length - 1];
  19. }
  20. var src = me.src;
  21. // strip the last two elements from the URL
  22. // e.g. http://app.com/amber/support/amber.js -> http://app.com/amber
  23. var amber_home = resolveViaDOM(src).replace(/\/[^\/]+\/[^\/]+$/, "");
  24. // In case of nonstandard deployment, you can specify libraries placement directly ...
  25. var library_home = me.hasAttribute('data-libs') && me.getAttribute('data-libs');
  26. // ... otherwise, this heuristics is used:
  27. if (!library_home) {
  28. // At the present moment, bower tries to have flat hierarchy,
  29. // which leads to two possible scenarios:
  30. // 1. amber itself was deployed via bower,
  31. // its libraries are at the same bower dir
  32. // where amber itself is placed
  33. // 2. amber was deployed in different fashion,
  34. // its libraries are included by bower locally, inside amber
  35. // The detection is done by looking for '/bower_components/' in amber path.
  36. var match = amber_home.match(/^(.*\/bower_components)\//);
  37. library_home = match ? match[1] : amber_home + '/bower_components';
  38. }
  39. function resolveViaDOM(url) {
  40. var a = document.createElement("a");
  41. a.href = url;
  42. return a.href;
  43. }
  44. var config = {
  45. paths: {
  46. 'amber': amber_home + '/support',
  47. 'amber_vm': amber_home + '/support',
  48. 'amber_css': amber_home + '/css',
  49. 'amber_lib': library_home,
  50. 'amber_inc': amber_home + '/support',
  51. 'amber_core': amber_home + '/js',
  52. 'amber_core/_source': amber_home + '/st',
  53. 'amber_helios/html': amber_home,
  54. 'jquery': library_home + '/jquery/jquery.min',
  55. 'jquery-ui': library_home + '/jquery-ui/ui/minified/jquery-ui.min'
  56. },
  57. map: {
  58. '*': {
  59. 'css': 'amber_lib/require-css/css'
  60. }
  61. },
  62. shim: {
  63. 'jquery-ui': {
  64. deps: [ 'jquery' ]
  65. },
  66. 'amber_lib/bootstrap/js/bootstrap': {
  67. deps: [ 'jquery', 'css!amber_lib/bootstrap/css/bootstrap' ]
  68. },
  69. 'amber_lib/codemirror/lib/codemirror': {
  70. deps: [ 'css!amber_lib/codemirror/lib/codemirror' ]
  71. },
  72. 'amber_lib/jquery-tabby/jquery.textarea': {
  73. deps: [ 'jquery' ]
  74. },
  75. 'amber_inc/CodeMirror/smalltalk': {
  76. deps: [ 'amber_lib/codemirror/lib/codemirror' ]
  77. },
  78. 'amber_lib/codemirror/addon/hint/show-hint': {
  79. deps: [ '../../lib/codemirror' ]
  80. },
  81. 'ensure-console': {
  82. exports: 'console'
  83. }
  84. }
  85. };
  86. // This is to allow both alternatives of loading:
  87. // before require.js as well as after require.js
  88. // See http://requirejs.org/docs/api.html#config for details
  89. // of usage of 'require' global to allow to pre-define configuration
  90. // before require.js is loaded.
  91. if (require) {
  92. require.config(config);
  93. return require;
  94. } else {
  95. return config;
  96. }
  97. }(require);