1
0

amber.js 3.5 KB

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