envjs19 0.3.8.20101029121421

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. data/.jslintrbrc +30 -0
  2. data/.project +17 -0
  3. data/CHANGELOG.rdoc +57 -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 +280 -0
  14. data/README.rdoc +65 -0
  15. data/Rakefile +196 -0
  16. data/Wakefile +11 -0
  17. data/bin/envjsrb +257 -0
  18. data/build.properties +9 -0
  19. data/build.xml +247 -0
  20. data/gm/jquery.js +6002 -0
  21. data/gm/mainx.js +2648 -0
  22. data/gm/sensx.js +135 -0
  23. data/gm/t.js +6 -0
  24. data/gm/x.html +76 -0
  25. data/htmlparser/BrowserTreeBuilder.java +456 -0
  26. data/htmlparser/README +34 -0
  27. data/htmlparser/build.sh +38 -0
  28. data/jsl/jsl +0 -0
  29. data/jsl/jsl.default.conf +129 -0
  30. data/jsl/jsl.exe +0 -0
  31. data/lib/envjs.rb +35 -0
  32. data/lib/envjs/event_loop.js +206 -0
  33. data/lib/envjs/net.rb +3 -0
  34. data/lib/envjs/net/cgi.rb +94 -0
  35. data/lib/envjs/net/file.rb +69 -0
  36. data/lib/envjs/options.rb +11 -0
  37. data/lib/envjs/runtime.rb +346 -0
  38. data/lib/envjs/tempfile.rb +24 -0
  39. data/licenses/GPL-LICENSE.txt +278 -0
  40. data/licenses/MIT-LICENSE.txt +20 -0
  41. data/src/base64.js +80 -0
  42. data/src/build.js +6 -0
  43. data/src/cruft/bad.html +24 -0
  44. data/src/cruft/dom.js +606 -0
  45. data/src/cruft/element.js +297 -0
  46. data/src/cruft/good.html +30 -0
  47. data/src/cruft/good.js +32 -0
  48. data/src/cruft/internal.js +81 -0
  49. data/src/cruft/parser.js +458 -0
  50. data/src/css/properties.js +293 -0
  51. data/src/css/rule.js +22 -0
  52. data/src/css/sizzle.js +717 -0
  53. data/src/css/stylesheet.js +52 -0
  54. data/src/dom/attr.js +55 -0
  55. data/src/dom/cdatasection.js +31 -0
  56. data/src/dom/characterdata.js +119 -0
  57. data/src/dom/comment.js +30 -0
  58. data/src/dom/doctype.js +9 -0
  59. data/src/dom/document.js +1023 -0
  60. data/src/dom/dom.js +134 -0
  61. data/src/dom/element.js +217 -0
  62. data/src/dom/entities.js +273 -0
  63. data/src/dom/exception.js +28 -0
  64. data/src/dom/fragment.js +37 -0
  65. data/src/dom/implementation.js +140 -0
  66. data/src/dom/instruction.js +51 -0
  67. data/src/dom/namednodemap.js +374 -0
  68. data/src/dom/namespace.js +50 -0
  69. data/src/dom/node.js +618 -0
  70. data/src/dom/nodelist.js +195 -0
  71. data/src/dom/parser.js +1207 -0
  72. data/src/dom/text.js +73 -0
  73. data/src/event/event.js +47 -0
  74. data/src/event/mouseevent.js +4 -0
  75. data/src/event/uievent.js +8 -0
  76. data/src/html/a.js +110 -0
  77. data/src/html/anchor.js +80 -0
  78. data/src/html/area.js +57 -0
  79. data/src/html/base.js +26 -0
  80. data/src/html/blockquote-q.js +19 -0
  81. data/src/html/body.js +19 -0
  82. data/src/html/button.js +21 -0
  83. data/src/html/canvas.js +14 -0
  84. data/src/html/col-colgroup.js +49 -0
  85. data/src/html/collection.js +72 -0
  86. data/src/html/cookie.js +153 -0
  87. data/src/html/del-ins.js +25 -0
  88. data/src/html/div.js +28 -0
  89. data/src/html/document.js +364 -0
  90. data/src/html/element.js +382 -0
  91. data/src/html/fieldset.js +19 -0
  92. data/src/html/form.js +484 -0
  93. data/src/html/frame.js +89 -0
  94. data/src/html/frameset.js +25 -0
  95. data/src/html/head.js +44 -0
  96. data/src/html/html.js +0 -0
  97. data/src/html/htmlparser.js +340 -0
  98. data/src/html/iframe.js +26 -0
  99. data/src/html/image.js +0 -0
  100. data/src/html/img.js +62 -0
  101. data/src/html/input-elements.js +307 -0
  102. data/src/html/input.js +65 -0
  103. data/src/html/label.js +26 -0
  104. data/src/html/legend.js +19 -0
  105. data/src/html/link.js +82 -0
  106. data/src/html/map.js +22 -0
  107. data/src/html/meta.js +37 -0
  108. data/src/html/object.js +89 -0
  109. data/src/html/optgroup.js +25 -0
  110. data/src/html/option.js +103 -0
  111. data/src/html/param.js +38 -0
  112. data/src/html/script.js +122 -0
  113. data/src/html/select.js +132 -0
  114. data/src/html/style.js +31 -0
  115. data/src/html/table.js +199 -0
  116. data/src/html/tbody-thead-tfoot.js +92 -0
  117. data/src/html/td-th.js +18 -0
  118. data/src/html/textarea.js +31 -0
  119. data/src/html/title.js +20 -0
  120. data/src/html/tr.js +114 -0
  121. data/src/intro.js +141 -0
  122. data/src/outro.js +70 -0
  123. data/src/parser/html5.detailed.js +10762 -0
  124. data/src/parser/html5.min.js +503 -0
  125. data/src/parser/html5.pretty.js +10815 -0
  126. data/src/parser/intro.js +42 -0
  127. data/src/parser/outro.js +9 -0
  128. data/src/platform/core.js +323 -0
  129. data/src/platform/johnson.js +484 -0
  130. data/src/platform/rhino.js +327 -0
  131. data/src/platform/static/intro.js +41 -0
  132. data/src/platform/static/outro.js +30 -0
  133. data/src/profile/aop.js +238 -0
  134. data/src/profile/profile.js +402 -0
  135. data/src/serializer/xml.js +21 -0
  136. data/src/svg/animatedstring.js +25 -0
  137. data/src/svg/document.js +25 -0
  138. data/src/svg/element.js +22 -0
  139. data/src/svg/locatable.js +17 -0
  140. data/src/svg/rect.js +18 -0
  141. data/src/svg/rectelement.js +24 -0
  142. data/src/svg/stylable.js +49 -0
  143. data/src/svg/svgelement.js +22 -0
  144. data/src/svg/transformable.js +15 -0
  145. data/src/window/css.js +15 -0
  146. data/src/window/dialog.js +16 -0
  147. data/src/window/document.js +28 -0
  148. data/src/window/event.js +265 -0
  149. data/src/window/history.js +62 -0
  150. data/src/window/location.js +156 -0
  151. data/src/window/navigator.js +48 -0
  152. data/src/window/screen.js +53 -0
  153. data/src/window/timer.js +21 -0
  154. data/src/window/window.js +284 -0
  155. data/src/window/xhr.js +135 -0
  156. data/src/xpath/expression.js +49 -0
  157. data/src/xpath/implementation.js +2505 -0
  158. data/src/xpath/result.js +67 -0
  159. data/src/xpath/util.js +551 -0
  160. data/src/xpath/xmltoken.js +149 -0
  161. data/src/xslt/COPYING +34 -0
  162. data/src/xslt/ajaxslt-0.8.1/AUTHORS +1 -0
  163. data/src/xslt/ajaxslt-0.8.1/ChangeLog +136 -0
  164. data/src/xslt/ajaxslt-0.8.1/Makefile +49 -0
  165. data/src/xslt/ajaxslt-0.8.1/README +102 -0
  166. data/src/xslt/ajaxslt-0.8.1/TODO +15 -0
  167. data/src/xslt/ajaxslt-0.8.1/dom.js +566 -0
  168. data/src/xslt/ajaxslt-0.8.1/dom_unittest.html +24 -0
  169. data/src/xslt/ajaxslt-0.8.1/dom_unittest.js +131 -0
  170. data/src/xslt/ajaxslt-0.8.1/simplelog.js +79 -0
  171. data/src/xslt/ajaxslt-0.8.1/test/xpath.html +18 -0
  172. data/src/xslt/ajaxslt-0.8.1/test/xpath_script.js +45 -0
  173. data/src/xslt/ajaxslt-0.8.1/test/xslt.html +58 -0
  174. data/src/xslt/ajaxslt-0.8.1/test/xslt_script.js +33 -0
  175. data/src/xslt/ajaxslt-0.8.1/unittestsuite.html +26 -0
  176. data/src/xslt/ajaxslt-0.8.1/xmltoken.js +149 -0
  177. data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.html +18 -0
  178. data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.js +811 -0
  179. data/src/xslt/ajaxslt-0.8.1/xpath_unittest.html +39 -0
  180. data/src/xslt/ajaxslt-0.8.1/xpath_unittest.js +557 -0
  181. data/src/xslt/ajaxslt-0.8.1/xpathdebug.js +234 -0
  182. data/src/xslt/ajaxslt-0.8.1/xslt_unittest.html +138 -0
  183. data/src/xslt/ajaxslt-0.8.1/xslt_unittest.js +68 -0
  184. data/src/xslt/implementation.js +625 -0
  185. data/src/xslt/processor.js +37 -0
  186. data/src/xslt/util.js +449 -0
  187. data/test/base64.js +80 -0
  188. data/test/call-load-test.js +15 -0
  189. data/test/data.js +45 -0
  190. data/test/debug.js +53 -0
  191. data/test/firebug/errorIcon.png +0 -0
  192. data/test/firebug/firebug.css +209 -0
  193. data/test/firebug/firebug.html +23 -0
  194. data/test/firebug/firebug.js +672 -0
  195. data/test/firebug/firebugx.js +10 -0
  196. data/test/firebug/infoIcon.png +0 -0
  197. data/test/firebug/warningIcon.png +0 -0
  198. data/test/fixtures/html/events.html +171 -0
  199. data/test/fixtures/html/iframe1.html +46 -0
  200. data/test/fixtures/html/iframe1a.html +46 -0
  201. data/test/fixtures/html/iframe2.html +45 -0
  202. data/test/fixtures/html/iframe3.html +28 -0
  203. data/test/fixtures/html/iframeN.html +57 -0
  204. data/test/fixtures/html/malformed.html +181 -0
  205. data/test/fixtures/html/scope.html +81 -0
  206. data/test/fixtures/html/trivial.html +19 -0
  207. data/test/fixtures/html/with_js.html +26 -0
  208. data/test/fixtures/images/icon-blue.png +0 -0
  209. data/test/fixtures/js/external_script.js +1 -0
  210. data/test/fixtures/js/script.js +1 -0
  211. data/test/fixtures/js/script_error.js +2 -0
  212. data/test/foo.html +8 -0
  213. data/test/foo.js +40 -0
  214. data/test/html/events.html +171 -0
  215. data/test/html/iframe1.html +46 -0
  216. data/test/html/iframe1a.html +46 -0
  217. data/test/html/iframe2.html +45 -0
  218. data/test/html/iframe3.html +30 -0
  219. data/test/html/iframeN.html +57 -0
  220. data/test/html/malformed.html +181 -0
  221. data/test/html/scope.html +87 -0
  222. data/test/html/script.js +1 -0
  223. data/test/html/trivial.html +19 -0
  224. data/test/html/with_js.html +26 -0
  225. data/test/index.html +328 -0
  226. data/test/java-prototype.js +9 -0
  227. data/test/jquery.js +6002 -0
  228. data/test/primary-tests.js +26 -0
  229. data/test/prototype-test.js +13 -0
  230. data/test/qunit.js +61 -0
  231. data/test/qunit/qunit/qunit.css +17 -0
  232. data/test/qunit/qunit/qunit.js +997 -0
  233. data/test/scope.html +19 -0
  234. data/test/scope.rb +24 -0
  235. data/test/smp/dmathieu/index.html +8 -0
  236. data/test/specs/dist/env.spec.js +1534 -0
  237. data/test/specs/envjs.spec.css +46 -0
  238. data/test/specs/parser/html.js +31 -0
  239. data/test/specs/parser/spec.html +40 -0
  240. data/test/specs/parser/xml.js +31 -0
  241. data/test/specs/qunit.bdd.js +210 -0
  242. data/test/specs/qunit.css +17 -0
  243. data/test/specs/qunit.js +997 -0
  244. data/test/specs/template/spec-0.js +31 -0
  245. data/test/specs/template/spec-1.js +31 -0
  246. data/test/specs/template/spec.html +40 -0
  247. data/test/specs/window/css.js +23 -0
  248. data/test/specs/window/dialog.js +25 -0
  249. data/test/specs/window/document.js +23 -0
  250. data/test/specs/window/event.js +25 -0
  251. data/test/specs/window/history.js +34 -0
  252. data/test/specs/window/location.js +34 -0
  253. data/test/specs/window/navigator.js +71 -0
  254. data/test/specs/window/screen.js +42 -0
  255. data/test/specs/window/spec.html +48 -0
  256. data/test/specs/window/timer.js +26 -0
  257. data/test/specs/window/window.js +53 -0
  258. data/test/specs/xhr/spec.html +47 -0
  259. data/test/specs/xhr/xhr.js +31 -0
  260. data/test/test.js +10 -0
  261. data/test/unit/dom.js +44 -0
  262. data/test/unit/elementmembers.js +92 -0
  263. data/test/unit/events.js +195 -0
  264. data/test/unit/fixtures/external_script.js +1 -0
  265. data/test/unit/form.js +40 -0
  266. data/test/unit/iframe.js +234 -0
  267. data/test/unit/insertion.js +23 -0
  268. data/test/unit/multi-window.js +212 -0
  269. data/test/unit/nu.validator.js +34 -0
  270. data/test/unit/onload.js +90 -0
  271. data/test/unit/parser.js +122 -0
  272. data/test/unit/prototypecompat.js +22 -0
  273. data/test/unit/proxy.js +6 -0
  274. data/test/unit/scope.js +209 -0
  275. data/test/unit/timer.js +115 -0
  276. data/test/unit/window.js +57 -0
  277. data/test/x.js +1 -0
  278. data/test/y.js +1 -0
  279. metadata +367 -0
@@ -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,1023 @@
1
+ $debug("Defining Document");
2
+
3
+ /**
4
+ * Defined 'globally' to this scope. Remember everything is wrapped in a closure so this doesnt show up
5
+ * in the outer most global scope.
6
+ */
7
+
8
+ /**
9
+ * process SAX events
10
+ *
11
+ * @author Jon van Noort (jon@webarcana.com.au), David Joham (djoham@yahoo.com) and Scott Severtson
12
+ *
13
+ * @param impl : DOMImplementation
14
+ * @param doc : DOMDocument - the Document to contain the parsed XML string
15
+ * @param p : XMLP - the SAX Parser
16
+ *
17
+ * @return : DOMDocument
18
+ */
19
+
20
+ function __parseLoop__(impl, doc, p, isWindowDocument) {
21
+ var iEvt, iNode, iAttr, strName;
22
+ var iNodeParent = doc;
23
+
24
+ var el_close_count = 0;
25
+
26
+ var entitiesList = new Array();
27
+ var textNodesList = new Array();
28
+
29
+ // if namespaceAware, add default namespace
30
+ if (impl.namespaceAware) {
31
+ var iNS = doc.createNamespace(""); // add the default-default namespace
32
+ iNS.value = "http://www.w3.org/2000/xmlns/";
33
+ doc._namespaces.setNamedItem(iNS);
34
+ }
35
+
36
+ // loop until SAX parser stops emitting events
37
+ var q = 0;
38
+ while(true) {
39
+ // get next event
40
+ iEvt = p.next();
41
+
42
+ if (iEvt == XMLP._ELM_B) { // Begin-Element Event
43
+ var pName = p.getName(); // get the Element name
44
+ pName = trim(pName, true, true); // strip spaces from Element name
45
+ if(pName.toLowerCase() == 'script')
46
+ p.replaceEntities = false;
47
+
48
+ if (!impl.namespaceAware) {
49
+ iNode = doc.createElement(p.getName()); // create the Element
50
+ // add attributes to Element
51
+ for(var i = 0; i < p.getAttributeCount(); i++) {
52
+ strName = p.getAttributeName(i); // get Attribute name
53
+ iAttr = iNode.getAttributeNode(strName); // if Attribute exists, use it
54
+
55
+ if(!iAttr) {
56
+ iAttr = doc.createAttribute(strName); // otherwise create it
57
+ }
58
+
59
+ iAttr.value = p.getAttributeValue(i); // set Attribute value
60
+ iNode.setAttributeNode(iAttr); // attach Attribute to Element
61
+ }
62
+ }
63
+ else { // Namespace Aware
64
+ // create element (with empty namespaceURI,
65
+ // resolve after namespace 'attributes' have been parsed)
66
+ iNode = doc.createElementNS("", p.getName());
67
+
68
+ // duplicate ParentNode's Namespace definitions
69
+ iNode._namespaces = __cloneNamedNodes__(iNodeParent._namespaces, iNode, true);
70
+
71
+ // add attributes to Element
72
+ for(var i = 0; i < p.getAttributeCount(); i++) {
73
+ strName = p.getAttributeName(i); // get Attribute name
74
+
75
+ // if attribute is a namespace declaration
76
+ if (__isNamespaceDeclaration__(strName)) {
77
+ // parse Namespace Declaration
78
+ var namespaceDec = __parseNSName__(strName);
79
+
80
+ if (strName != "xmlns") {
81
+ iNS = doc.createNamespace(strName); // define namespace
82
+ }
83
+ else {
84
+ iNS = doc.createNamespace(""); // redefine default namespace
85
+ }
86
+ iNS.value = p.getAttributeValue(i); // set value = namespaceURI
87
+
88
+ iNode._namespaces.setNamedItem(iNS); // attach namespace to namespace collection
89
+ }
90
+ else { // otherwise, it is a normal attribute
91
+ iAttr = iNode.getAttributeNode(strName); // if Attribute exists, use it
92
+
93
+ if(!iAttr) {
94
+ iAttr = doc.createAttributeNS("", strName); // otherwise create it
95
+ }
96
+
97
+ iAttr.value = p.getAttributeValue(i); // set Attribute value
98
+ iNode.setAttributeNodeNS(iAttr); // attach Attribute to Element
99
+
100
+ if (__isIdDeclaration__(strName)) {
101
+ iNode.id = p.getAttributeValue(i); // cache ID for getElementById()
102
+ }
103
+ }
104
+ }
105
+
106
+ // resolve namespaceURIs for this Element
107
+ if (iNode._namespaces.getNamedItem(iNode.prefix)) {
108
+ iNode.namespaceURI = iNode._namespaces.getNamedItem(iNode.prefix).value;
109
+ } else {
110
+ iNode.namespaceURI = iNodeParent.namespaceURI;
111
+ }
112
+
113
+ // for this Element's attributes
114
+ for (var i = 0; i < iNode.attributes.length; i++) {
115
+ if (iNode.attributes.item(i).prefix != "") { // attributes do not have a default namespace
116
+ if (iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix)) {
117
+ iNode.attributes.item(i).namespaceURI = iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix).value;
118
+ }
119
+ }
120
+ }
121
+
122
+ // We didn't know the NS of the node when we created it, which means we created a default DOM object.
123
+ // Now that we know the NS, if there is one, we clone this node so that it'll get created under
124
+ // with the right constructor. This makes things like SVG work. Might be nice not to create twice as
125
+ // as many nodes, but that's painfully given the complexity of namespaces.
126
+ if(iNode.namespaceURI != ""){
127
+ iNode = iNode.cloneNode();
128
+ }
129
+ }
130
+
131
+ // if this is the Root Element
132
+ if (iNodeParent.nodeType == DOMNode.DOCUMENT_NODE) {
133
+ iNodeParent._documentElement = iNode; // register this Element as the Document.documentElement
134
+ }
135
+
136
+ iNodeParent.appendChild(iNode); // attach Element to parentNode
137
+ iNodeParent = iNode; // descend one level of the DOM Tree
138
+ }
139
+
140
+ else if(iEvt == XMLP._ELM_E) { // End-Element Event
141
+ iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree
142
+ }
143
+
144
+ else if(iEvt == XMLP._ELM_EMP) { // Empty Element Event
145
+ pName = p.getName(); // get the Element name
146
+ pName = trim(pName, true, true); // strip spaces from Element name
147
+
148
+ if (!impl.namespaceAware) {
149
+ iNode = doc.createElement(pName); // create the Element
150
+
151
+ // add attributes to Element
152
+ for(var i = 0; i < p.getAttributeCount(); i++) {
153
+ strName = p.getAttributeName(i); // get Attribute name
154
+ iAttr = iNode.getAttributeNode(strName); // if Attribute exists, use it
155
+
156
+ if(!iAttr) {
157
+ iAttr = doc.createAttribute(strName); // otherwise create it
158
+ }
159
+
160
+ iAttr.value = p.getAttributeValue(i); // set Attribute value
161
+ iNode.setAttributeNode(iAttr); // attach Attribute to Element
162
+ }
163
+ }
164
+ else { // Namespace Aware
165
+ // create element (with empty namespaceURI,
166
+ // resolve after namespace 'attributes' have been parsed)
167
+ iNode = doc.createElementNS("", p.getName());
168
+
169
+ // duplicate ParentNode's Namespace definitions
170
+ iNode._namespaces = __cloneNamedNodes__(iNodeParent._namespaces, iNode);
171
+
172
+ // add attributes to Element
173
+ for(var i = 0; i < p.getAttributeCount(); i++) {
174
+ strName = p.getAttributeName(i); // get Attribute name
175
+
176
+ // if attribute is a namespace declaration
177
+ if (__isNamespaceDeclaration__(strName)) {
178
+ // parse Namespace Declaration
179
+ var namespaceDec = __parseNSName__(strName);
180
+
181
+ if (strName != "xmlns") {
182
+ iNS = doc.createNamespace(strName); // define namespace
183
+ }
184
+ else {
185
+ iNS = doc.createNamespace(""); // redefine default namespace
186
+ }
187
+ iNS.value = p.getAttributeValue(i); // set value = namespaceURI
188
+
189
+ iNode._namespaces.setNamedItem(iNS); // attach namespace to namespace collection
190
+ }
191
+ else { // otherwise, it is a normal attribute
192
+ iAttr = iNode.getAttributeNode(strName); // if Attribute exists, use it
193
+
194
+ if(!iAttr) {
195
+ iAttr = doc.createAttributeNS("", strName); // otherwise create it
196
+ }
197
+
198
+ iAttr.value = p.getAttributeValue(i); // set Attribute value
199
+ iNode.setAttributeNodeNS(iAttr); // attach Attribute to Element
200
+
201
+ if (__isIdDeclaration__(strName)) {
202
+ iNode.id = p.getAttributeValue(i); // cache ID for getElementById()
203
+ }
204
+ }
205
+ }
206
+
207
+ // resolve namespaceURIs for this Element
208
+ if (iNode._namespaces.getNamedItem(iNode.prefix)) {
209
+ iNode.namespaceURI = iNode._namespaces.getNamedItem(iNode.prefix).value;
210
+ }
211
+
212
+ // for this Element's attributes
213
+ for (var i = 0; i < iNode.attributes.length; i++) {
214
+ if (iNode.attributes.item(i).prefix != "") { // attributes do not have a default namespace
215
+ if (iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix)) {
216
+ iNode.attributes.item(i).namespaceURI = iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix).value;
217
+ }
218
+ }
219
+ }
220
+ }
221
+
222
+ // if this is the Root Element
223
+ if (iNodeParent.nodeType == DOMNode.DOCUMENT_NODE) {
224
+ iNodeParent._documentElement = iNode; // register this Element as the Document.documentElement
225
+ }
226
+
227
+ iNodeParent.appendChild(iNode); // attach Element to parentNode
228
+ }
229
+ else if(iEvt == XMLP._TEXT || iEvt == XMLP._ENTITY) { // TextNode and entity Events
230
+ // get Text content
231
+ var pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
232
+
233
+ if (!impl.preserveWhiteSpace ) {
234
+ if (trim(pContent, true, true) == "") {
235
+ pContent = ""; //this will cause us not to create the text node below
236
+ }
237
+ }
238
+
239
+ if (pContent.length > 0) { // ignore empty TextNodes
240
+ var textNode = doc.createTextNode(pContent);
241
+ iNodeParent.appendChild(textNode); // attach TextNode to parentNode
242
+
243
+ //the sax parser breaks up text nodes when it finds an entity. For
244
+ //example hello&lt;there will fire a text, an entity and another text
245
+ //this sucks for the dom parser because it looks to us in this logic
246
+ //as three text nodes. I fix this by keeping track of the entity nodes
247
+ //and when we're done parsing, calling normalize on their parent to
248
+ //turn the multiple text nodes into one, which is what DOM users expect
249
+ //the code to do this is at the bottom of this function
250
+ if (iEvt == XMLP._ENTITY) {
251
+ entitiesList[entitiesList.length] = textNode;
252
+ }
253
+ else {
254
+ //I can't properly decide how to handle preserve whitespace
255
+ //until the siblings of the text node are built due to
256
+ //the entitiy handling described above. I don't know that this
257
+ //will be all of the text node or not, so trimming is not appropriate
258
+ //at this time. Keep a list of all the text nodes for now
259
+ //and we'll process the preserve whitespace stuff at a later time.
260
+ textNodesList[textNodesList.length] = textNode;
261
+ }
262
+ }
263
+ }
264
+ else if(iEvt == XMLP._PI) { // ProcessingInstruction Event
265
+ // attach ProcessingInstruction to parentNode
266
+ iNodeParent.appendChild(doc.createProcessingInstruction(p.getName(), p.getContent().substring(p.getContentBegin(), p.getContentEnd())));
267
+ }
268
+ else if(iEvt == XMLP._CDATA) { // CDATA Event
269
+ // get CDATA data
270
+ pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
271
+
272
+ if (!impl.preserveWhiteSpace) {
273
+ pContent = trim(pContent, true, true); // trim whitespace
274
+ pContent.replace(/ +/g, ' '); // collapse multiple spaces to 1 space
275
+ }
276
+
277
+ if (pContent.length > 0) { // ignore empty CDATANodes
278
+ iNodeParent.appendChild(doc.createCDATASection(pContent)); // attach CDATA to parentNode
279
+ }
280
+ }
281
+ else if(iEvt == XMLP._COMMENT) { // Comment Event
282
+ // get COMMENT data
283
+ var pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
284
+
285
+ if (!impl.preserveWhiteSpace) {
286
+ pContent = trim(pContent, true, true); // trim whitespace
287
+ pContent.replace(/ +/g, ' '); // collapse multiple spaces to 1 space
288
+ }
289
+
290
+ if (pContent.length > 0) { // ignore empty CommentNodes
291
+ iNodeParent.appendChild(doc.createComment(pContent)); // attach Comment to parentNode
292
+ }
293
+ }
294
+ else if(iEvt == XMLP._DTD) { // ignore DTD events
295
+ }
296
+ else if(iEvt == XMLP._ERROR) {
297
+ $error("Fatal Error: " + p.getContent() +
298
+ "\nLine: " + p.getLineNumber() +
299
+ "\nColumn: " + p.getColumnNumber() + "\n");
300
+ throw(new DOMException(DOMException.SYNTAX_ERR));
301
+ }
302
+ else if(iEvt == XMLP._NONE) { // no more events
303
+ //steven woods notes that unclosed tags are rejected elsewhere and this check
304
+ //breaks a table patching routine
305
+ //if (iNodeParent == doc) { // confirm that we have recursed back up to root
306
+ // break;
307
+ //}
308
+ //else {
309
+ // throw(new DOMException(DOMException.SYNTAX_ERR)); // one or more Tags were not closed properly
310
+ //}
311
+ break;
312
+
313
+ }
314
+ }
315
+
316
+ //normalize any entities in the DOM to a single textNode
317
+ for (var i = 0; i < entitiesList.length; i++) {
318
+ var entity = entitiesList[i];
319
+ //its possible (if for example two entities were in the
320
+ //same domnode, that the normalize on the first entitiy
321
+ //will remove the parent for the second. Only do normalize
322
+ //if I can find a parent node
323
+ var parentNode = entity.parentNode;
324
+ if (parentNode) {
325
+ parentNode.normalize();
326
+
327
+ //now do whitespace (if necessary)
328
+ //it was not done for text nodes that have entities
329
+ if(!impl.preserveWhiteSpace) {
330
+ var children = parentNode.childNodes;
331
+ for ( var j = 0; j < children.length; j++) {
332
+ var child = children.item(j);
333
+ if (child.nodeType == DOMNode.TEXT_NODE) {
334
+ var childData = child.data;
335
+ childData.replace(/\s/g, ' ');
336
+ child.data = childData;
337
+ }
338
+ }
339
+ }
340
+ }
341
+ }
342
+
343
+ //do the preserve whitespace processing on the rest of the text nodes
344
+ //It's possible (due to the processing above) that the node will have been
345
+ //removed from the tree. Only do whitespace checking if parentNode is not null.
346
+ //This may duplicate the whitespace processing for some nodes that had entities in them
347
+ //but there's no way around that
348
+ if (!impl.preserveWhiteSpace) {
349
+ for (var i = 0; i < textNodesList.length; i++) {
350
+ var node = textNodesList[i];
351
+ if (node.parentNode != null) {
352
+ var nodeData = node.data;
353
+ nodeData.replace(/\s/g, ' ');
354
+ node.data = nodeData;
355
+ }
356
+ }
357
+
358
+ }
359
+ };
360
+
361
+
362
+
363
+
364
+ /**
365
+ * @class DOMDocument - The Document interface represents the entire HTML
366
+ * or XML document. Conceptually, it is the root of the document tree,
367
+ * and provides the primary access to the document's data.
368
+ *
369
+ * @extends DOMNode
370
+ * @author Jon van Noort (jon@webarcana.com.au)
371
+ * @param implementation : DOMImplementation - the creator Implementation
372
+ */
373
+ var DOMDocument = function(implementation, docParentWindow) {
374
+ // if (!( implementation === undefined && docParentWindow == undefined)) {
375
+ // print("DD",implementation, docParentWindow, docParentWindow && docParentWindow.isInner);
376
+ // }
377
+ //$log("\tcreating dom document");
378
+ this.DOMNode = DOMNode;
379
+ this.DOMNode(this);
380
+
381
+ this.doctype = null; // The Document Type Declaration (see DocumentType) associated with this document
382
+ this.implementation = implementation; // The DOMImplementation object that handles this document.
383
+
384
+ // "private" variable providing the read-only document.parentWindow property
385
+ this._parentWindow = docParentWindow;
386
+ try {
387
+ if (docParentWindow.$thisWindowsProxyObject)
388
+ this._parentWindow = docParentWindow.$thisWindowsProxyObject;
389
+ } catch(e){}
390
+
391
+ this.nodeName = "#document";
392
+ this._id = 0;
393
+ this._lastId = 0;
394
+ this._parseComplete = false; // initially false, set to true by parser
395
+ this._url = "";
396
+
397
+ this.ownerDocument = null;
398
+
399
+ this._performingImportNodeOperation = false;
400
+ };
401
+ DOMDocument.prototype = new DOMNode;
402
+ __extend__(DOMDocument.prototype, {
403
+
404
+ addEventListener : function(type, fn){ __addEventListener__(this, type, fn); },
405
+ removeEventListener : function(type){ __removeEventListener__(this, type); },
406
+ attachEvent : function(type, fn){ __addEventListener__(this, type, fn); },
407
+ detachEvent : function(type){ __removeEventListener__(this, type); },
408
+ dispatchEvent : function(event, bubbles){ __dispatchEvent__(this, event, bubbles); },
409
+
410
+ toString : function(){
411
+ return '[object DOMDocument]';
412
+ },
413
+ addEventListener : function(){ this._parentWindow.addEventListener.apply(this, arguments); },
414
+ removeEventListener : function(){ this._parentWindow.removeEventListener.apply(this, arguments); },
415
+ attachEvent : function(){ this._parentWindow.addEventListener.apply(this, arguments); },
416
+ detachEvent : function(){ this._parentWindow.removeEventListener.apply(this, arguments); },
417
+ dispatchEvent : function(){ this._parentWindow.dispatchEvent.apply(this, arguments); },
418
+
419
+ get styleSheets(){
420
+ return [];/*TODO*/
421
+ },
422
+ get all(){
423
+ return this.getElementsByTagName("*");
424
+ },
425
+ get documentElement(){
426
+ var i, length = this.childNodes?this.childNodes.length:0;
427
+ for(i=0;i<length;i++){
428
+ if(this.childNodes[i].nodeType == DOMNode.ELEMENT_NODE){
429
+ return this.childNodes[i];
430
+ }
431
+ }
432
+ return null;
433
+ },
434
+ get parentWindow(){
435
+ return this._parentWindow;
436
+ },
437
+ loadXML : function(xmlString) {
438
+ // create SAX Parser
439
+ var parser = new XMLP(xmlString+'');
440
+
441
+ /*
442
+ // create DOM Document
443
+ if(this === $document){
444
+ $debug("Setting internal window.document");
445
+ $document = this;
446
+ }
447
+ */
448
+
449
+ // populate Document with Parsed Nodes
450
+ try {
451
+ // make sure thid document object is empty before we try to load ...
452
+ this.childNodes = new DOMNodeList(this, this);
453
+ this.firstChild = null;
454
+ this.lastChild = null;
455
+ this.attributes = new DOMNamedNodeMap(this, this);
456
+ this._namespaces = new DOMNamespaceNodeMap(this, this);
457
+ this._readonly = false;
458
+
459
+ __parseLoop__(this.implementation, this, parser);
460
+ } catch (e) {
461
+ $error(e);
462
+ }
463
+
464
+ // set parseComplete flag, (Some validation Rules are relaxed if this is false)
465
+ this._parseComplete = true;
466
+ return this;
467
+ },
468
+ load: function(url,xhr_options){
469
+ $debug("Loading url into DOM Document: "+ url + " - (Asynch? "+this._parentWindow.document.async+")");
470
+ var scripts, _this = this;
471
+ var xhr;
472
+ if (url == "about:blank"){
473
+ xhr = ({
474
+ open: function(){},
475
+ send: function(){
476
+ this.responseText = "<html><head><title></title></head><body></body></html>";
477
+ this.onreadystatechange();
478
+ },
479
+ status: 200
480
+ });
481
+ } else if (url.indexOf("data:") === 0) {
482
+ url = url.slice(5);
483
+ var fields = url.split(",");
484
+ var content = fields[1];
485
+ var fields = fields[0].split(";");
486
+ if(fields[1] === "base64" || (fields[1] && fields[1].indexOf("charset=") === 0 && fields[2] === "base64" ) ) {
487
+ content = Base64.decode(content);
488
+ } else {
489
+ content = unescape(content);
490
+ }
491
+ if(fields[0] === "text/html") {
492
+ } else if(fields[0] === "image/png") {
493
+ throw new Error("png");
494
+ } else {
495
+ content = "<html><head><title></title></head><body>"+content+"</body></html>";
496
+ }
497
+ xhr = ({
498
+ open: function(){},
499
+ send: function(){
500
+ var self = this;
501
+ setTimeout(function(){
502
+ self.responseText = content;
503
+ self.onreadystatechange();
504
+ },0);
505
+ },
506
+ status: 200
507
+ });
508
+ } else {
509
+ xhr = new _this._parentWindow.XMLHttpRequest();
510
+ }
511
+ xhr_options = xhr_options || {};
512
+ var method = (xhr_options.method || "GET").toUpperCase();
513
+ xhr.open(method, url, this._parentWindow.document.async);
514
+ // FIXME: not all XHRs have this right now
515
+ xhr.setRequestHeader && xhr.setRequestHeader('Content-Type', xhr_options["Content-Type"] || 'application/x-www-form-urlencoded');
516
+ xhr.setRequestHeader && xhr.setRequestHeader('Cookie', _this.cookie);
517
+ // print("rf",xhr_options["referer"]);
518
+ xhr.setRequestHeader && xhr_options["referer"] && xhr.setRequestHeader('Referer', xhr_options["referer"]);
519
+ // print(_this._parentWindow.location.href);
520
+ xhr.onreadystatechange = function(){
521
+ // print(url,xhr.status,xhr.responseText);
522
+ if(xhr.status === 302) {
523
+ // print(302,xhr.responseHeaders["location"]);
524
+ _this.load(xhr.responseHeaders["location"],{});
525
+ return;
526
+ }
527
+ if (xhr.status != 200) {
528
+ $warn("Could not retrieve XHR content from " + url + ": status code " + xhr.status);
529
+ _this.loadXML(
530
+ "<html><head></head><body>"+
531
+ "<h1>No File</h1>"+
532
+ "</body></html>");
533
+ } else {
534
+ try{
535
+ _this.loadXML(xhr.responseText, xhr.__url);
536
+ _this.__original_text__ = xhr.responseText;
537
+ if(xhr.responseHeaders && xhr.responseHeaders["set-cookie"]) {
538
+ try {
539
+ _this.cookie = xhr.responseHeaders["set-cookie"];
540
+ } catch(e) {
541
+ $error("could not set cookie: "+e);
542
+ }
543
+ }
544
+ if(xhr.responseHeaders) {
545
+ var h = _this.__headers__ = {};
546
+ for(var key in xhr.responseHeaders) {
547
+ h[key] = xhr.responseHeaders[key];
548
+ }
549
+ }
550
+ }catch(e){
551
+ $error("Error Parsing XML - ",e);
552
+ _this.loadXML(
553
+ "<html><head></head><body>"+
554
+ "<h1>Parse Error</h1>"+
555
+ "<p>"+e.toString()+"</p>"+
556
+ "</body></html>");
557
+ }
558
+ }
559
+ _this._url = url;
560
+
561
+ if ( url != "about:blank" ) {
562
+ $info("Sucessfully loaded document at "+url);
563
+ }
564
+
565
+ // first fire body-onload event
566
+ var bodyLoad = _this.createEvent();
567
+ bodyLoad.initEvent("load");
568
+ try { // assume <body> element, but just in case....
569
+ _this.getElementsByTagName('body')[0].
570
+ dispatchEvent( bodyLoad, false );
571
+ } catch (e){;}
572
+
573
+ // then fire this onload event
574
+ //event = _this.createEvent();
575
+ //event.initEvent("load");
576
+ //_this.dispatchEvent( event, false );
577
+
578
+ //also use DOMContentLoaded event
579
+ var domContentLoaded = _this.createEvent();
580
+ domContentLoaded.initEvent("DOMContentLoaded");
581
+ _this.dispatchEvent( domContentLoaded, false );
582
+
583
+ //finally fire the window.onload event
584
+ if(_this === _this._parentWindow.document){
585
+ var windowLoad = _this.createEvent();
586
+ windowLoad.initEvent("load", false, false);
587
+ _this._parentWindow.dispatchEvent( windowLoad, false );
588
+ }
589
+
590
+ };
591
+ xhr.send(xhr_options["data"]);
592
+ },
593
+ createEvent : function(eventType){
594
+ var event;
595
+ if(eventType === "UIEvents"){ event = new UIEvent();}
596
+ else if(eventType === "MouseEvents"){ event = new MouseEvent();}
597
+ else{ event = new Event(); }
598
+ return event;
599
+ },
600
+ createExpression : function(xpath, nsuriMap){
601
+ return new XPathExpression(xpath, nsuriMap);
602
+ },
603
+ createElement : function(tagName) {
604
+ //$debug("DOMDocument.createElement( "+tagName+" )");
605
+ // throw Exception if the tagName string contains an illegal character
606
+ if (__ownerDocument__(this).implementation.errorChecking
607
+ && (!__isValidName__(tagName))) {
608
+ throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
609
+ }
610
+
611
+ // create DOMElement specifying 'this' as ownerDocument
612
+ var node = new DOMElement(this);
613
+
614
+ // assign values to properties (and aliases)
615
+ node.tagName = tagName;
616
+
617
+ return node;
618
+ },
619
+ createDocumentFragment : function() {
620
+ // create DOMDocumentFragment specifying 'this' as ownerDocument
621
+ var node = new DOMDocumentFragment(this);
622
+ return node;
623
+ },
624
+ createTextNode: function(data) {
625
+ // create DOMText specifying 'this' as ownerDocument
626
+ var node = new DOMText(this);
627
+
628
+ // assign values to properties (and aliases)
629
+ node.data = data;
630
+
631
+ return node;
632
+ },
633
+ createComment : function(data) {
634
+ // create DOMComment specifying 'this' as ownerDocument
635
+ var node = new DOMComment(this);
636
+
637
+ // assign values to properties (and aliases)
638
+ node.data = data;
639
+
640
+ return node;
641
+ },
642
+ createCDATASection : function(data) {
643
+ // create DOMCDATASection specifying 'this' as ownerDocument
644
+ var node = new DOMCDATASection(this);
645
+
646
+ // assign values to properties (and aliases)
647
+ node.data = data;
648
+
649
+ return node;
650
+ },
651
+ createProcessingInstruction : function(target, data) {
652
+ // throw Exception if the target string contains an illegal character
653
+ //$log("DOMDocument.createProcessingInstruction( "+target+" )");
654
+ if (__ownerDocument__(this).implementation.errorChecking
655
+ && (!__isValidName__(target))) {
656
+ throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
657
+ }
658
+
659
+ // create DOMProcessingInstruction specifying 'this' as ownerDocument
660
+ var node = new DOMProcessingInstruction(this);
661
+
662
+ // assign values to properties (and aliases)
663
+ node.target = target;
664
+ node.data = data;
665
+
666
+ return node;
667
+ },
668
+ createAttribute : function(name) {
669
+ // throw Exception if the name string contains an illegal character
670
+ //$log("DOMDocument.createAttribute( "+target+" )");
671
+ if (__ownerDocument__(this).implementation.errorChecking
672
+ && (!__isValidName__(name))) {
673
+ throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
674
+ }
675
+
676
+ // create DOMAttr specifying 'this' as ownerDocument
677
+ var node = new DOMAttr(this);
678
+
679
+ // assign values to properties (and aliases)
680
+ node.name = name;
681
+
682
+ return node;
683
+ },
684
+ createElementNS : function(namespaceURI, qualifiedName) {
685
+ //$log("DOMDocument.createElementNS( "+namespaceURI+", "+qualifiedName+" )");
686
+ // test for exceptions
687
+ if (__ownerDocument__(this).implementation.errorChecking) {
688
+ // throw Exception if the Namespace is invalid
689
+ if (!__isValidNamespace__(this, namespaceURI, qualifiedName)) {
690
+ throw(new DOMException(DOMException.NAMESPACE_ERR));
691
+ }
692
+
693
+ // throw Exception if the qualifiedName string contains an illegal character
694
+ if (!__isValidName__(qualifiedName)) {
695
+ throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
696
+ }
697
+ }
698
+
699
+ var qname = __parseQName__(qualifiedName);
700
+
701
+ // create DOMElement specifying 'this' as ownerDocument
702
+ if(namespaceURI === "http://www.w3.org/2000/svg"){
703
+ var node = SVGDocument.prototype.createElement.call( this, qname.localName );
704
+ } else {
705
+ var node = new DOMElement(this);
706
+ }
707
+
708
+ // assign values to properties (and aliases)
709
+ node.namespaceURI = namespaceURI;
710
+ node.prefix = qname.prefix;
711
+ node.localName = qname.localName;
712
+ node.tagName = qualifiedName;
713
+
714
+ return node;
715
+ },
716
+ createAttributeNS : function(namespaceURI, qualifiedName) {
717
+ // test for exceptions
718
+ if (__ownerDocument__(this).implementation.errorChecking) {
719
+ // throw Exception if the Namespace is invalid
720
+ if (!__isValidNamespace__(this, namespaceURI, qualifiedName, true)) {
721
+ throw(new DOMException(DOMException.NAMESPACE_ERR));
722
+ }
723
+
724
+ // throw Exception if the qualifiedName string contains an illegal character
725
+ if (!__isValidName__(qualifiedName)) {
726
+ throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
727
+ }
728
+ }
729
+
730
+ // create DOMAttr specifying 'this' as ownerDocument
731
+ var node = new DOMAttr(this);
732
+ var qname = __parseQName__(qualifiedName);
733
+
734
+ // assign values to properties (and aliases)
735
+ node.namespaceURI = namespaceURI;
736
+ node.prefix = qname.prefix;
737
+ node.localName = qname.localName;
738
+ node.name = qualifiedName;
739
+ node.nodeValue = "";
740
+
741
+ return node;
742
+ },
743
+ createNamespace : function(qualifiedName) {
744
+ // create DOMNamespace specifying 'this' as ownerDocument
745
+ var node = new DOMNamespace(this);
746
+ var qname = __parseQName__(qualifiedName);
747
+
748
+ // assign values to properties (and aliases)
749
+ node.prefix = qname.prefix;
750
+ node.localName = qname.localName;
751
+ node.name = qualifiedName;
752
+ node.nodeValue = "";
753
+
754
+ return node;
755
+ },
756
+ /** from David Flanagan's JavaScript - The Definitive Guide
757
+ *
758
+ * @param {String} xpathText
759
+ * The string representing the XPath expression to evaluate.
760
+ * @param {Node} contextNode
761
+ * The node in this document against which the expression is to
762
+ * be evaluated.
763
+ * @param {Function} nsuriMapper
764
+ * A function that will map from namespace prefix to to a full
765
+ * namespace URL or null if no such mapping is required.
766
+ * @param {Number} resultType
767
+ * Specifies the type of object expected as a result, using
768
+ * XPath conversions to coerce the result. Possible values for
769
+ * type are the constrainsts defined by the XPathResult object.
770
+ * (null if not required)
771
+ * @param {XPathResult} result
772
+ * An XPathResult object to be reused or null
773
+ * if you want a new XPathResult object to be created.
774
+ * @returns {XPathResult} result
775
+ * A XPathResult object representing the evaluation of the
776
+ * expression against the given context node.
777
+ * @throws {Exception} e
778
+ * This method may throw an exception if the xpathText contains
779
+ * a syntax error, if the expression cannot be converted to the
780
+ * desired resultType, if the expression contains namespaces
781
+ * that nsuriMapper cannot resolve, or if contextNode is of the
782
+ * wrong type or is not assosciated with this document.
783
+ * @seealso
784
+ * Document.evaluate
785
+ */
786
+ evaluate: function(xpathText, contextNode, nsuriMapper, resultType, result){
787
+ try {
788
+ return new XPathExpression(xpathText, contextNode, nsuriMapper, resultType, result).evaluate();
789
+ } catch(e) {
790
+ print("xpath failure: " + e);
791
+ throw e;
792
+ }
793
+
794
+ },
795
+ getElementById : function(elementId) {
796
+ var retNode = null,
797
+ node;
798
+ // loop through all Elements in the 'all' collection
799
+ var all = this.all;
800
+ for (var i=0; i < all.length; i++) {
801
+ node = all[i];
802
+ // if id matches & node is alive (ie, connected (in)directly to the documentElement)
803
+ if (node.id == elementId) {
804
+ if((__ownerDocument__(node).documentElement._id == this.documentElement._id)){
805
+ retNode = node;
806
+ //$log("Found node with id = " + node.id);
807
+ break;
808
+ }
809
+ }
810
+ }
811
+
812
+ //if(retNode == null){$log("Couldn't find id " + elementId);}
813
+ return retNode;
814
+ },
815
+ normalizeDocument: function(){
816
+ this.documentElement.normalize();
817
+ },
818
+ get nodeType(){
819
+ return DOMNode.DOCUMENT_NODE;
820
+ },
821
+ get xml(){
822
+ //$log("Serializing " + this);
823
+ return this.documentElement.xml;
824
+ },
825
+ toString: function(){
826
+ return "DOMDocument" + (typeof this._url == "string" ? ": " + this._url : "");
827
+ },
828
+ get defaultView(){
829
+ var doc = this;
830
+ return {
831
+ document: this,
832
+ getComputedStyle: function(elem){
833
+ return doc._parentWindow.getComputedStyle(elem);
834
+ }};
835
+ },
836
+ _genId : function() {
837
+ this._lastId += 1; // increment lastId (to generate unique id)
838
+ return this._lastId;
839
+ }
840
+ });
841
+
842
+
843
+ var __isValidNamespace__ = function(doc, namespaceURI, qualifiedName, isAttribute) {
844
+
845
+ if (doc._performingImportNodeOperation == true) {
846
+ //we're doing an importNode operation (or a cloneNode) - in both cases, there
847
+ //is no need to perform any namespace checking since the nodes have to have been valid
848
+ //to have gotten into the DOM in the first place
849
+ return true;
850
+ }
851
+
852
+ var valid = true;
853
+ // parse QName
854
+ var qName = __parseQName__(qualifiedName);
855
+
856
+
857
+ //only check for namespaces if we're finished parsing
858
+ if (this._parseComplete == true) {
859
+
860
+ // if the qualifiedName is malformed
861
+ if (qName.localName.indexOf(":") > -1 ){
862
+ valid = false;
863
+ }
864
+
865
+ if ((valid) && (!isAttribute)) {
866
+ // if the namespaceURI is not null
867
+ if (!namespaceURI) {
868
+ valid = false;
869
+ }
870
+ }
871
+
872
+ // if the qualifiedName has a prefix
873
+ if ((valid) && (qName.prefix == "")) {
874
+ valid = false;
875
+ }
876
+
877
+ }
878
+
879
+ // if the qualifiedName has a prefix that is "xml" and the namespaceURI is
880
+ // different from "http://www.w3.org/XML/1998/namespace" [Namespaces].
881
+ if ((valid) && (qName.prefix == "xml") && (namespaceURI != "http://www.w3.org/XML/1998/namespace")) {
882
+ valid = false;
883
+ }
884
+
885
+ return valid;
886
+ };
887
+
888
+ /**
889
+ * @method DOMImplementation._parseQName - parse the qualified name
890
+ * @author Jon van Noort (jon@webarcana.com.au)
891
+ * @param qualifiedName : string - The qualified name
892
+ * @return : QName
893
+ */
894
+ function __parseQName__(qualifiedName) {
895
+ var resultQName = new Object();
896
+
897
+ resultQName.localName = qualifiedName; // unless the qname has a prefix, the local name is the entire String
898
+ resultQName.prefix = "";
899
+
900
+ // split on ':'
901
+ var delimPos = qualifiedName.indexOf(':');
902
+
903
+ if (delimPos > -1) {
904
+ // get prefix
905
+ resultQName.prefix = qualifiedName.substring(0, delimPos);
906
+
907
+ // get localName
908
+ resultQName.localName = qualifiedName.substring(delimPos +1, qualifiedName.length);
909
+ }
910
+
911
+ return resultQName;
912
+ };
913
+
914
+ /**
915
+ * @method DOMImplementation._isNamespaceDeclaration - Return true, if attributeName is a namespace declaration
916
+ * @author Jon van Noort (jon@webarcana.com.au)
917
+ * @param attributeName : string - the attribute name
918
+ * @return : boolean
919
+ */
920
+ function __isNamespaceDeclaration__(attributeName) {
921
+ // test if attributeName is 'xmlns'
922
+ return (attributeName.indexOf('xmlns') > -1);
923
+ };
924
+
925
+ /**
926
+ * @method DOMImplementation._isIdDeclaration - Return true, if attributeName is an id declaration
927
+ * @author Jon van Noort (jon@webarcana.com.au)
928
+ * @param attributeName : string - the attribute name
929
+ * @return : boolean
930
+ */
931
+ function __isIdDeclaration__(attributeName) {
932
+ // test if attributeName is 'id' (case insensitive)
933
+ return attributeName?(attributeName.toLowerCase() == 'id'):false;
934
+ };
935
+
936
+ /**
937
+ * @method DOMImplementation._isValidName - Return true,
938
+ * if name contains no invalid characters
939
+ * @author Jon van Noort (jon@webarcana.com.au)
940
+ * @param name : string - the candidate name
941
+ * @return : boolean
942
+ */
943
+ function __isValidName__(name) {
944
+ // test if name contains only valid characters
945
+ return name.match(re_validName);
946
+ };
947
+ var re_validName = /^[a-zA-Z_:][a-zA-Z0-9\.\-_:]*$/;
948
+
949
+ /**
950
+ * @method DOMImplementation._isValidString - Return true, if string does not contain any illegal chars
951
+ * All of the characters 0 through 31 and character 127 are nonprinting control characters.
952
+ * With the exception of characters 09, 10, and 13, (Ox09, Ox0A, and Ox0D)
953
+ * Note: different from _isValidName in that ValidStrings may contain spaces
954
+ * @author Jon van Noort (jon@webarcana.com.au)
955
+ * @param name : string - the candidate string
956
+ * @return : boolean
957
+ */
958
+ function __isValidString__(name) {
959
+ // test that string does not contains invalid characters
960
+ return (name.search(re_invalidStringChars) < 0);
961
+ };
962
+ var re_invalidStringChars = /\x01|\x02|\x03|\x04|\x05|\x06|\x07|\x08|\x0B|\x0C|\x0E|\x0F|\x10|\x11|\x12|\x13|\x14|\x15|\x16|\x17|\x18|\x19|\x1A|\x1B|\x1C|\x1D|\x1E|\x1F|\x7F/;
963
+
964
+ /**
965
+ * @method DOMImplementation._parseNSName - parse the namespace name.
966
+ * if there is no colon, the
967
+ * @author Jon van Noort (jon@webarcana.com.au)
968
+ * @param qualifiedName : string - The qualified name
969
+ * @return : NSName - [
970
+ .prefix : string - The prefix part of the qname
971
+ .namespaceName : string - The namespaceURI part of the qname
972
+ ]
973
+ */
974
+ function __parseNSName__(qualifiedName) {
975
+ var resultNSName = new Object();
976
+
977
+ resultNSName.prefix = qualifiedName; // unless the qname has a namespaceName, the prefix is the entire String
978
+ resultNSName.namespaceName = "";
979
+
980
+ // split on ':'
981
+ var delimPos = qualifiedName.indexOf(':');
982
+ if (delimPos > -1) {
983
+ // get prefix
984
+ resultNSName.prefix = qualifiedName.substring(0, delimPos);
985
+ // get namespaceName
986
+ resultNSName.namespaceName = qualifiedName.substring(delimPos +1, qualifiedName.length);
987
+ }
988
+ return resultNSName;
989
+ };
990
+
991
+ /**
992
+ * @method DOMImplementation._parseQName - parse the qualified name
993
+ * @author Jon van Noort (jon@webarcana.com.au)
994
+ * @param qualifiedName : string - The qualified name
995
+ * @return : QName
996
+ */
997
+ function __parseQName__(qualifiedName) {
998
+ var resultQName = new Object();
999
+
1000
+ resultQName.localName = qualifiedName; // unless the qname has a prefix, the local name is the entire String
1001
+ resultQName.prefix = "";
1002
+
1003
+ // split on ':'
1004
+ var delimPos = qualifiedName.indexOf(':');
1005
+
1006
+ if (delimPos > -1) {
1007
+ // get prefix
1008
+ resultQName.prefix = qualifiedName.substring(0, delimPos);
1009
+
1010
+ // get localName
1011
+ resultQName.localName = qualifiedName.substring(delimPos +1, qualifiedName.length);
1012
+ }
1013
+
1014
+ return resultQName;
1015
+ };
1016
+
1017
+ // $w.Document = DOMDocument;
1018
+
1019
+ // Local Variables:
1020
+ // espresso-indent-level:4
1021
+ // c-basic-offset:4
1022
+ // tab-width:4
1023
+ // End: