2
0

amber.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. loadJS("JQuery.deploy.js");
  61. } else {
  62. loadIDEDependencies();
  63. loadCSS('amber.css');
  64. loadJS("boot.js");
  65. loadJS("Kernel.js");
  66. loadJS("Canvas.js");
  67. loadJS("JQuery.js");
  68. loadJS("Compiler.js");
  69. loadJS("parser.js");
  70. loadJS("IDE.js");
  71. loadJS("SUnit.js");
  72. loadJS("Examples.js");
  73. loadJS("Benchfib.js");
  74. loadJS("Kernel-Tests.js");
  75. loadJS("JQuery-Tests.js");
  76. }
  77. // Load other files, possibly with another directory prefix than 'js'
  78. if(spec.files) {
  79. for(var i=0; i < spec.files.length; i++) {
  80. loadJS(spec.files[i], spec.prefix);
  81. }
  82. }
  83. smalltalkReady = function() {
  84. if(spec.ready) {
  85. spec.ready();
  86. }
  87. if(deploy) {smalltalk.setDeploymentMode()}
  88. }
  89. // Be sure to setup & initialize smalltalk classes
  90. loadJS("init.js");
  91. }
  92. })();