2
0

amber.js 3.7 KB

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