envjs 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/.jslintrbrc +29 -0
  2. data/.project +17 -0
  3. data/CHANGELOG.rdoc +3 -0
  4. data/DTD/xhtml-lat1.ent +196 -0
  5. data/DTD/xhtml-special.ent +80 -0
  6. data/DTD/xhtml-symbol.ent +237 -0
  7. data/DTD/xhtml.soc +14 -0
  8. data/DTD/xhtml1-frameset.dtd +1235 -0
  9. data/DTD/xhtml1-strict.dtd +978 -0
  10. data/DTD/xhtml1-transitional.dtd +1201 -0
  11. data/DTD/xhtml1.dcl +192 -0
  12. data/Makefile +7 -0
  13. data/Manifest.txt +287 -0
  14. data/{README → README.rdoc} +24 -3
  15. data/Rakefile +196 -0
  16. data/Wakefile +24 -0
  17. data/build.properties +9 -0
  18. data/build.xml +247 -0
  19. data/gm/jquery.js +6002 -0
  20. data/gm/mainx.js +2648 -0
  21. data/gm/sensx.js +135 -0
  22. data/gm/t.js +6 -0
  23. data/gm/x.html +76 -0
  24. data/htmlparser/BrowserTreeBuilder.java +456 -0
  25. data/htmlparser/README +34 -0
  26. data/htmlparser/build.sh +38 -0
  27. data/jsl/jsl +0 -0
  28. data/jsl/jsl.default.conf +129 -0
  29. data/jsl/jsl.exe +0 -0
  30. data/lib/envjs.rb +2 -0
  31. data/lib/envjs/env.js +22 -3
  32. data/lib/envjs/event_loop.js +2 -0
  33. data/lib/envjs/static.js +155 -21
  34. data/licenses/GPL-LICENSE.txt +278 -0
  35. data/licenses/MIT-LICENSE.txt +20 -0
  36. data/src/base64.js +80 -0
  37. data/src/build.js +6 -0
  38. data/src/cruft/bad.html +24 -0
  39. data/src/cruft/dom.js +606 -0
  40. data/src/cruft/element.js +297 -0
  41. data/src/cruft/good.html +30 -0
  42. data/src/cruft/good.js +32 -0
  43. data/src/cruft/internal.js +81 -0
  44. data/src/cruft/parser.js +458 -0
  45. data/src/css/properties.js +293 -0
  46. data/src/css/rule.js +22 -0
  47. data/src/css/sizzle.js +717 -0
  48. data/src/css/stylesheet.js +52 -0
  49. data/src/dom/attr.js +55 -0
  50. data/src/dom/cdatasection.js +31 -0
  51. data/src/dom/characterdata.js +119 -0
  52. data/src/dom/comment.js +30 -0
  53. data/src/dom/doctype.js +9 -0
  54. data/src/dom/document.js +553 -0
  55. data/src/dom/dom.js +134 -0
  56. data/src/dom/element.js +217 -0
  57. data/src/dom/entities.js +273 -0
  58. data/src/dom/exception.js +28 -0
  59. data/src/dom/fragment.js +37 -0
  60. data/src/dom/implementation.js +602 -0
  61. data/src/dom/instruction.js +51 -0
  62. data/src/dom/namednodemap.js +374 -0
  63. data/src/dom/namespace.js +50 -0
  64. data/src/dom/node.js +618 -0
  65. data/src/dom/nodelist.js +195 -0
  66. data/src/dom/parser.js +1207 -0
  67. data/src/dom/text.js +73 -0
  68. data/src/event/event.js +39 -0
  69. data/src/event/mouseevent.js +4 -0
  70. data/src/event/uievent.js +8 -0
  71. data/src/html/a.js +110 -0
  72. data/src/html/anchor.js +80 -0
  73. data/src/html/area.js +57 -0
  74. data/src/html/base.js +26 -0
  75. data/src/html/blockquote-q.js +19 -0
  76. data/src/html/body.js +19 -0
  77. data/src/html/button.js +21 -0
  78. data/src/html/canvas.js +14 -0
  79. data/src/html/col-colgroup.js +49 -0
  80. data/src/html/collection.js +72 -0
  81. data/src/html/cookie.js +151 -0
  82. data/src/html/del-ins.js +25 -0
  83. data/src/html/div.js +28 -0
  84. data/src/html/document.js +359 -0
  85. data/src/html/element.js +380 -0
  86. data/src/html/fieldset.js +19 -0
  87. data/src/html/form.js +484 -0
  88. data/src/html/frame.js +89 -0
  89. data/src/html/frameset.js +25 -0
  90. data/src/html/head.js +44 -0
  91. data/src/html/html.js +0 -0
  92. data/src/html/htmlparser.js +340 -0
  93. data/src/html/iframe.js +26 -0
  94. data/src/html/image.js +0 -0
  95. data/src/html/img.js +62 -0
  96. data/src/html/input-elements.js +307 -0
  97. data/src/html/input.js +65 -0
  98. data/src/html/label.js +26 -0
  99. data/src/html/legend.js +19 -0
  100. data/src/html/link.js +82 -0
  101. data/src/html/map.js +22 -0
  102. data/src/html/meta.js +37 -0
  103. data/src/html/object.js +89 -0
  104. data/src/html/optgroup.js +25 -0
  105. data/src/html/option.js +97 -0
  106. data/src/html/param.js +38 -0
  107. data/src/html/script.js +122 -0
  108. data/src/html/select.js +129 -0
  109. data/src/html/style.js +31 -0
  110. data/src/html/table.js +199 -0
  111. data/src/html/tbody-thead-tfoot.js +91 -0
  112. data/src/html/td-th.js +18 -0
  113. data/src/html/textarea.js +25 -0
  114. data/src/html/title.js +20 -0
  115. data/src/html/tr.js +114 -0
  116. data/src/intro.js +141 -0
  117. data/src/outro.js +70 -0
  118. data/src/parser/html5.detailed.js +10762 -0
  119. data/src/parser/html5.min.js +503 -0
  120. data/src/parser/html5.pretty.js +10815 -0
  121. data/src/parser/intro.js +42 -0
  122. data/src/parser/outro.js +9 -0
  123. data/src/platform/core.js +323 -0
  124. data/src/platform/johnson.js +479 -0
  125. data/src/platform/rhino.js +327 -0
  126. data/src/platform/static/intro.js +41 -0
  127. data/src/platform/static/outro.js +30 -0
  128. data/src/profile/aop.js +238 -0
  129. data/src/profile/profile.js +402 -0
  130. data/src/serializer/xml.js +21 -0
  131. data/src/svg/animatedstring.js +25 -0
  132. data/src/svg/document.js +25 -0
  133. data/src/svg/element.js +22 -0
  134. data/src/svg/locatable.js +17 -0
  135. data/src/svg/rect.js +18 -0
  136. data/src/svg/rectelement.js +24 -0
  137. data/src/svg/stylable.js +49 -0
  138. data/src/svg/svgelement.js +22 -0
  139. data/src/svg/transformable.js +15 -0
  140. data/src/window/css.js +15 -0
  141. data/src/window/dialog.js +16 -0
  142. data/src/window/document.js +28 -0
  143. data/src/window/event.js +262 -0
  144. data/src/window/history.js +62 -0
  145. data/src/window/location.js +138 -0
  146. data/src/window/navigator.js +48 -0
  147. data/src/window/screen.js +53 -0
  148. data/src/window/timer.js +21 -0
  149. data/src/window/window.js +284 -0
  150. data/src/window/xhr.js +127 -0
  151. data/src/xpath/expression.js +49 -0
  152. data/src/xpath/implementation.js +2482 -0
  153. data/src/xpath/result.js +67 -0
  154. data/src/xpath/util.js +551 -0
  155. data/src/xpath/xmltoken.js +149 -0
  156. data/src/xslt/COPYING +34 -0
  157. data/src/xslt/ajaxslt-0.8.1/AUTHORS +1 -0
  158. data/src/xslt/ajaxslt-0.8.1/ChangeLog +136 -0
  159. data/src/xslt/ajaxslt-0.8.1/Makefile +49 -0
  160. data/src/xslt/ajaxslt-0.8.1/README +102 -0
  161. data/src/xslt/ajaxslt-0.8.1/TODO +15 -0
  162. data/src/xslt/ajaxslt-0.8.1/dom.js +566 -0
  163. data/src/xslt/ajaxslt-0.8.1/dom_unittest.html +24 -0
  164. data/src/xslt/ajaxslt-0.8.1/dom_unittest.js +131 -0
  165. data/src/xslt/ajaxslt-0.8.1/simplelog.js +79 -0
  166. data/src/xslt/ajaxslt-0.8.1/test/xpath.html +18 -0
  167. data/src/xslt/ajaxslt-0.8.1/test/xpath_script.js +45 -0
  168. data/src/xslt/ajaxslt-0.8.1/test/xslt.html +58 -0
  169. data/src/xslt/ajaxslt-0.8.1/test/xslt_script.js +33 -0
  170. data/src/xslt/ajaxslt-0.8.1/unittestsuite.html +26 -0
  171. data/src/xslt/ajaxslt-0.8.1/xmltoken.js +149 -0
  172. data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.html +18 -0
  173. data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.js +811 -0
  174. data/src/xslt/ajaxslt-0.8.1/xpath_unittest.html +39 -0
  175. data/src/xslt/ajaxslt-0.8.1/xpath_unittest.js +557 -0
  176. data/src/xslt/ajaxslt-0.8.1/xpathdebug.js +234 -0
  177. data/src/xslt/ajaxslt-0.8.1/xslt_unittest.html +138 -0
  178. data/src/xslt/ajaxslt-0.8.1/xslt_unittest.js +68 -0
  179. data/src/xslt/implementation.js +625 -0
  180. data/src/xslt/processor.js +37 -0
  181. data/src/xslt/util.js +449 -0
  182. data/test/foo.html +8 -0
  183. data/test/foo.js +40 -0
  184. data/test/jquery.js +6002 -0
  185. data/test/x.js +1 -0
  186. data/test/y.js +1 -0
  187. metadata +245 -14
@@ -0,0 +1,52 @@
1
+ /*
2
+ * CSSStyleSheet - DOM Level 2
3
+ */
4
+ var CSSStyleSheet = function(options){
5
+ var $cssRules,
6
+ $disabled = options.disabled?options.disabled:false,
7
+ $href = options.href?options.href:null,
8
+ $parentStyleSheet = options.parentStyleSheet?options.parentStyleSheet:null,
9
+ $title = options.title?options.title:"",
10
+ $type = "text/css";
11
+
12
+ function parseStyleSheet(text){
13
+ $debug("parsing css");
14
+ //this is pretty ugly, but text is the entire text of a stylesheet
15
+ var cssRules = [];
16
+ if (!text) text = "";
17
+ text = trim(text.replace(/\/\*(\r|\n|.)*\*\//g,""));
18
+ // TODO: @import ?
19
+ var blocks = text.split("}");
20
+ blocks.pop();
21
+ var i, len = blocks.length;
22
+ var definition_block, properties, selectors;
23
+ for (i=0; i<len; i++){
24
+ definition_block = blocks[i].split("{");
25
+ if(definition_block.length === 2){
26
+ selectors = definition_block[0].split(",");
27
+ for(var j=0;j<selectors.length;j++){
28
+ cssRules.push(new CSSRule({
29
+ selectorText:selectors[j],
30
+ cssText:definition_block[1]
31
+ }));
32
+ }
33
+ __setArray__($cssRules, cssRules);
34
+ }
35
+ }
36
+ };
37
+ parseStyleSheet(options.text);
38
+ return __extend__(this, {
39
+ get cssRules(){return $cssRules;},
40
+ get rule(){return $cssRules;},//IE - may be deprecated
41
+ get href(){return $href;},
42
+ get parentStyleSheet(){return $parentStyleSheet;},
43
+ get title(){return $title;},
44
+ get type(){return $type;},
45
+ addRule: function(selector, style, index){/*TODO*/},
46
+ deleteRule: function(index){/*TODO*/},
47
+ insertRule: function(rule, index){/*TODO*/},
48
+ removeRule: function(index){this.deleteRule(index);}//IE - may be deprecated
49
+ });
50
+ };
51
+
52
+ // $w.CSSStyleSheet = CSSStyleSheet;
data/src/dom/attr.js ADDED
@@ -0,0 +1,55 @@
1
+ $debug("Defining Attr");
2
+ /*
3
+ * Attr - DOM Level 2
4
+ */
5
+ /**
6
+ * @class DOMAttr - The Attr interface represents an attribute in an Element object
7
+ * @extends DOMNode
8
+ * @author Jon van Noort (jon@webarcana.com.au)
9
+ * @param ownerDocument : DOMDocument - The Document object associated with this node.
10
+ */
11
+ var DOMAttr = function(ownerDocument) {
12
+ this.DOMNode = DOMNode;
13
+ this.DOMNode(ownerDocument);
14
+
15
+ this.ownerElement = null; // set when Attr is added to NamedNodeMap
16
+ };
17
+ DOMAttr.prototype = new DOMNode;
18
+ __extend__(DOMAttr.prototype, {
19
+ // the name of this attribute
20
+ get name(){
21
+ return this.nodeName;
22
+ },
23
+ set name(name){
24
+ this.nodeName = name;
25
+ },
26
+ // the value of the attribute is returned as a string
27
+ get value(){
28
+ return this.nodeValue;
29
+ },
30
+ set value(value){
31
+ // throw Exception if Attribute is readonly
32
+ if (__ownerDocument__(this).implementation.errorChecking && this._readonly) {
33
+ throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
34
+ }
35
+ // delegate to node
36
+ this.nodeValue = value;
37
+ },
38
+ get specified(){
39
+ return (this!==null&&this!=undefined);
40
+ },
41
+ get nodeType(){
42
+ return DOMNode.ATTRIBUTE_NODE;
43
+ },
44
+ get xml(){
45
+ if(this.nodeValue)
46
+ return ' '+this.nodeName + '="' + __escapeXML__(this.nodeValue+"") + '"';
47
+ else
48
+ return '';
49
+ },
50
+ toString : function(){
51
+ return "Attr #" + this._id + " " + this.name;
52
+ }
53
+ });
54
+
55
+ // $w.Attr = DOMAttr;
@@ -0,0 +1,31 @@
1
+ $debug("Defining CDATASection");
2
+ /*
3
+ * CDATASection - DOM Level 2
4
+ */
5
+ /**
6
+ * @class DOMCDATASection - CDATA sections are used to escape blocks of text containing characters that would otherwise be regarded as markup.
7
+ * The only delimiter that is recognized in a CDATA section is the "\]\]\>" string that ends the CDATA section
8
+ * @extends DOMCharacterData
9
+ * @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
10
+ * @param ownerDocument : DOMDocument - The Document object associated with this node.
11
+ */
12
+ var DOMCDATASection = function(ownerDocument) {
13
+ this.DOMText = DOMText;
14
+ this.DOMText(ownerDocument);
15
+
16
+ this.nodeName = "#cdata-section";
17
+ };
18
+ DOMCDATASection.prototype = new DOMText;
19
+ __extend__(DOMCDATASection.prototype,{
20
+ get nodeType(){
21
+ return DOMNode.CDATA_SECTION_NODE;
22
+ },
23
+ get xml(){
24
+ return "<![CDATA[" + this.nodeValue + "]]>";
25
+ },
26
+ toString : function(){
27
+ return "CDATA #"+this._id;
28
+ }
29
+ });
30
+
31
+ // $w.CDATASection = DOMCDATASection;
@@ -0,0 +1,119 @@
1
+ $debug("Defining CharacterData");
2
+ /*
3
+ * CharacterData - DOM Level 2
4
+ */
5
+ /**
6
+ * @class DOMCharacterData - parent abstract class for DOMText and DOMComment
7
+ * @extends DOMNode
8
+ * @author Jon van Noort (jon@webarcana.com.au)
9
+ * @param ownerDocument : DOMDocument - The Document object associated with this node.
10
+ */
11
+ var DOMCharacterData = function(ownerDocument) {
12
+ this.DOMNode = DOMNode;
13
+ this.DOMNode(ownerDocument);
14
+ };
15
+ DOMCharacterData.prototype = new DOMNode;
16
+ __extend__(DOMCharacterData.prototype,{
17
+ get data(){
18
+ return this.nodeValue;
19
+ },
20
+ set data(data){
21
+ this.nodeValue = data;
22
+ },
23
+ get length(){return this.nodeValue.length;},
24
+ appendData: function(arg){
25
+ // throw Exception if DOMCharacterData is readonly
26
+ if (__ownerDocument__(this).implementation.errorChecking && this._readonly) {
27
+ throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
28
+ }
29
+ // append data
30
+ this.data = "" + this.data + arg;
31
+ },
32
+ deleteData: function(offset, count){
33
+ // throw Exception if DOMCharacterData is readonly
34
+ if (__ownerDocument__(this).implementation.errorChecking && this._readonly) {
35
+ throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
36
+ }
37
+ if (this.data) {
38
+ // throw Exception if offset is negative or greater than the data length,
39
+ if (__ownerDocument__(this).implementation.errorChecking &&
40
+ ((offset < 0) || (offset > this.data.length) || (count < 0))) {
41
+ throw(new DOMException(DOMException.INDEX_SIZE_ERR));
42
+ }
43
+
44
+ // delete data
45
+ if(!count || (offset + count) > this.data.length) {
46
+ this.data = this.data.substring(0, offset);
47
+ }else {
48
+ this.data = this.data.substring(0, offset).
49
+ concat(this.data.substring(offset + count));
50
+ }
51
+ }
52
+ },
53
+ insertData: function(offset, arg){
54
+ // throw Exception if DOMCharacterData is readonly
55
+ if(__ownerDocument__(this).implementation.errorChecking && this._readonly){
56
+ throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
57
+ }
58
+
59
+ if(this.data){
60
+ // throw Exception if offset is negative or greater than the data length,
61
+ if (__ownerDocument__(this).implementation.errorChecking &&
62
+ ((offset < 0) || (offset > this.data.length))) {
63
+ throw(new DOMException(DOMException.INDEX_SIZE_ERR));
64
+ }
65
+
66
+ // insert data
67
+ this.data = this.data.substring(0, offset).concat(arg, this.data.substring(offset));
68
+ }else {
69
+ // throw Exception if offset is negative or greater than the data length,
70
+ if (__ownerDocument__(this).implementation.errorChecking && (offset != 0)) {
71
+ throw(new DOMException(DOMException.INDEX_SIZE_ERR));
72
+ }
73
+
74
+ // set data
75
+ this.data = arg;
76
+ }
77
+ },
78
+ replaceData: function(offset, count, arg){
79
+ // throw Exception if DOMCharacterData is readonly
80
+ if (__ownerDocument__(this).implementation.errorChecking && this._readonly) {
81
+ throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
82
+ }
83
+
84
+ if (this.data) {
85
+ // throw Exception if offset is negative or greater than the data length,
86
+ if (__ownerDocument__(this).implementation.errorChecking &&
87
+ ((offset < 0) || (offset > this.data.length) || (count < 0))) {
88
+ throw(new DOMException(DOMException.INDEX_SIZE_ERR));
89
+ }
90
+
91
+ // replace data
92
+ this.data = this.data.substring(0, offset).
93
+ concat(arg, this.data.substring(offset + count));
94
+ }else {
95
+ // set data
96
+ this.data = arg;
97
+ }
98
+ },
99
+ substringData: function(offset, count){
100
+ var ret = null;
101
+ if (this.data) {
102
+ // throw Exception if offset is negative or greater than the data length,
103
+ // or the count is negative
104
+ if (__ownerDocument__(this).implementation.errorChecking &&
105
+ ((offset < 0) || (offset > this.data.length) || (count < 0))) {
106
+ throw(new DOMException(DOMException.INDEX_SIZE_ERR));
107
+ }
108
+ // if count is not specified
109
+ if (!count) {
110
+ ret = this.data.substring(offset); // default to 'end of string'
111
+ }else{
112
+ ret = this.data.substring(offset, offset + count);
113
+ }
114
+ }
115
+ return ret;
116
+ }
117
+ });
118
+
119
+ // $w.CharacterData = DOMCharacterData;
@@ -0,0 +1,30 @@
1
+ $debug("Defining Comment");
2
+ /*
3
+ * Comment - DOM Level 2
4
+ */
5
+ /**
6
+ * @class DOMComment - This represents the content of a comment, i.e., all the characters between the starting '<!--' and ending '-->'
7
+ * @extends DOMCharacterData
8
+ * @author Jon van Noort (jon@webarcana.com.au)
9
+ * @param ownerDocument : DOMDocument - The Document object associated with this node.
10
+ */
11
+ var DOMComment = function(ownerDocument) {
12
+ this.DOMCharacterData = DOMCharacterData;
13
+ this.DOMCharacterData(ownerDocument);
14
+
15
+ this.nodeName = "#comment";
16
+ };
17
+ DOMComment.prototype = new DOMCharacterData;
18
+ __extend__(DOMComment.prototype, {
19
+ get nodeType(){
20
+ return DOMNode.COMMENT_NODE;
21
+ },
22
+ get xml(){
23
+ return "<!--" + this.nodeValue + "-->";
24
+ },
25
+ toString : function(){
26
+ return "Comment #"+this._id;
27
+ }
28
+ });
29
+
30
+ // $w.Comment = DOMComment;
@@ -0,0 +1,9 @@
1
+ $debug("Defining DocumentType");
2
+ ;/*
3
+ * DocumentType - DOM Level 2
4
+ */
5
+ var DOMDocumentType = function() {
6
+ $error("DOMDocumentType.constructor(): Not Implemented" );
7
+ };
8
+
9
+ // $w.DocumentType = DOMDocumentType;
@@ -0,0 +1,553 @@
1
+ $debug("Defining Document");
2
+ /**
3
+ * @class DOMDocument - The Document interface represents the entire HTML
4
+ * or XML document. Conceptually, it is the root of the document tree,
5
+ * and provides the primary access to the document's data.
6
+ *
7
+ * @extends DOMNode
8
+ * @author Jon van Noort (jon@webarcana.com.au)
9
+ * @param implementation : DOMImplementation - the creator Implementation
10
+ */
11
+ var DOMDocument = function(implementation, docParentWindow) {
12
+ // if (!( implementation === undefined && docParentWindow == undefined)) {
13
+ // print("DD",implementation, docParentWindow, docParentWindow && docParentWindow.isInner);
14
+ // }
15
+ //$log("\tcreating dom document");
16
+ this.DOMNode = DOMNode;
17
+ this.DOMNode(this);
18
+
19
+ this.doctype = null; // The Document Type Declaration (see DocumentType) associated with this document
20
+ this.implementation = implementation; // The DOMImplementation object that handles this document.
21
+
22
+ // "private" variable providing the read-only document.parentWindow property
23
+ this._parentWindow = docParentWindow;
24
+ try {
25
+ if (docParentWindow.$thisWindowsProxyObject)
26
+ this._parentWindow = docParentWindow.$thisWindowsProxyObject;
27
+ } catch(e){}
28
+
29
+ this.nodeName = "#document";
30
+ this._id = 0;
31
+ this._lastId = 0;
32
+ this._parseComplete = false; // initially false, set to true by parser
33
+ this._url = "";
34
+
35
+ this.ownerDocument = null;
36
+
37
+ this._performingImportNodeOperation = false;
38
+ };
39
+ DOMDocument.prototype = new DOMNode;
40
+ __extend__(DOMDocument.prototype, {
41
+
42
+ addEventListener : function(type, fn){ __addEventListener__(this, type, fn); },
43
+ removeEventListener : function(type){ __removeEventListener__(this, type); },
44
+ attachEvent : function(type, fn){ __addEventListener__(this, type, fn); },
45
+ detachEvent : function(type){ __removeEventListener__(this, type); },
46
+ dispatchEvent : function(event, bubbles){ __dispatchEvent__(this, event, bubbles); },
47
+
48
+ toString : function(){
49
+ return '[object DOMDocument]';
50
+ },
51
+ addEventListener : function(){ this._parentWindow.addEventListener.apply(this, arguments); },
52
+ removeEventListener : function(){ this._parentWindow.removeEventListener.apply(this, arguments); },
53
+ attachEvent : function(){ this._parentWindow.addEventListener.apply(this, arguments); },
54
+ detachEvent : function(){ this._parentWindow.removeEventListener.apply(this, arguments); },
55
+ dispatchEvent : function(){ this._parentWindow.dispatchEvent.apply(this, arguments); },
56
+
57
+ get styleSheets(){
58
+ return [];/*TODO*/
59
+ },
60
+ get all(){
61
+ return this.getElementsByTagName("*");
62
+ },
63
+ get documentElement(){
64
+ var i, length = this.childNodes?this.childNodes.length:0;
65
+ for(i=0;i<length;i++){
66
+ if(this.childNodes[i].nodeType == DOMNode.ELEMENT_NODE){
67
+ return this.childNodes[i];
68
+ }
69
+ }
70
+ return null;
71
+ },
72
+ get parentWindow(){
73
+ return this._parentWindow;
74
+ },
75
+ loadXML : function(xmlString) {
76
+ // create SAX Parser
77
+ var parser = new XMLP(xmlString+'');
78
+
79
+ // create DOM Document
80
+ if(this === $document){
81
+ $debug("Setting internal window.document");
82
+ $document = this;
83
+ }
84
+ // populate Document with Parsed Nodes
85
+ try {
86
+ // make sure thid document object is empty before we try to load ...
87
+ this.childNodes = new DOMNodeList(this, this);
88
+ this.firstChild = null;
89
+ this.lastChild = null;
90
+ this.attributes = new DOMNamedNodeMap(this, this);
91
+ this._namespaces = new DOMNamespaceNodeMap(this, this);
92
+ this._readonly = false;
93
+
94
+ __parseLoop__(this.implementation, this, parser);
95
+ } catch (e) {
96
+ $error(e);
97
+ }
98
+
99
+ // set parseComplete flag, (Some validation Rules are relaxed if this is false)
100
+ this._parseComplete = true;
101
+ return this;
102
+ },
103
+ load: function(url,xhr_options){
104
+ $debug("Loading url into DOM Document: "+ url + " - (Asynch? "+this._parentWindow.document.async+")");
105
+ var scripts, _this = this;
106
+ var xhr;
107
+ if (url == "about:blank"){
108
+ xhr = ({
109
+ open: function(){},
110
+ send: function(){
111
+ this.responseText = "<html><head><title></title></head><body></body></html>";
112
+ this.onreadystatechange();
113
+ },
114
+ status: 200
115
+ });
116
+ } else if (url.indexOf("data:") === 0) {
117
+ url = url.slice(5);
118
+ var fields = url.split(",");
119
+ var content = fields[1];
120
+ var fields = fields[0].split(";");
121
+ if(fields[1] === "base64" || (fields[1] && fields[1].indexOf("charset=") === 0 && fields[2] === "base64" ) ) {
122
+ content = Base64.decode(content);
123
+ } else {
124
+ content = unescape(content);
125
+ }
126
+ if(fields[0] === "text/html") {
127
+ } else if(fields[0] === "image/png") {
128
+ throw new Error("png");
129
+ } else {
130
+ content = "<html><head><title></title></head><body>"+content+"</body></html>";
131
+ }
132
+ xhr = ({
133
+ open: function(){},
134
+ send: function(){
135
+ var self = this;
136
+ setTimeout(function(){
137
+ self.responseText = content;
138
+ self.onreadystatechange();
139
+ },0);
140
+ },
141
+ status: 200
142
+ });
143
+ } else {
144
+ xhr = new _this._parentWindow.XMLHttpRequest();
145
+ }
146
+ xhr_options = xhr_options || {};
147
+ var method = (xhr_options.method || "GET").toUpperCase();
148
+ xhr.open(method, url, this._parentWindow.document.async);
149
+ // FIXME: not all XHRs have this right now
150
+ xhr.setRequestHeader && xhr.setRequestHeader('Content-Type', xhr_options["Content-Type"] || 'application/x-www-form-urlencoded');
151
+ xhr.setRequestHeader && xhr.setRequestHeader('Cookie', _this.cookie);
152
+ // print("rf",xhr_options["referer"]);
153
+ xhr.setRequestHeader && xhr_options["referer"] && xhr.setRequestHeader('Referer', xhr_options["referer"]);
154
+ // print(_this._parentWindow.location.href);
155
+ xhr.onreadystatechange = function(){
156
+ // print(url,xhr.status,xhr.responseText);
157
+ if(xhr.status === 302) {
158
+ // print(302,xhr.responseHeaders["location"]);
159
+ _this.load(xhr.responseHeaders["location"],{});
160
+ return;
161
+ }
162
+ if (xhr.status != 200) {
163
+ $warn("Could not retrieve XHR content from " + url + ": status code " + xhr.status);
164
+ _this.loadXML(
165
+ "<html><head></head><body>"+
166
+ "<h1>No File</h1>"+
167
+ "</body></html>");
168
+ } else {
169
+ try{
170
+ _this.loadXML(xhr.responseText);
171
+ _this.__original_text__ = xhr.responseText;
172
+ if(xhr.responseHeaders && xhr.responseHeaders["set-cookie"]) {
173
+ try {
174
+ _this.cookie = xhr.responseHeaders["set-cookie"];
175
+ } catch(e) {
176
+ $error("could not set cookie: "+e);
177
+ }
178
+ }
179
+ if(xhr.responseHeaders) {
180
+ var h = _this.__headers__ = {};
181
+ for(var key in xhr.responseHeaders) {
182
+ h[key] = xhr.responseHeaders[key];
183
+ }
184
+ }
185
+ }catch(e){
186
+ $error("Error Parsing XML - ",e);
187
+ _this.loadXML(
188
+ "<html><head></head><body>"+
189
+ "<h1>Parse Error</h1>"+
190
+ "<p>"+e.toString()+"</p>"+
191
+ "</body></html>");
192
+ }
193
+ }
194
+ _this._url = url;
195
+
196
+ if ( url != "about:blank" ) {
197
+ $info("Sucessfully loaded document at "+url);
198
+ }
199
+
200
+ // first fire body-onload event
201
+ var bodyLoad = _this.createEvent();
202
+ bodyLoad.initEvent("load");
203
+ try { // assume <body> element, but just in case....
204
+ _this.getElementsByTagName('body')[0].
205
+ dispatchEvent( bodyLoad, false );
206
+ } catch (e){;}
207
+
208
+ // then fire this onload event
209
+ //event = _this.createEvent();
210
+ //event.initEvent("load");
211
+ //_this.dispatchEvent( event, false );
212
+
213
+ //also use DOMContentLoaded event
214
+ var domContentLoaded = _this.createEvent();
215
+ domContentLoaded.initEvent("DOMContentLoaded");
216
+ _this.dispatchEvent( domContentLoaded, false );
217
+
218
+ //finally fire the window.onload event
219
+ if(_this === _this._parentWindow.document){
220
+ var windowLoad = _this.createEvent();
221
+ windowLoad.initEvent("load", false, false);
222
+ _this._parentWindow.dispatchEvent( windowLoad, false );
223
+ }
224
+
225
+ };
226
+ xhr.send(xhr_options["data"]);
227
+ },
228
+ createEvent : function(eventType){
229
+ var event;
230
+ if(eventType === "UIEvents"){ event = new UIEvent();}
231
+ else if(eventType === "MouseEvents"){ event = new MouseEvent();}
232
+ else{ event = new Event(); }
233
+ return event;
234
+ },
235
+ createExpression : function(xpath, nsuriMap){
236
+ return new XPathExpression(xpath, nsuriMap);
237
+ },
238
+ createElement : function(tagName) {
239
+ //$debug("DOMDocument.createElement( "+tagName+" )");
240
+ // throw Exception if the tagName string contains an illegal character
241
+ if (__ownerDocument__(this).implementation.errorChecking
242
+ && (!__isValidName__(tagName))) {
243
+ throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
244
+ }
245
+
246
+ // create DOMElement specifying 'this' as ownerDocument
247
+ var node = new DOMElement(this);
248
+
249
+ // assign values to properties (and aliases)
250
+ node.tagName = tagName;
251
+
252
+ return node;
253
+ },
254
+ createDocumentFragment : function() {
255
+ // create DOMDocumentFragment specifying 'this' as ownerDocument
256
+ var node = new DOMDocumentFragment(this);
257
+ return node;
258
+ },
259
+ createTextNode: function(data) {
260
+ // create DOMText specifying 'this' as ownerDocument
261
+ var node = new DOMText(this);
262
+
263
+ // assign values to properties (and aliases)
264
+ node.data = data;
265
+
266
+ return node;
267
+ },
268
+ createComment : function(data) {
269
+ // create DOMComment specifying 'this' as ownerDocument
270
+ var node = new DOMComment(this);
271
+
272
+ // assign values to properties (and aliases)
273
+ node.data = data;
274
+
275
+ return node;
276
+ },
277
+ createCDATASection : function(data) {
278
+ // create DOMCDATASection specifying 'this' as ownerDocument
279
+ var node = new DOMCDATASection(this);
280
+
281
+ // assign values to properties (and aliases)
282
+ node.data = data;
283
+
284
+ return node;
285
+ },
286
+ createProcessingInstruction : function(target, data) {
287
+ // throw Exception if the target string contains an illegal character
288
+ //$log("DOMDocument.createProcessingInstruction( "+target+" )");
289
+ if (__ownerDocument__(this).implementation.errorChecking
290
+ && (!__isValidName__(target))) {
291
+ throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
292
+ }
293
+
294
+ // create DOMProcessingInstruction specifying 'this' as ownerDocument
295
+ var node = new DOMProcessingInstruction(this);
296
+
297
+ // assign values to properties (and aliases)
298
+ node.target = target;
299
+ node.data = data;
300
+
301
+ return node;
302
+ },
303
+ createAttribute : function(name) {
304
+ // throw Exception if the name string contains an illegal character
305
+ //$log("DOMDocument.createAttribute( "+target+" )");
306
+ if (__ownerDocument__(this).implementation.errorChecking
307
+ && (!__isValidName__(name))) {
308
+ throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
309
+ }
310
+
311
+ // create DOMAttr specifying 'this' as ownerDocument
312
+ var node = new DOMAttr(this);
313
+
314
+ // assign values to properties (and aliases)
315
+ node.name = name;
316
+
317
+ return node;
318
+ },
319
+ createElementNS : function(namespaceURI, qualifiedName) {
320
+ //$log("DOMDocument.createElementNS( "+namespaceURI+", "+qualifiedName+" )");
321
+ // test for exceptions
322
+ if (__ownerDocument__(this).implementation.errorChecking) {
323
+ // throw Exception if the Namespace is invalid
324
+ if (!__isValidNamespace__(this, namespaceURI, qualifiedName)) {
325
+ throw(new DOMException(DOMException.NAMESPACE_ERR));
326
+ }
327
+
328
+ // throw Exception if the qualifiedName string contains an illegal character
329
+ if (!__isValidName__(qualifiedName)) {
330
+ throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
331
+ }
332
+ }
333
+
334
+ var qname = __parseQName__(qualifiedName);
335
+
336
+ // create DOMElement specifying 'this' as ownerDocument
337
+ if(namespaceURI === "http://www.w3.org/2000/svg"){
338
+ var node = SVGDocument.prototype.createElement.call( this, qname.localName );
339
+ } else {
340
+ var node = new DOMElement(this);
341
+ }
342
+
343
+ // assign values to properties (and aliases)
344
+ node.namespaceURI = namespaceURI;
345
+ node.prefix = qname.prefix;
346
+ node.localName = qname.localName;
347
+ node.tagName = qualifiedName;
348
+
349
+ return node;
350
+ },
351
+ createAttributeNS : function(namespaceURI, qualifiedName) {
352
+ // test for exceptions
353
+ if (__ownerDocument__(this).implementation.errorChecking) {
354
+ // throw Exception if the Namespace is invalid
355
+ if (!__isValidNamespace__(this, namespaceURI, qualifiedName, true)) {
356
+ throw(new DOMException(DOMException.NAMESPACE_ERR));
357
+ }
358
+
359
+ // throw Exception if the qualifiedName string contains an illegal character
360
+ if (!__isValidName__(qualifiedName)) {
361
+ throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
362
+ }
363
+ }
364
+
365
+ // create DOMAttr specifying 'this' as ownerDocument
366
+ var node = new DOMAttr(this);
367
+ var qname = __parseQName__(qualifiedName);
368
+
369
+ // assign values to properties (and aliases)
370
+ node.namespaceURI = namespaceURI;
371
+ node.prefix = qname.prefix;
372
+ node.localName = qname.localName;
373
+ node.name = qualifiedName;
374
+ node.nodeValue = "";
375
+
376
+ return node;
377
+ },
378
+ createNamespace : function(qualifiedName) {
379
+ // create DOMNamespace specifying 'this' as ownerDocument
380
+ var node = new DOMNamespace(this);
381
+ var qname = __parseQName__(qualifiedName);
382
+
383
+ // assign values to properties (and aliases)
384
+ node.prefix = qname.prefix;
385
+ node.localName = qname.localName;
386
+ node.name = qualifiedName;
387
+ node.nodeValue = "";
388
+
389
+ return node;
390
+ },
391
+ /** from David Flanagan's JavaScript - The Definitive Guide
392
+ *
393
+ * @param {String} xpathText
394
+ * The string representing the XPath expression to evaluate.
395
+ * @param {Node} contextNode
396
+ * The node in this document against which the expression is to
397
+ * be evaluated.
398
+ * @param {Function} nsuriMapper
399
+ * A function that will map from namespace prefix to to a full
400
+ * namespace URL or null if no such mapping is required.
401
+ * @param {Number} resultType
402
+ * Specifies the type of object expected as a result, using
403
+ * XPath conversions to coerce the result. Possible values for
404
+ * type are the constrainsts defined by the XPathResult object.
405
+ * (null if not required)
406
+ * @param {XPathResult} result
407
+ * An XPathResult object to be reused or null
408
+ * if you want a new XPathResult object to be created.
409
+ * @returns {XPathResult} result
410
+ * A XPathResult object representing the evaluation of the
411
+ * expression against the given context node.
412
+ * @throws {Exception} e
413
+ * This method may throw an exception if the xpathText contains
414
+ * a syntax error, if the expression cannot be converted to the
415
+ * desired resultType, if the expression contains namespaces
416
+ * that nsuriMapper cannot resolve, or if contextNode is of the
417
+ * wrong type or is not assosciated with this document.
418
+ * @seealso
419
+ * Document.evaluate
420
+ */
421
+ evaluate: function(xpathText, contextNode, nsuriMapper, resultType, result){
422
+ try {
423
+ return new XPathExpression(xpathText, contextNode, nsuriMapper, resultType, result).evaluate();
424
+ } catch(e) {
425
+ print("xpath failure: " + e);
426
+ throw e;
427
+ }
428
+
429
+ },
430
+ getElementById : function(elementId) {
431
+ var retNode = null,
432
+ node;
433
+ // loop through all Elements in the 'all' collection
434
+ var all = this.all;
435
+ for (var i=0; i < all.length; i++) {
436
+ node = all[i];
437
+ // if id matches & node is alive (ie, connected (in)directly to the documentElement)
438
+ if (node.id == elementId) {
439
+ if((__ownerDocument__(node).documentElement._id == this.documentElement._id)){
440
+ retNode = node;
441
+ //$log("Found node with id = " + node.id);
442
+ break;
443
+ }
444
+ }
445
+ }
446
+
447
+ //if(retNode == null){$log("Couldn't find id " + elementId);}
448
+ return retNode;
449
+ },
450
+ normalizeDocument: function(){
451
+ this.documentElement.normalize();
452
+ },
453
+ get nodeType(){
454
+ return DOMNode.DOCUMENT_NODE;
455
+ },
456
+ get xml(){
457
+ //$log("Serializing " + this);
458
+ return this.documentElement.xml;
459
+ },
460
+ toString: function(){
461
+ return "DOMDocument" + (typeof this._url == "string" ? ": " + this._url : "");
462
+ },
463
+ get defaultView(){
464
+ var doc = this;
465
+ return { getComputedStyle: function(elem){
466
+ return doc._parentWindow.getComputedStyle(elem);
467
+ }};
468
+ },
469
+ _genId : function() {
470
+ this._lastId += 1; // increment lastId (to generate unique id)
471
+ return this._lastId;
472
+ }
473
+ });
474
+
475
+
476
+ var __isValidNamespace__ = function(doc, namespaceURI, qualifiedName, isAttribute) {
477
+
478
+ if (doc._performingImportNodeOperation == true) {
479
+ //we're doing an importNode operation (or a cloneNode) - in both cases, there
480
+ //is no need to perform any namespace checking since the nodes have to have been valid
481
+ //to have gotten into the DOM in the first place
482
+ return true;
483
+ }
484
+
485
+ var valid = true;
486
+ // parse QName
487
+ var qName = __parseQName__(qualifiedName);
488
+
489
+
490
+ //only check for namespaces if we're finished parsing
491
+ if (this._parseComplete == true) {
492
+
493
+ // if the qualifiedName is malformed
494
+ if (qName.localName.indexOf(":") > -1 ){
495
+ valid = false;
496
+ }
497
+
498
+ if ((valid) && (!isAttribute)) {
499
+ // if the namespaceURI is not null
500
+ if (!namespaceURI) {
501
+ valid = false;
502
+ }
503
+ }
504
+
505
+ // if the qualifiedName has a prefix
506
+ if ((valid) && (qName.prefix == "")) {
507
+ valid = false;
508
+ }
509
+
510
+ }
511
+
512
+ // if the qualifiedName has a prefix that is "xml" and the namespaceURI is
513
+ // different from "http://www.w3.org/XML/1998/namespace" [Namespaces].
514
+ if ((valid) && (qName.prefix == "xml") && (namespaceURI != "http://www.w3.org/XML/1998/namespace")) {
515
+ valid = false;
516
+ }
517
+
518
+ return valid;
519
+ };
520
+
521
+ /**
522
+ * @method DOMImplementation._parseQName - parse the qualified name
523
+ * @author Jon van Noort (jon@webarcana.com.au)
524
+ * @param qualifiedName : string - The qualified name
525
+ * @return : QName
526
+ */
527
+ function __parseQName__(qualifiedName) {
528
+ var resultQName = new Object();
529
+
530
+ resultQName.localName = qualifiedName; // unless the qname has a prefix, the local name is the entire String
531
+ resultQName.prefix = "";
532
+
533
+ // split on ':'
534
+ var delimPos = qualifiedName.indexOf(':');
535
+
536
+ if (delimPos > -1) {
537
+ // get prefix
538
+ resultQName.prefix = qualifiedName.substring(0, delimPos);
539
+
540
+ // get localName
541
+ resultQName.localName = qualifiedName.substring(delimPos +1, qualifiedName.length);
542
+ }
543
+
544
+ return resultQName;
545
+ };
546
+
547
+ // $w.Document = DOMDocument;
548
+
549
+ // Local Variables:
550
+ // espresso-indent-level:4
551
+ // c-basic-offset:4
552
+ // tab-width:4
553
+ // End: