MockDOM.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /***
  2. MochiKit.MockDOM 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.MockDOM) == "undefined") {
  10. MochiKit.MockDOM = {};
  11. }
  12. MochiKit.MockDOM.NAME = "MochiKit.MockDOM";
  13. MochiKit.MockDOM.VERSION = "1.4";
  14. MochiKit.MockDOM.__repr__ = function () {
  15. return "[" + this.NAME + " " + this.VERSION + "]";
  16. };
  17. MochiKit.MockDOM.toString = function () {
  18. return this.__repr__();
  19. };
  20. MochiKit.MockDOM.createDocument = function () {
  21. var doc = new MochiKit.MockDOM.MockElement("DOCUMENT");
  22. doc.body = doc.createElement("BODY");
  23. doc.appendChild(doc.body);
  24. return doc;
  25. };
  26. MochiKit.MockDOM.MockElement = function (name, data) {
  27. this.nodeName = name.toUpperCase();
  28. if (typeof(data) == "string") {
  29. this.nodeValue = data;
  30. this.nodeType = 3;
  31. } else {
  32. this.nodeType = 1;
  33. this.childNodes = [];
  34. }
  35. if (name.substring(0, 1) == "<") {
  36. var nameattr = name.substring(
  37. name.indexOf('"') + 1, name.lastIndexOf('"'));
  38. name = name.substring(1, name.indexOf(" "));
  39. this.nodeName = name.toUpperCase();
  40. this.setAttribute("name", nameattr);
  41. }
  42. };
  43. MochiKit.MockDOM.MockElement.prototype = {
  44. createElement: function (nodeName) {
  45. return new MochiKit.MockDOM.MockElement(nodeName);
  46. },
  47. createTextNode: function (text) {
  48. return new MochiKit.MockDOM.MockElement("text", text);
  49. },
  50. setAttribute: function (name, value) {
  51. this[name] = value;
  52. },
  53. getAttribute: function (name) {
  54. return this[name];
  55. },
  56. appendChild: function (child) {
  57. this.childNodes.push(child);
  58. },
  59. toString: function () {
  60. return "MockElement(" + this.nodeName + ")";
  61. }
  62. };
  63. MochiKit.MockDOM.EXPORT_OK = [
  64. "mockElement",
  65. "createDocument"
  66. ];
  67. MochiKit.MockDOM.EXPORT = [
  68. "document"
  69. ];
  70. MochiKit.MockDOM.__new__ = function () {
  71. this.document = this.createDocument();
  72. };
  73. MochiKit.MockDOM.__new__();