amber.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. 'jscrollpane': document_home + '/bower_components/jscrollpane/script/jquery.jscrollpane.min',
  51. 'mousewheel': document_home + '/bower_components/jscrollpane/script/jquery.mousewheel'
  52. },
  53. map: {
  54. '*': {
  55. 'css': 'amber_lib/require-css/css'
  56. }
  57. },
  58. shim: {
  59. 'jquery-ui': {
  60. deps: [ 'jquery' ]
  61. },
  62. 'amber_lib/bootstrap/js/bootstrap': {
  63. deps: [ 'jquery', 'css!amber_lib/bootstrap/css/bootstrap' ]
  64. },
  65. 'amber_lib/CodeMirror/codemirror': {
  66. deps: [ 'css!amber_lib/codemirror/lib/codemirror' ]
  67. },
  68. 'amber_lib/jquery-tabby/jquery.textarea': {
  69. deps: [ 'jquery', 'jquery-ui' ]
  70. },
  71. 'amber_inc/CodeMirror/smalltalk': {
  72. deps: [ 'amber_lib/codemirror/lib/codemirror' ]
  73. },
  74. 'amber_lib/codemirror/addon/hint/show-hint': {
  75. deps: [ '../../lib/codemirror' ]
  76. },
  77. 'ensure-console': {
  78. exports: 'console'
  79. }
  80. }
  81. };
  82. // This is to allow both alternatives of loading:
  83. // before require.js as well as after require.js
  84. // See http://requirejs.org/docs/api.html#config for details
  85. // of usage of 'require' global to allow to pre-define configuration
  86. // before require.js is loaded.
  87. if (require) {
  88. require.config(config);
  89. return require;
  90. } else {
  91. return config;
  92. }
  93. }(require);