amber.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Adapted from Clamato by Avi Bryant. http://www.clamato.net */
  2. (function() {
  3. var scripts = document.getElementsByTagName("script");
  4. var src = scripts[ scripts.length - 1 ].src;
  5. var home = src.split("/").slice(0, -2).join("/") + "/";
  6. var nocache = '?' + (new Date()).getTime();
  7. var deploy = false;
  8. function loadJS(name, prefix) {
  9. var prefix = prefix || 'js';
  10. var name = name;
  11. if(!deploy) {
  12. name = name + nocache;
  13. }
  14. document.write('<script src="' + home + prefix + '/' + name + '" type="text/javascript"></script>');
  15. }
  16. function loadCSS(name, prefix) {
  17. var prefix = prefix || 'css';
  18. var name = name;
  19. if(!deploy) {
  20. name = name + nocache;
  21. }
  22. var link = document.createElement("link")
  23. link.setAttribute("rel", "stylesheet")
  24. link.setAttribute("type", "text/css")
  25. link.setAttribute("href", home + prefix + '/' + name)
  26. document.getElementsByTagName("head")[0].appendChild(link);
  27. }
  28. function loadDependencies() {
  29. loadJS('lib/jQuery/jquery-1.6.2.min.js');
  30. loadJS('lib/jQuery/jquery-ui-1.8.9.custom.min.js');
  31. }
  32. function loadIDEDependencies() {
  33. loadJS('lib/jQuery/jquery.textarea.js');
  34. loadJS('lib/CodeMirror/lib/codemirror.js');
  35. loadCSS('lib/CodeMirror/lib/codemirror.css', 'js');
  36. loadJS('lib/CodeMirror/mode/smalltalk/smalltalk.js');
  37. loadCSS('lib/CodeMirror/theme/amber.css', 'js');
  38. }
  39. window.loadAmber = function(spec) {
  40. /*
  41. example:
  42. loadAmber({
  43. files: ['MyCategory1.js', 'MyCategory2.js'],
  44. ready: function() {smalltalk.Browser._open()}
  45. })
  46. */
  47. var spec = spec || {};
  48. // In deployment mode, only the compressed version of Kernel
  49. // and Canvas are loaded
  50. deploy = spec.deploy || false;
  51. // Specify a version string to avoid wrong browser caching
  52. if(spec.version) {
  53. nocache = '?' + spec.version;
  54. }
  55. loadDependencies();
  56. if(deploy) {
  57. loadJS("boot.js");
  58. loadJS("Kernel.deploy.js");
  59. loadJS("Canvas.deploy.js");
  60. } else {
  61. loadIDEDependencies();
  62. loadCSS('amber.css');
  63. loadJS("boot.js");
  64. loadJS("Kernel.js");
  65. loadJS("Canvas.js");
  66. loadJS("Compiler.js");
  67. loadJS("parser.js");
  68. loadJS("IDE.js");
  69. loadJS("SUnit.js");
  70. loadJS("Examples.js");
  71. loadJS("Benchfib.js");
  72. loadJS("Kernel-Tests.js");
  73. }
  74. // Load other files, possibly with another directory prefix than 'js'
  75. if(spec.files) {
  76. for(var i=0; i < spec.files.length; i++) {
  77. loadJS(spec.files[i], spec.prefix);
  78. }
  79. }
  80. smalltalkReady = function() {
  81. if(spec.ready) {
  82. spec.ready();
  83. }
  84. if(deploy) {smalltalk.setDeploymentMode()}
  85. }
  86. // Be sure to setup & initialize smalltalk classes
  87. loadJS("init.js");
  88. }
  89. })();