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,21 @@
1
+ $debug("Defining HTMLButtonElement");
2
+ /*
3
+ * HTMLButtonElement - DOM Level 2
4
+ */
5
+ var HTMLButtonElement = function(ownerDocument) {
6
+ this.HTMLTypeValueInputs = HTMLTypeValueInputs;
7
+ this.HTMLTypeValueInputs(ownerDocument);
8
+ };
9
+ HTMLButtonElement.prototype = new HTMLTypeValueInputs;
10
+ __extend__(HTMLButtonElement.prototype, inputElements_status);
11
+ __extend__(HTMLButtonElement.prototype, {
12
+ get dataFormatAs(){
13
+ return this.getAttribute('dataFormatAs');
14
+ },
15
+ set dataFormatAs(value){
16
+ this.setAttribute('dataFormatAs',value);
17
+ }
18
+ });
19
+
20
+ // $w.HTMLButtonElement = HTMLButtonElement;
21
+
@@ -0,0 +1,14 @@
1
+ $debug("Defining HTMLCanvasElement");
2
+ /*
3
+ * HTMLCanvasElement - DOM Level 2
4
+ */
5
+ var HTMLCanvasElement = function(ownerDocument) {
6
+ this.HTMLElement = HTMLElement;
7
+ this.HTMLElement(ownerDocument);
8
+ };
9
+ HTMLCanvasElement.prototype = new HTMLElement;
10
+ __extend__(HTMLCanvasElement.prototype, {
11
+ });
12
+
13
+ $w.HTMLCanvasElement = HTMLCanvasElement;
14
+
@@ -0,0 +1,49 @@
1
+ $debug("Defining HTMLTableColElement");
2
+ /*
3
+ * HTMLTableColElement - DOM Level 2
4
+ */
5
+ var HTMLTableColElement = function(ownerDocument) {
6
+ this.HTMLElement = HTMLElement;
7
+ this.HTMLElement(ownerDocument);
8
+ };
9
+ HTMLTableColElement.prototype = new HTMLElement;
10
+ __extend__(HTMLTableColElement.prototype, {
11
+ get align(){
12
+ return this.getAttribute('align');
13
+ },
14
+ set align(value){
15
+ this.setAttribute('align', value);
16
+ },
17
+ get ch(){
18
+ return this.getAttribute('ch');
19
+ },
20
+ set ch(value){
21
+ this.setAttribute('ch', value);
22
+ },
23
+ get chOff(){
24
+ return this.getAttribute('ch');
25
+ },
26
+ set chOff(value){
27
+ this.setAttribute('ch', value);
28
+ },
29
+ get span(){
30
+ return this.getAttribute('span');
31
+ },
32
+ set span(value){
33
+ this.setAttribute('span', value);
34
+ },
35
+ get vAlign(){
36
+ return this.getAttribute('valign');
37
+ },
38
+ set vAlign(value){
39
+ this.setAttribute('valign', value);
40
+ },
41
+ get width(){
42
+ return this.getAttribute('width');
43
+ },
44
+ set width(value){
45
+ this.setAttribute('width', value);
46
+ }
47
+ });
48
+
49
+ // $w.HTMLTableColElement = HTMLTableColElement;
@@ -0,0 +1,72 @@
1
+ $debug("Defining HTMLCollection");
2
+ /*
3
+ * HTMLCollection - DOM Level 2
4
+ * Implementation Provided by Steven Wood
5
+ */
6
+ var HTMLCollection = function(nodelist, type){
7
+
8
+ __setArray__(this, []);
9
+ for (var i=0; i<nodelist.length; i++) {
10
+ this[i] = nodelist[i];
11
+ }
12
+
13
+ this.length = nodelist.length;
14
+
15
+ }
16
+
17
+ HTMLCollection.prototype = {
18
+
19
+ item : function (idx) {
20
+ var ret = null;
21
+ if ((idx >= 0) && (idx < this.length)) {
22
+ ret = this[idx];
23
+ }
24
+
25
+ return ret;
26
+ },
27
+
28
+ namedItem : function (name) {
29
+ }
30
+ };
31
+
32
+ // $w.HTMLCollection = HTMLCollection;
33
+
34
+ /*var HTMLCollection = function(nodelist, type){
35
+ var $items = [],
36
+ $item, i;
37
+ if(type === "Anchor" ){
38
+ for(i=0;i<nodelist.length;i++){
39
+ //The name property is required to be add to the collection
40
+ if(nodelist.item(i).name){
41
+ item = new nodelist.item(i);
42
+ $items.push(item);
43
+ this[nodelist.item(i).name] = item;
44
+ }
45
+ }
46
+ }else if(type === "Link"){
47
+ for(i=0;i<nodelist.length;i++){
48
+ //The name property is required to be add to the collection
49
+ if(nodelist.item(i).href){
50
+ item = new nodelist.item(i);
51
+ $items.push(item);
52
+ this[nodelist.item(i).name] = item;
53
+ }
54
+ }
55
+ }else if(type === "Form"){
56
+ for(i=0;i<nodelist.length;i++){
57
+ //The name property is required to be add to the collection
58
+ if(nodelist.item(i).href){
59
+ item = new nodelist.item(i);
60
+ $items.push(item);
61
+ this[nodelist.item(i).name] = item;
62
+ }
63
+ }
64
+ }
65
+ setArray(this, $items);
66
+ return __extend__(this, {
67
+ item : function(i){return this[i];},
68
+ namedItem : function(name){return this[name];}
69
+ });
70
+ };*/
71
+
72
+
@@ -0,0 +1,151 @@
1
+ $debug("Defining document.cookie");
2
+ /*
3
+ * cookie.js
4
+ * - requires env
5
+ */
6
+
7
+ var $cookies = {
8
+ persistent:{
9
+ //domain - key on domain name {
10
+ //path - key on path {
11
+ //name - key on name {
12
+ //value : cookie value
13
+ //other cookie properties
14
+ //}
15
+ //}
16
+ //}
17
+ //expire - provides a timestamp for expiring the cookie
18
+ //cookie - the cookie!
19
+ },
20
+ temporary:{//transient is a reserved word :(
21
+ //like above
22
+ }
23
+ };
24
+
25
+ //HTMLDocument cookie
26
+ __extend__(HTMLDocument.prototype, {
27
+ set cookie(cookie){
28
+ var i,name,value,properties = {},attr,attrs = cookie.split(";");
29
+ //for now the strategy is to simply create a json object
30
+ //and post it to a file in the .cookies.js file. I hate parsing
31
+ //dates so I decided not to implement support for 'expires'
32
+ //(which is deprecated) and instead focus on the easier 'max-age'
33
+ //(which succeeds 'expires')
34
+ cookie = {};//keyword properties of the cookie
35
+ for(i=0;i<attrs.length;i++){
36
+ var index = attrs[i].indexOf("=");
37
+ if(index > -1){
38
+ name = trim(attrs[i].slice(0,index));
39
+ value = trim(attrs[i].slice(index+1));
40
+ cookie['domain'] = "";
41
+ if(name=='max-age'){
42
+ //we'll have to set a timer to check these
43
+ //and garbage collect expired cookies
44
+ cookie[name] = parseInt(value, 10);
45
+ } else if(name=='domain'){
46
+ if(domainValid(value)){
47
+ cookie['domain']=value;
48
+ }else{
49
+ cookie['domain']=$w.location.domain;
50
+ }
51
+ } else if(name=='path'){
52
+ //not sure of any special logic for path
53
+ cookie['path'] = value;
54
+ } else {
55
+ //its not a cookie keyword so store it in our array of properties
56
+ //and we'll serialize individually in a moment
57
+ properties[name] = value;
58
+ }
59
+ }else{
60
+ if(attrs[i] == 'secure'){
61
+ cookie[attrs[i]] = true;
62
+ }
63
+ }
64
+ }
65
+ if(!cookie['max-age']){
66
+ //it's a transient cookie so it only lasts as long as
67
+ //the window.location remains the same
68
+ mergeCookie($cookies.temporary, cookie, properties);
69
+ }else if(cookie['max-age']===0){
70
+ //delete the cookies
71
+ //TODO
72
+ }else{
73
+ //the cookie is persistent
74
+ mergeCookie($cookies.persistent, cookie, properties);
75
+ persistCookies();
76
+ }
77
+ },
78
+ get cookie(c){
79
+ //The cookies that are returned must belong to the same domain
80
+ //and be at or below the current window.location.path. Also
81
+ //we must check to see if the cookie was set to 'secure' in which
82
+ //case we must check our current location.protocol to make sure it's
83
+ //https:
84
+ var allcookies = [], i;
85
+ return cookieString($cookies.temporary) + cookieString($cookies.persistent);
86
+ }});
87
+
88
+ var cookieString = function(cookies) {
89
+ var cookieString = "";
90
+ for (var i in cookies) {
91
+ // check if the cookie is in the current domain (if domain is set)
92
+ if (i == "" || i == $w.location.domain) {
93
+ for (var j in cookies[i]) {
94
+ // make sure path is at or below the window location path
95
+ if (j == "/" || $w.location.pathname.indexOf(j) === 0) {
96
+ for (var k in cookies[i][j]) {
97
+ cookieString += k + "=" + cookies[i][j][k].value+";";
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
103
+ return cookieString;
104
+ }
105
+
106
+
107
+ var domainValid = function(domain){
108
+ //make sure the domain
109
+ //TODO
110
+ };
111
+
112
+ var mergeCookie = function(target, cookie, properties){
113
+ var name, now;
114
+ if(!target[cookie.domain]){
115
+ target[cookie.domain] = {};
116
+ }
117
+ if(!target[cookie.domain][cookie.path]){
118
+ target[cookie.domain][cookie.path] = {};
119
+ }
120
+ for(name in properties){
121
+ now = new Date().getTime();
122
+ target[cookie.domain][cookie.path][name] = {
123
+ value:properties[name],
124
+ "@env:secure":cookie.secure,
125
+ "@env:max-age":cookie['max-age'],
126
+ "@env:date-created":now,
127
+ "@env:expiration":now + cookie['max-age']
128
+ };
129
+ }
130
+ };
131
+
132
+ var persistCookies = function(){
133
+ //TODO
134
+ //I think it should be done via $env so it can be customized
135
+ };
136
+
137
+ var loadCookies = function(){
138
+ //TODO
139
+ //should also be configurable via $env
140
+ };
141
+
142
+ //We simply use the default ajax get to load the .cookies.js file
143
+ //if it doesn't exist we create it with a post. Cookies are maintained
144
+ //in memory, but serialized with each set.
145
+ try{
146
+ //TODO - load cookies
147
+ loadCookies();
148
+ }catch(e){
149
+ //TODO - fail gracefully
150
+ }
151
+
@@ -0,0 +1,25 @@
1
+ $debug("Defining HTMLModElement");
2
+ /*
3
+ * HTMLModElement - DOM Level 2
4
+ */
5
+ var HTMLModElement = function(ownerDocument) {
6
+ this.HTMLElement = HTMLElement;
7
+ this.HTMLElement(ownerDocument);
8
+ };
9
+ HTMLModElement.prototype = new HTMLElement;
10
+ __extend__(HTMLModElement.prototype, {
11
+ get cite(){
12
+ return this.getAttribute('cite');
13
+ },
14
+ set cite(value){
15
+ this.setAttribute('cite', value);
16
+ },
17
+ get dateTime(){
18
+ return this.getAttribute('datetime');
19
+ },
20
+ set dateTime(value){
21
+ this.setAttribute('datetime', value);
22
+ }
23
+ });
24
+
25
+ // $w.HTMLModElement = HTMLModElement;
data/src/html/div.js ADDED
@@ -0,0 +1,28 @@
1
+ /*
2
+ * This file is a component of env.js,
3
+ * http://github.com/gleneivey/env-js/commits/master/README
4
+ * a Pure JavaScript Browser Environment
5
+ * Copyright 2009 John Resig, licensed under the MIT License
6
+ * http://www.opensource.org/licenses/mit-license.php
7
+ */
8
+
9
+
10
+ $debug("Defining HTMLDivElement");
11
+ /*
12
+ * HTMLDivElement - DOM Level 2
13
+ */
14
+ var HTMLDivElement = function(ownerDocument) {
15
+ this.HTMLElement = HTMLElement;
16
+ this.HTMLElement(ownerDocument);
17
+ };
18
+ HTMLDivElement.prototype = new HTMLElement;
19
+ __extend__(HTMLDivElement.prototype, {
20
+ get align(){
21
+ return this.getAttribute('align') || 'left';
22
+ },
23
+ set align(value){
24
+ this.setAttribute('align', value);
25
+ }
26
+ });
27
+
28
+ // $w.HTMLDivElement = HTMLDivElement;
@@ -0,0 +1,359 @@
1
+ $debug("Defining HTMLDocument");
2
+ /*
3
+ * HTMLDocument - DOM Level 2
4
+ */
5
+ /**
6
+ * @class HTMLDocument - The Document interface represents the entire HTML or XML document.
7
+ * Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
8
+ *
9
+ * @extends DOMDocument
10
+ */
11
+ var HTMLDocument = function(implementation, docParentWindow, docReferrer) {
12
+ this.DOMDocument = DOMDocument;
13
+ this.DOMDocument(implementation, docParentWindow);
14
+
15
+ this._referrer = docReferrer;
16
+ this._domain;
17
+ this._open = false;
18
+ this.$async = false;
19
+ };
20
+ HTMLDocument.prototype = new DOMDocument;
21
+ __extend__(HTMLDocument.prototype, {
22
+ loadXML : function(xmlString) {
23
+ // create DOM Document
24
+ /*
25
+ if(this === $document){
26
+ $debug("Setting internal window.document");
27
+ $document = this;
28
+ }
29
+ */
30
+ // populate Document with Parsed Nodes
31
+ try {
32
+ // make sure thid document object is empty before we try to load ...
33
+ this.childNodes = new DOMNodeList(this, this);
34
+ this.firstChild = null;
35
+ this.lastChild = null;
36
+ this.attributes = new DOMNamedNodeMap(this, this);
37
+ this._namespaces = new DOMNamespaceNodeMap(this, this);
38
+ this._readonly = false;
39
+
40
+ // var now = Date.now();
41
+ // print("begin parse");
42
+ try{
43
+ this._parentWindow.parseHtmlDocument(xmlString, this, null, null);
44
+ }catch(e){
45
+ print("oopsd",e);
46
+ throw e;
47
+ }
48
+ // print("end parse");
49
+ // print("parse time: "+(Date.now() - now)/1000.);
50
+ // print("parse: "+xmlString.substring(0,80));
51
+
52
+
53
+ } catch (e) {
54
+ $error(e);
55
+ }
56
+
57
+ // set parseComplete flag, (Some validation Rules are relaxed if this is false)
58
+ this._parseComplete = true;
59
+ return this;
60
+ },
61
+ createElement: function(tagName){
62
+ var node;
63
+ //print('createElement :'+tagName);
64
+ // throw Exception if the tagName string contains an illegal character
65
+ if (__ownerDocument__(this).implementation.errorChecking &&
66
+ (!__isValidName__(tagName))) {
67
+ throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
68
+ }
69
+ var originalName = tagName;
70
+ tagName = tagName.toUpperCase();
71
+ // create DOMElement specifying 'this' as ownerDocument
72
+ //This is an html document so we need to use explicit interfaces per the
73
+ if( tagName.match(/^A$/)) {node = new HTMLAnchorElement(this);}
74
+ else if(tagName.match(/^AREA$/)) {node = new HTMLAreaElement(this);}
75
+ else if(tagName.match(/BASE/)) {node = new HTMLBaseElement(this);}
76
+ else if(tagName.match(/BLOCKQUOTE|Q/)) {node = new HTMLQuoteElement(this);}
77
+ else if(tagName.match(/BODY/)) {node = new HTMLBodyElement(this);}
78
+ else if(tagName.match(/BR/)) {node = new HTMLElement(this);}
79
+ else if(tagName.match(/BUTTON/)) {node = new HTMLButtonElement(this);}
80
+ else if(tagName.match(/CAPTION/)) {node = new HTMLElement(this);}
81
+ else if(tagName.match(/COL|COLGROUP/)) {node = new HTMLTableColElement(this);}
82
+ else if(tagName.match(/DEL|INS/)) {node = new HTMLModElement(this);}
83
+ else if(tagName.match(/DIV/)) {node = new HTMLDivElement(this);}
84
+ else if(tagName.match(/DL/)) {node = new HTMLElement(this);}
85
+ else if(tagName.match(/FIELDSET/)) {node = new HTMLFieldSetElement(this);}
86
+ else if(tagName.match(/FORM/)) {node = new HTMLFormElement(this);}
87
+ else if(tagName.match(/^FRAME$/)) {node = new HTMLFrameElement(this);}
88
+ else if(tagName.match(/FRAMESET/)) {node = new HTMLFrameSetElement(this);}
89
+ else if(tagName.match(/H1|H2|H3|H4|H5|H6/)) {node = new HTMLElement(this);}
90
+ else if(tagName.match(/HEAD/)) {node = new HTMLHeadElement(this);}
91
+ else if(tagName.match(/HR/)) {node = new HTMLElement(this);}
92
+ else if(tagName.match(/HTML/)) {node = new HTMLElement(this);}
93
+ else if(tagName.match(/IFRAME/)) {node = new HTMLIFrameElement(this);}
94
+ else if(tagName.match(/IMG/)) {node = new HTMLImageElement(this);}
95
+ else if(tagName.match(/INPUT/)) {node = new HTMLInputElement(this);}
96
+ else if(tagName.match(/LABEL/)) {node = new HTMLLabelElement(this);}
97
+ else if(tagName.match(/LEGEND/)) {node = new HTMLLegendElement(this);}
98
+ else if(tagName.match(/^LI$/)) {node = new HTMLElement(this);}
99
+ else if(tagName.match(/LINK/)) {node = new HTMLLinkElement(this);}
100
+ else if(tagName.match(/MAP/)) {node = new HTMLMapElement(this);}
101
+ else if(tagName.match(/META/)) {node = new HTMLMetaElement(this);}
102
+ else if(tagName.match(/OBJECT/)) {node = new HTMLObjectElement(this);}
103
+ else if(tagName.match(/OL/)) {node = new HTMLElement(this);}
104
+ else if(tagName.match(/OPTGROUP/)) {node = new HTMLOptGroupElement(this);}
105
+ else if(tagName.match(/OPTION/)) {node = new HTMLOptionElement(this);;}
106
+ else if(tagName.match(/^P$/)) {node = new HTMLElement(this);}
107
+ else if(tagName.match(/PARAM/)) {node = new HTMLParamElement(this);}
108
+ else if(tagName.match(/PRE/)) {node = new HTMLElement(this);}
109
+ else if(tagName.match(/SCRIPT/)) {node = new HTMLScriptElement(this);}
110
+ else if(tagName.match(/SELECT/)) {node = new HTMLSelectElement(this);}
111
+ else if(tagName.match(/STYLE/)) {node = new HTMLStyleElement(this);}
112
+ else if(tagName.match(/TABLE/)) {node = new HTMLTableElement(this);}
113
+ else if(tagName.match(/TBODY|TFOOT|THEAD/)) {node = new HTMLTableSectionElement(this);}
114
+ else if(tagName.match(/TD|TH/)) {node = new HTMLTableCellElement(this);}
115
+ else if(tagName.match(/TEXTAREA/)) {node = new HTMLTextAreaElement(this);}
116
+ else if(tagName.match(/TITLE/)) {node = new HTMLTitleElement(this);}
117
+ else if(tagName.match(/TR/)) {node = new HTMLTableRowElement(this);}
118
+ else if(tagName.match(/UL/)) {node = new HTMLElement(this);}
119
+ else{
120
+ node = new HTMLElement(this);
121
+ }
122
+
123
+ // assign values to properties (and aliases)
124
+ node.tagName = tagName; // originalName;
125
+ return node;
126
+ },
127
+ createElementNS : function (uri, local) {
128
+ //print('createElementNS :'+uri+" "+local);
129
+ if(!uri){
130
+ return this.createElement(local);
131
+ }else if ("http://www.w3.org/1999/xhtml" == uri) {
132
+ return this.createElement(local);
133
+ } else if ("http://www.w3.org/1998/Math/MathML" == uri) {
134
+ if (!this.mathplayerinitialized) {
135
+ var obj = this.createElement("object");
136
+ obj.setAttribute("id", "mathplayer");
137
+ obj.setAttribute("classid", "clsid:32F66A20-7614-11D4-BD11-00104BD3F987");
138
+ this.getElementsByTagName("head")[0].appendChild(obj);
139
+ this.namespaces.add("m", "http://www.w3.org/1998/Math/MathML", "#mathplayer");
140
+ this.mathplayerinitialized = true;
141
+ }
142
+ return this.createElement("m:" + local);
143
+ } else {
144
+ return DOMDocument.prototype.createElementNS.apply(this,[uri, local]);
145
+ }
146
+ },
147
+ get anchors(){
148
+ return new HTMLCollection(this.getElementsByTagName('a'), 'Anchor');
149
+
150
+ },
151
+ get applets(){
152
+ return new HTMLCollection(this.getElementsByTagName('applet'), 'Applet');
153
+
154
+ },
155
+ get body(){
156
+ var nodelist = this.getElementsByTagName('body');
157
+ return nodelist.item(0);
158
+
159
+ },
160
+ set body(html){
161
+ return this.replaceNode(this.body,html);
162
+
163
+ },
164
+
165
+ get title(){
166
+ var titleArray = this.getElementsByTagName('title');
167
+ if (titleArray.length < 1)
168
+ return "";
169
+ return titleArray[0].text;
170
+ },
171
+ set title(titleStr){
172
+ titleArray = this.getElementsByTagName('title');
173
+ if (titleArray.length < 1){
174
+ // need to make a new element and add it to "head"
175
+ var titleElem = new HTMLTitleElement(this);
176
+ titleElem.text = titleStr;
177
+ var headArray = this.getElementsByTagName('head');
178
+ if (headArray.length < 1)
179
+ return; // ill-formed, just give up.....
180
+ headArray[0].appendChild(titleElem);
181
+ }
182
+ else {
183
+ titleArray[0].text = titleStr;
184
+ }
185
+ },
186
+
187
+ //set/get cookie see cookie.js
188
+ get domain(){
189
+ return this._domain||this._parentWindow.location.domain;
190
+
191
+ },
192
+ set domain(){
193
+ /* TODO - requires a bit of thought to enforce domain restrictions */
194
+ return;
195
+
196
+ },
197
+ get forms(){
198
+ return new HTMLCollection(this.getElementsByTagName('form'), 'Form');
199
+ },
200
+ get images(){
201
+ return new HTMLCollection(this.getElementsByTagName('img'), 'Image');
202
+
203
+ },
204
+ get lastModified(){
205
+ /* TODO */
206
+ return this._lastModified;
207
+
208
+ },
209
+ get links(){
210
+ return new HTMLCollection(this.getElementsByTagName('a'), 'Link');
211
+
212
+ },
213
+ get location(){
214
+ return this._parentWindow.location
215
+ },
216
+ get referrer(){
217
+ return this._referrer;
218
+ },
219
+ close : function(){
220
+ /* TODO */
221
+ this._open = false;
222
+ },
223
+ getElementsByName : function(name){
224
+ //returns a real Array + the DOMNodeList
225
+ var retNodes = __extend__([],new DOMNodeList(this, this.documentElement)),
226
+ node;
227
+ // loop through all Elements in the 'all' collection
228
+ var all = this.all;
229
+ for (var i=0; i < all.length; i++) {
230
+ node = all[i];
231
+ if (node.nodeType == DOMNode.ELEMENT_NODE && node.getAttribute('name') == name) {
232
+ retNodes.push(node);
233
+ }
234
+ }
235
+ return retNodes;
236
+ },
237
+ open : function(){
238
+ /* TODO */
239
+ this._open = true;
240
+ },
241
+ write: function(htmlstring){
242
+ /* TODO */
243
+ return;
244
+
245
+ },
246
+ writeln: function(htmlstring){
247
+ this.write(htmlstring+'\n');
248
+ },
249
+ toString: function(){
250
+ return "HTMLDocument" + (typeof this._url == "string" ? ": " + this._url : "");
251
+ },
252
+ get innerHTML(){
253
+ return this.documentElement.outerHTML;
254
+
255
+ },
256
+ get __html__(){
257
+ return true;
258
+
259
+ },
260
+ get async(){ return this.$async;},
261
+ set async(async){ this.$async = async; },
262
+ get baseURI(){
263
+ var $env = this.ownerDocument._parentWindow.$envx;
264
+ return $env.location('./');
265
+ },
266
+ get URL(){ return this._parentWindow.location.href; },
267
+ set URL(url){ this._parentWindow.location.href = url; },
268
+ });
269
+
270
+ var __elementPopped__ = function(ns, name, node){
271
+ try{
272
+ var $env = __ownerDocument__(node)._parentWindow.$envx;
273
+ // $error('Element Popped: '+ns+" "+name+ " "+ node+" " +node.type+" "+node.nodeName);
274
+ var doc = __ownerDocument__(node);
275
+ // SMP: subtle issue here: we're currently getting two kinds of script nodes from the html5 parser.
276
+ // The "fake" nodes come with a type of undefined. The "real" nodes come with the type that's given,
277
+ // or null if not given. So the following check has the side-effect of ignoring the "fake" nodes. So
278
+ // something to watch for if this code changes.
279
+ var type = ( node.type === null ) ? "text/javascript" : node.type;
280
+ try{
281
+ if(node.nodeName.toLowerCase() == 'script' && type == "text/javascript"){
282
+ // print(node,doc.in_inner_html);
283
+ if (doc.in_inner_html) {
284
+ // this is a fib, but ...
285
+ // print("ignore",node);
286
+ // node.executed = true;
287
+ } else {
288
+ //$env.debug("element popped: script\n"+node.xml);
289
+ // unless we're parsing in a window context, don't execute scripts
290
+ // this probably doesn't do anything ...
291
+ if (true /*doc.parentWindow && !node.ownerDocument.is_innerHTML*/){
292
+ //p.replaceEntities = true;
293
+ var okay = $env.loadLocalScript(node, null);
294
+ // only fire event if we actually had something to load
295
+ if (node.src && node.src.length > 0){
296
+ var event = doc.createEvent();
297
+ event.initEvent( okay ? "load" : "error", false, false );
298
+ node.dispatchEvent( event, false );
299
+ }
300
+ }
301
+ }
302
+ }
303
+ else if (node.nodeName.toLowerCase() == 'frame' ||
304
+ node.nodeName.toLowerCase() == 'iframe' ){
305
+
306
+ //$env.debug("element popped: iframe\n"+node.xml);
307
+ if (node.src && node.src.length > 0){
308
+ $debug("getting content document for (i)frame from " + node.src);
309
+
310
+ // any JS here is DOM-instigated, so the JS scope is the window, not the first script
311
+
312
+ var $inner = node.ownerDocument._parentWindow["$inner"];
313
+
314
+ var save = $master.first_script_window;
315
+ $master.first_script_window = $inner;
316
+
317
+ $env.loadFrame(node, $env.location(node.src));
318
+
319
+ $master.first_script_window = save;
320
+
321
+ var event = doc.createEvent();
322
+ event.initEvent("load", false, false);
323
+ node.dispatchEvent( event, false );
324
+ }
325
+ }
326
+ else if (node.nodeName.toLowerCase() == 'link'){
327
+ //$env.debug("element popped: link\n"+node.xml);
328
+ if (node.href && node.href.length > 0){
329
+ // don't actually load anything, so we're "done" immediately:
330
+ var event = doc.createEvent();
331
+ event.initEvent("load", false, false);
332
+ node.dispatchEvent( event, false );
333
+ }
334
+ }
335
+ else if (node.nodeName.toLowerCase() == 'img'){
336
+ //$env.debug("element popped: img \n"+node.xml);
337
+ if (node.src && node.src.length > 0){
338
+ // don't actually load anything, so we're "done" immediately:
339
+ var event = doc.createEvent();
340
+ event.initEvent("load", false, false);
341
+ node.dispatchEvent( event, false );
342
+ }
343
+ }
344
+ }catch(e){
345
+ $error('error loading html element', e);
346
+ $error(e);
347
+ }
348
+ } catch(e) {
349
+ $error("arg",e);
350
+ }
351
+ };
352
+
353
+ //$w.HTMLDocument = HTMLDocument;
354
+
355
+ // Local Variables:
356
+ // espresso-indent-level:4
357
+ // c-basic-offset:4
358
+ // tab-width:4
359
+ // End: