MochiKit.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /***
  2. MochiKit.MochiKit 1.4
  3. See <http://mochikit.com/> for documentation, downloads, license, etc.
  4. (c) 2005 Bob Ippolito. All rights Reserved.
  5. ***/
  6. if (typeof(MochiKit) == 'undefined') {
  7. MochiKit = {};
  8. }
  9. if (typeof(MochiKit.MochiKit) == 'undefined') {
  10. /** @id MochiKit.MochiKit */
  11. MochiKit.MochiKit = {};
  12. }
  13. MochiKit.MochiKit.NAME = "MochiKit.MochiKit";
  14. MochiKit.MochiKit.VERSION = "1.4";
  15. MochiKit.MochiKit.__repr__ = function () {
  16. return "[" + this.NAME + " " + this.VERSION + "]";
  17. };
  18. /** @id MochiKit.MochiKit.toString */
  19. MochiKit.MochiKit.toString = function () {
  20. return this.__repr__();
  21. };
  22. /** @id MochiKit.MochiKit.SUBMODULES */
  23. MochiKit.MochiKit.SUBMODULES = [
  24. "Base",
  25. "Iter",
  26. "Logging",
  27. "DateTime",
  28. "Format",
  29. "Async",
  30. "DOM",
  31. "Style",
  32. "LoggingPane",
  33. "Color",
  34. "Signal",
  35. "Visual"
  36. ];
  37. if (typeof(JSAN) != 'undefined' || typeof(dojo) != 'undefined') {
  38. if (typeof(dojo) != 'undefined') {
  39. dojo.provide('MochiKit.MochiKit');
  40. dojo.require("MochiKit.*");
  41. }
  42. if (typeof(JSAN) != 'undefined') {
  43. (function (lst) {
  44. for (var i = 0; i < lst.length; i++) {
  45. JSAN.use("MochiKit." + lst[i], []);
  46. }
  47. })(MochiKit.MochiKit.SUBMODULES);
  48. }
  49. (function () {
  50. var extend = MochiKit.Base.extend;
  51. var self = MochiKit.MochiKit;
  52. var modules = self.SUBMODULES;
  53. var EXPORT = [];
  54. var EXPORT_OK = [];
  55. var EXPORT_TAGS = {};
  56. var i, k, m, all;
  57. for (i = 0; i < modules.length; i++) {
  58. m = MochiKit[modules[i]];
  59. extend(EXPORT, m.EXPORT);
  60. extend(EXPORT_OK, m.EXPORT_OK);
  61. for (k in m.EXPORT_TAGS) {
  62. EXPORT_TAGS[k] = extend(EXPORT_TAGS[k], m.EXPORT_TAGS[k]);
  63. }
  64. all = m.EXPORT_TAGS[":all"];
  65. if (!all) {
  66. all = extend(null, m.EXPORT, m.EXPORT_OK);
  67. }
  68. var j;
  69. for (j = 0; j < all.length; j++) {
  70. k = all[j];
  71. self[k] = m[k];
  72. }
  73. }
  74. self.EXPORT = EXPORT;
  75. self.EXPORT_OK = EXPORT_OK;
  76. self.EXPORT_TAGS = EXPORT_TAGS;
  77. }());
  78. } else {
  79. if (typeof(MochiKit.__compat__) == 'undefined') {
  80. MochiKit.__compat__ = true;
  81. }
  82. (function () {
  83. if (typeof(document) == "undefined") {
  84. return;
  85. }
  86. var scripts = document.getElementsByTagName("script");
  87. var kXULNSURI = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  88. var base = null;
  89. var baseElem = null;
  90. var allScripts = {};
  91. var i;
  92. for (i = 0; i < scripts.length; i++) {
  93. var src = scripts[i].getAttribute("src");
  94. if (!src) {
  95. continue;
  96. }
  97. allScripts[src] = true;
  98. if (src.match(/MochiKit.js$/)) {
  99. base = src.substring(0, src.lastIndexOf('MochiKit.js'));
  100. baseElem = scripts[i];
  101. }
  102. }
  103. if (base === null) {
  104. return;
  105. }
  106. var modules = MochiKit.MochiKit.SUBMODULES;
  107. for (var i = 0; i < modules.length; i++) {
  108. if (MochiKit[modules[i]]) {
  109. continue;
  110. }
  111. var uri = base + modules[i] + '.js';
  112. if (uri in allScripts) {
  113. continue;
  114. }
  115. if (document.documentElement &&
  116. document.documentElement.namespaceURI == kXULNSURI) {
  117. // XUL
  118. var s = document.createElementNS(kXULNSURI, 'script');
  119. s.setAttribute("id", "MochiKit_" + base + modules[i]);
  120. s.setAttribute("src", uri);
  121. s.setAttribute("type", "application/x-javascript");
  122. baseElem.parentNode.appendChild(s);
  123. } else {
  124. // HTML
  125. /*
  126. DOM can not be used here because Safari does
  127. deferred loading of scripts unless they are
  128. in the document or inserted with document.write
  129. This is not XHTML compliant. If you want XHTML
  130. compliance then you must use the packed version of MochiKit
  131. or include each script individually (basically unroll
  132. these document.write calls into your XHTML source)
  133. */
  134. document.write('<script src="' + uri +
  135. '" type="text/javascript"></script>');
  136. }
  137. };
  138. })();
  139. }