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,382 @@
1
+ $debug("Defining HTMLElement");
2
+ /*
3
+ * HTMLElement - DOM Level 2
4
+ */
5
+ var HTMLElement = function(ownerDocument) {
6
+ this.DOMElement = DOMElement;
7
+ this.DOMElement(ownerDocument);
8
+
9
+ this.$css2props = null;
10
+ };
11
+ HTMLElement.prototype = new DOMElement;
12
+ __extend__(HTMLElement.prototype, {
13
+
14
+ get className() {
15
+ return this.getAttribute("class")||'';
16
+ },
17
+ set className(value) {
18
+ return this.setAttribute("class",trim(value));
19
+
20
+ },
21
+ get dir() {
22
+ return this.getAttribute("dir")||"ltr";
23
+
24
+ },
25
+ set dir(val) {
26
+ return this.setAttribute("dir",val);
27
+
28
+ },
29
+ get id(){
30
+ return this.getAttribute('id');
31
+
32
+ },
33
+ set id(id){
34
+ this.setAttribute('id', id);
35
+
36
+ },
37
+ get innerHTML(){
38
+ return this.childNodes.xml;
39
+
40
+ },
41
+ set innerHTML(html){
42
+ //Should be replaced with HTMLPARSER usage
43
+ //$debug('SETTING INNER HTML ('+this+'+'+html.substring(0,64));
44
+ var doc = new HTMLDocument(this.ownerDocument.implementation,
45
+ this.ownerDocument._parentWindow,
46
+ "");
47
+ // print("innerHTML",html);
48
+ // try { throw new Error; } catch(e) { print(e.stack); }
49
+ var docstring = '<html><head></head><body>'+
50
+ '<envjs_1234567890 xmlns="envjs_1234567890">'
51
+ +html+
52
+ '</envjs_1234567890>'+
53
+ '</body></html>';
54
+ doc.in_inner_html = true;
55
+ this.ownerDocument._parentWindow.parseHtmlDocument(docstring,doc,null,null,true);
56
+ var parent = doc.body.childNodes[0];
57
+ while(this.firstChild != null){
58
+ this.removeChild( this.firstChild );
59
+ }
60
+ var importedNode;
61
+
62
+ var pn = this;
63
+ while(pn.parentNode) {
64
+ pn = pn.parentNode;
65
+ }
66
+ // print(this,pn,this.ownerDocument);
67
+ try{
68
+ if (pn === this.ownerDocument) {
69
+ this.ownerDocument.in_inner_html = true;
70
+ // print("yup");
71
+ }
72
+ while(parent.firstChild != null){
73
+ importedNode = this.importNode(
74
+ parent.removeChild( parent.firstChild ), true);
75
+ this.appendChild( importedNode );
76
+ }
77
+ } finally {
78
+ if (pn === this.ownerDocument) {
79
+ // print("nope");
80
+ this.ownerDocument.in_inner_html = false;
81
+ }
82
+ }
83
+ //Mark for garbage collection
84
+ doc = null;
85
+ },
86
+ get innerText(){
87
+ return __recursivelyGatherText__(this);
88
+ },
89
+ set innerText(newText){
90
+ while(this.firstChild != null){
91
+ this.removeChild( this.firstChild );
92
+ }
93
+ var text = this.ownerDocument.createTextNode(newText);
94
+ this.appendChild(text);
95
+ },
96
+ get lang() {
97
+ return this.getAttribute("lang");
98
+
99
+ },
100
+ set lang(val) {
101
+ return this.setAttribute("lang",val);
102
+
103
+ },
104
+ get offsetHeight(){
105
+ return Number(this.style["height"].replace("px",""));
106
+ },
107
+ get offsetWidth(){
108
+ return Number(this.style["width"].replace("px",""));
109
+ },
110
+ offsetLeft: 0,
111
+ offsetRight: 0,
112
+ offsetTop: 0,
113
+ get offsetParent(){
114
+ /* TODO */
115
+ return;
116
+ },
117
+ set offsetParent(element){
118
+ /* TODO */
119
+ return;
120
+ },
121
+ scrollTop: 0,
122
+ scrollHeight: 0,
123
+ scrollWidth: 0,
124
+ scrollLeft: 0,
125
+ scrollRight: 0,
126
+ get style(){
127
+ if(this.$css2props === null){
128
+ this.$css2props = new CSS2Properties(this);
129
+ }
130
+ return this.$css2props;
131
+ },
132
+ set style(values){
133
+ __updateCss2Props__(this, values);
134
+ },
135
+ setAttribute: function (name, value) {
136
+ DOMElement.prototype.setAttribute.apply(this,[name, value]);
137
+ if (name === "style") {
138
+ __updateCss2Props__(this, value);
139
+ }
140
+ },
141
+ get title() {
142
+ return this.getAttribute("title");
143
+
144
+ },
145
+ set title(value) {
146
+ return this.setAttribute("title", value);
147
+
148
+ },
149
+ get tabIndex(){
150
+ var ti = this.getAttribute('tabindex');
151
+ if(ti!==null)
152
+ return Number(ti);
153
+ else
154
+ return 0;
155
+ },
156
+ set tabIndex(value){
157
+ if(value===undefined||value===null)
158
+ value = 0;
159
+ this.setAttribute('tabindex',Number(value));
160
+ },
161
+ //Not in the specs but I'll leave it here for now.
162
+ get outerHTML(){
163
+ return this.xml;
164
+
165
+ },
166
+ scrollIntoView: function(){
167
+ /*TODO*/
168
+ return;
169
+
170
+ },
171
+
172
+ onclick: function(event){
173
+ return __eval__(this.getAttribute('onclick')||'', this);
174
+ },
175
+
176
+
177
+ ondblclick: function(event){
178
+ return __eval__(this.getAttribute('ondblclick')||'', this);
179
+ },
180
+ onkeydown: function(event){
181
+ return __eval__(this.getAttribute('onkeydown')||'', this);
182
+ },
183
+ onkeypress: function(event){
184
+ return __eval__(this.getAttribute('onkeypress')||'', this);
185
+ },
186
+ onkeyup: function(event){
187
+ return __eval__(this.getAttribute('onkeyup')||'', this);
188
+ },
189
+ onmousedown: function(event){
190
+ return __eval__(this.getAttribute('onmousedown')||'', this);
191
+ },
192
+ onmousemove: function(event){
193
+ return __eval__(this.getAttribute('onmousemove')||'', this);
194
+ },
195
+ onmouseout: function(event){
196
+ return __eval__(this.getAttribute('onmouseout')||'', this);
197
+ },
198
+ onmouseover: function(event){
199
+ return __eval__(this.getAttribute('onmouseover')||'', this);
200
+ },
201
+ onmouseup: function(event){
202
+ return __eval__(this.getAttribute('onmouseup')||'', this);
203
+ },
204
+
205
+ appendChild: function( newChild, refChild ) {
206
+ var rv = DOMElement.prototype.appendChild.apply(this, arguments);
207
+ var node = newChild;
208
+ var pn = this;
209
+ while(pn.parentNode) {
210
+ pn = pn.parentNode;
211
+ }
212
+ if(pn === node.ownerDocument) {
213
+ __exec_script_tags__(newChild);
214
+ }
215
+ return rv;
216
+ }
217
+ });
218
+
219
+ var __exec_script_tags__ = function(node) {
220
+ var $env = __ownerDocument__(node)._parentWindow.$envx;
221
+ var doc = __ownerDocument__(node);
222
+ var type = ( node.type === null ) ? "text/javascript" : node.type;
223
+ // print("check exec",node,node.ownerDocument.in_inner_html);
224
+ // print(node,node.childNodes.length);
225
+ if(node.nodeName.toLowerCase() == 'script' && type == "text/javascript"){
226
+ // print("check",node,node.src,node.text,node.ownerDocument.in_inner_html,doc.parentWindow,node.executed);
227
+ if (node.ownerDocument.in_inner_html) {
228
+ //print("ignore",node);
229
+ node.executed = true;
230
+ } else if (doc.parentWindow &&
231
+ !node.ownerDocument.in_inner_html &&
232
+ !node.executed && (
233
+ (node.src && !node.src.match(/^\s*$/)) ||
234
+ (node.text && !node.text.match(/^\s*$/))
235
+ ) ) {
236
+ node.executed = true;
237
+ //p.replaceEntities = true;
238
+ //print("exec",node);
239
+ var okay = $env.loadLocalScript(node, null);
240
+ // only fire event if we actually had something to load
241
+ if (node.src && node.src.length > 0){
242
+ var event = doc.createEvent();
243
+ event.initEvent( okay ? "load" : "error", false, false );
244
+ node.dispatchEvent( event, false );
245
+ }
246
+ }
247
+ }
248
+ for(var i=0; i < node.childNodes.length; i++) {
249
+ __exec_script_tags__(node.childNodes[i]);
250
+ }
251
+ };
252
+
253
+ var __recursivelyGatherText__ = function(aNode) {
254
+ var accumulateText = "";
255
+ var idx; var n;
256
+ for (idx=0;idx < aNode.childNodes.length;idx++){
257
+ n = aNode.childNodes.item(idx);
258
+ if(n.nodeType == DOMNode.TEXT_NODE)
259
+ accumulateText += n.data;
260
+ else
261
+ accumulateText += __recursivelyGatherText__(n);
262
+ }
263
+
264
+ return accumulateText;
265
+ };
266
+
267
+ var __eval__ = function(script,node){
268
+ if (script == "")
269
+ return undefined;
270
+ try {
271
+ var scope = node;
272
+ var __scopes__ = [];
273
+ var original = script;
274
+ if(scope) {
275
+ // script = "(function(){return eval(original)}).call(__scopes__[0])";
276
+ script = "return (function(){"+original+"}).call(__scopes__[0])";
277
+ while(scope) {
278
+ __scopes__.push(scope);
279
+ scope = scope.parentNode;
280
+ script = "with(__scopes__["+(__scopes__.length-1)+"] ){"+script+"};";
281
+ }
282
+ }
283
+ script = "function(original,__scopes__){"+script+"}";
284
+ // print("scripta",script);
285
+ // print("scriptb",original);
286
+ var original_script_window = $master.first_script_window;
287
+ if ( !$master.first_script_window ) {
288
+ // $master.first_script_window = window;
289
+ }
290
+ // FIX!!!
291
+ var $inner = node.ownerDocument._parentWindow["$inner"];
292
+ var result = $master.evaluate(script,$inner)(original,__scopes__);
293
+ // $master.first_script_window = original_script_window;
294
+ return result;
295
+ }catch(e){
296
+ $warn("Exception during on* event eval: "+e);
297
+ throw e;
298
+ }
299
+ };
300
+
301
+ var __updateCss2Props__ = function(elem, values){
302
+ if(elem.$css2props === null){
303
+ elem.$css2props = new CSS2Properties(elem);
304
+ }
305
+ __cssTextToStyles__(elem.$css2props, values);
306
+ };
307
+
308
+ var __registerEventAttrs__ = function(elm){
309
+ if(elm.hasAttribute('onclick')){
310
+ elm.addEventListener('click', elm.onclick );
311
+ }
312
+ if(elm.hasAttribute('ondblclick')){
313
+ elm.addEventListener('dblclick', elm.onclick );
314
+ }
315
+ if(elm.hasAttribute('onkeydown')){
316
+ elm.addEventListener('keydown', elm.onclick );
317
+ }
318
+ if(elm.hasAttribute('onkeypress')){
319
+ elm.addEventListener('keypress', elm.onclick );
320
+ }
321
+ if(elm.hasAttribute('onkeyup')){
322
+ elm.addEventListener('keyup', elm.onclick );
323
+ }
324
+ if(elm.hasAttribute('onmousedown')){
325
+ elm.addEventListener('mousedown', elm.onclick );
326
+ }
327
+ if(elm.hasAttribute('onmousemove')){
328
+ elm.addEventListener('mousemove', elm.onclick );
329
+ }
330
+ if(elm.hasAttribute('onmouseout')){
331
+ elm.addEventListener('mouseout', elm.onclick );
332
+ }
333
+ if(elm.hasAttribute('onmouseover')){
334
+ elm.addEventListener('mouseover', elm.onclick );
335
+ }
336
+ if(elm.hasAttribute('onmouseup')){
337
+ elm.addEventListener('mouseup', elm.onclick );
338
+ }
339
+ return elm;
340
+ };
341
+
342
+ // non-ECMA function, but no other way for click events to enter env.js
343
+ var __click__ = function(element){
344
+ var event = new Event({
345
+ target:element,
346
+ currentTarget:element
347
+ });
348
+ event.initEvent("click");
349
+ element.dispatchEvent(event);
350
+ };
351
+ var __submit__ = function(element){
352
+ var event = new Event({
353
+ target:element,
354
+ currentTarget:element
355
+ });
356
+ event.initEvent("submit");
357
+ element.dispatchEvent(event);
358
+ };
359
+ var __focus__ = function(element){
360
+ var event = new Event({
361
+ target:element,
362
+ currentTarget:element
363
+ });
364
+ event.initEvent("focus");
365
+ element.dispatchEvent(event);
366
+ };
367
+ var __blur__ = function(element){
368
+ var event = new Event({
369
+ target:element,
370
+ currentTarget:element
371
+ });
372
+ event.initEvent("blur");
373
+ element.dispatchEvent(event);
374
+ };
375
+
376
+ // $w.HTMLElement = HTMLElement;
377
+
378
+ // Local Variables:
379
+ // espresso-indent-level:4
380
+ // c-basic-offset:4
381
+ // tab-width:4
382
+ // End:
@@ -0,0 +1,19 @@
1
+ $debug("Defining HTMLFieldSetElement");
2
+ /*
3
+ * HTMLFieldSetElement - DOM Level 2
4
+ */
5
+ var HTMLFieldSetElement = function(ownerDocument) {
6
+ this.HTMLLegendElement = HTMLLegendElement;
7
+ this.HTMLLegendElement(ownerDocument);
8
+ };
9
+ HTMLFieldSetElement.prototype = new HTMLLegendElement;
10
+ __extend__(HTMLFieldSetElement.prototype, {
11
+ get margin(){
12
+ return this.getAttribute('margin');
13
+ },
14
+ set margin(value){
15
+ this.setAttribute('margin',value);
16
+ }
17
+ });
18
+
19
+ // $w.HTMLFieldSetElement = HTMLFieldSetElement;
data/src/html/form.js ADDED
@@ -0,0 +1,484 @@
1
+ $debug("Defining HTMLFormElement");
2
+ /*
3
+ * HTMLFormElement - DOM Level 2
4
+ */
5
+ var HTMLFormElement = function(ownerDocument){
6
+ this.HTMLElement = HTMLElement;
7
+ this.HTMLElement(ownerDocument);
8
+ };
9
+ HTMLFormElement.prototype = new HTMLElement;
10
+ __extend__(HTMLFormElement.prototype,{
11
+ get acceptCharset(){
12
+ return this.getAttribute('accept-charset');
13
+
14
+ },
15
+ set acceptCharset(acceptCharset){
16
+ this.setAttribute('accept-charset', acceptCharset);
17
+
18
+ },
19
+ get action(){
20
+ return this.getAttribute('action');
21
+
22
+ },
23
+ set action(action){
24
+ this.setAttribute('action', action);
25
+
26
+ },
27
+ get elements() {
28
+ return this.getElementsByTagName("*");
29
+
30
+ },
31
+ get enctype(){
32
+ return this.getAttribute('enctype');
33
+
34
+ },
35
+ set enctype(enctype){
36
+ this.setAttribute('enctype', enctype);
37
+
38
+ },
39
+ get length() {
40
+ return this.elements.length;
41
+
42
+ },
43
+ get method(){
44
+ return this.getAttribute('method');
45
+
46
+ },
47
+ set method(action){
48
+ this.setAttribute('method', action);
49
+
50
+ },
51
+ get name() {
52
+ return this.getAttribute("name");
53
+
54
+ },
55
+ set name(val) {
56
+ return this.setAttribute("name",val);
57
+
58
+ },
59
+ get target() {
60
+ return this.getAttribute("target");
61
+
62
+ },
63
+ set target(val) {
64
+ return this.setAttribute("target",val);
65
+
66
+ },
67
+ submit:function(){
68
+ __submit__(this);
69
+
70
+ },
71
+ reset:function(){
72
+ __reset__(this);
73
+
74
+ },
75
+ onsubmit:function(){
76
+ var v;
77
+ if ((v = __eval__(this.getAttribute('onsubmit')||'', this)) != false) {
78
+ // this.submit();
79
+ }
80
+ return v;
81
+ },
82
+ onreset:function(){
83
+ var v;
84
+ if ((v = __eval__(this.getAttribute('onreset')||'', this)) != false) {
85
+ this.reset();
86
+ }
87
+ return v;
88
+ }
89
+ });
90
+
91
+ // $w.HTMLFormElement = HTMLFormElement;
92
+
93
+ /**
94
+ * Form Submissions
95
+ *
96
+ * This code is borrow largely from jquery.params and jquery.form.js
97
+ *
98
+ * formToArray() gathers form element data into an array of objects that can
99
+ * be passed to any of the following ajax functions: $.get, $.post, or load.
100
+ * Each object in the array has both a 'name' and 'value' property. An example of
101
+ * an array for a simple login form might be:
102
+ *
103
+ * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
104
+ *
105
+ * It is this array that is passed to pre-submit callback functions provided to the
106
+ * ajaxSubmit() and ajaxForm() methods.
107
+ *
108
+ * The semantic argument can be used to force form serialization in semantic order.
109
+ * This is normally true anyway, unless the form contains input elements of type='image'.
110
+ * If your form must be submitted with name/value pairs in semantic order and your form
111
+ * contains an input of type='image" then pass true for this arg, otherwise pass false
112
+ * (or nothing) to avoid the overhead for this logic.
113
+ *
114
+ *
115
+ * @name formToArray
116
+ * @param semantic true if serialization must maintain strict semantic ordering of elements (slower)
117
+ * @type Array<Object>
118
+ */
119
+ var __formToArray__ = function(form, semantic, boundary) {
120
+ var array = [],
121
+ elements = semantic ? form.getElementsByTagName('*') : form.elements,
122
+ element,
123
+ i,j,imax, jmax,
124
+ name,
125
+ value;
126
+
127
+ if (!elements)
128
+ return array;
129
+
130
+ imax = elements.length;
131
+ for(i=0; i < imax; i++) {
132
+ element = elements[i];
133
+ name = element.name;
134
+ if (!name)
135
+ continue;
136
+
137
+ if (semantic && form.clk && element.type == "image") {
138
+ // handle image inputs on the fly when semantic == true
139
+ if(!element.disabled && form.clk == element) {
140
+ if (form.clk_x) {
141
+ array.push({
142
+ name: name+'.x',
143
+ value: form.clk_x
144
+ });
145
+ }
146
+ if (form.clk_y) {
147
+ array.push({
148
+ name: name+'.y',
149
+ value: form.clk_y
150
+ });
151
+ }
152
+ }
153
+ continue;
154
+ }
155
+
156
+ value = __fieldValue__(element, true);
157
+ if (value && value.constructor == Array) {
158
+ jmax = value.length;
159
+ for(j=0; j < jmax; j++){
160
+ // FIX: handle uploads with the same name
161
+ array.push({name: name, value: value[j]});
162
+ }
163
+ } else if (value !== null && typeof value != 'undefined'){
164
+ array.push({name: name, value: value});
165
+ if(element.type == "file") {
166
+ var v = array[array.length-1];
167
+ v.filename = element.value || null;
168
+ }
169
+ }
170
+ }
171
+
172
+ if (!semantic && form.clk) {
173
+ // input type=='image' are not found in elements array! handle them here
174
+ elements = form.getElementsByTagName("input");
175
+ imax = imax=elements.length;
176
+ for(i=0; i < imax; i++) {
177
+ element = elements[i];
178
+ name = element.name;
179
+ if(name && !element.disabled && element.type == "image" && form.clk == element)
180
+ if (form.clk_x)
181
+ array.push({name: name+'.x', value: form.clk_x});
182
+ if (form.clk_y)
183
+ array.push({name: name+'.y', value: form.clk_y});
184
+ }
185
+ }
186
+ return array;
187
+ };
188
+
189
+
190
+ /**
191
+ * Serializes form data into a 'submittable' string. This method will return a string
192
+ * in the format: name1=value1&amp;name2=value2
193
+ *
194
+ * The semantic argument can be used to force form serialization in semantic order.
195
+ * If your form must be submitted with name/value pairs in semantic order then pass
196
+ * true for this arg, otherwise pass false (or nothing) to avoid the overhead for
197
+ * this logic (which can be significant for very large forms).
198
+ *
199
+ *
200
+ * @name formSerialize
201
+ * @param semantic true if serialization must maintain strict semantic ordering of elements (slower)
202
+ * @type String
203
+ */
204
+ var __formSerialize__ = function(form, semantic,boundary) {
205
+ //hand off to param for proper encoding
206
+ v = __param__(__formToArray__(form, semantic,boundary),boundary);
207
+ // print("v",v);
208
+ return v;
209
+ };
210
+ this.__formSerialize__ = __formSerialize__;
211
+
212
+ /**
213
+ * Serializes all field elements inputs Array into a query string.
214
+ * This method will return a string in the format: name1=value1&amp;name2=value2
215
+ *
216
+ * The successful argument controls whether or not serialization is limited to
217
+ * 'successful' controls (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
218
+ * The default value of the successful argument is true.
219
+ *
220
+ *
221
+ * @name fieldSerialize
222
+ * @param successful true if only successful controls should be serialized (default is true)
223
+ * @type String
224
+ */
225
+ var __fieldSerialize__ = function(inputs, successful) {
226
+ var array = [],
227
+ input,
228
+ name,
229
+ value,
230
+ i,j, imax, jmax;
231
+
232
+ imax = inputs.length;
233
+ for(i=0; i<imax; i++){
234
+ input = inputs[i];
235
+ name = input.name;
236
+ if (!name)
237
+ return;
238
+ value = __fieldValue__(input, successful);
239
+ if (value && value.constructor == Array) {
240
+ jmax = value.length;
241
+ for (j=0; j < max; j++){
242
+ array.push({
243
+ name: name,
244
+ value: value[j]
245
+ });
246
+ }
247
+ }else if (value !== null && typeof value != 'undefined'){
248
+ array.push({
249
+ name: input.name,
250
+ value: value
251
+ });
252
+ }
253
+ };
254
+ //hand off for proper encoding
255
+ return __param__(array);
256
+ };
257
+
258
+
259
+ /**
260
+ * Returns the value(s) of the element in the matched set. For example, consider the following form:
261
+ *
262
+ *
263
+ * The successful argument controls whether or not the field element must be 'successful'
264
+ * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
265
+ * The default value of the successful argument is true. If this value is false the value(s)
266
+ * for each element is returned.
267
+ *
268
+ * Note: This method *always* returns an array. If no valid value can be determined the
269
+ * array will be empty, otherwise it will contain one or more values.
270
+ *
271
+ *
272
+ * @name fieldValue
273
+ * @param Boolean successful true if only the values for successful controls
274
+ * should be returned (default is true)
275
+ * @type Array<String>
276
+ */
277
+ var __fieldValues__ = function(inputs, successful) {
278
+ var i,
279
+ imax = inputs.length,
280
+ element,
281
+ values = [],
282
+ value;
283
+ for (i=0; i < imax; i++) {
284
+ element = inputs[i];
285
+ value = __fieldValue__(element, successful);
286
+ if (value === null || typeof value == 'undefined' ||
287
+ (value.constructor == Array && !value.length))
288
+ continue;
289
+ value.constructor == Array ?
290
+ Array.prototype.push(values, value) :
291
+ values.push(value);
292
+ }
293
+ return values;
294
+ };
295
+
296
+ /**
297
+ * Returns the value of the field element.
298
+ *
299
+ * The successful argument controls whether or not the field element must be 'successful'
300
+ * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
301
+ * The default value of the successful argument is true. If the given element is not
302
+ * successful and the successful arg is not false then the returned value will be null.
303
+ *
304
+ * Note: If the successful flag is true (default) but the element is not successful, the return will be null
305
+ * Note: The value returned for a successful select-multiple element will always be an array.
306
+ * Note: If the element has no value the return value will be undefined.
307
+ *
308
+ * @name fieldValue
309
+ * @param Element el The DOM element for which the value will be returned
310
+ * @param Boolean successful true if value returned must be for a successful controls (default is true)
311
+ * @type String or Array<String> or null or undefined
312
+ */
313
+ var __fieldValue__ = function(element, successful) {
314
+ var name = element.name,
315
+ type = element.type,
316
+ tag = element.tagName.toLowerCase(),
317
+ index,
318
+ array,
319
+ options,
320
+ option,
321
+ one,
322
+ i, imax,
323
+ value;
324
+ if (typeof successful == 'undefined') successful = true;
325
+
326
+ // NOTE: changed to default to first selected: could do this when building the DOM?
327
+ // Probably, but a little unclear ...
328
+
329
+ if (successful && (!name || element.disabled || type == 'reset' || type == 'button' ||
330
+ (type == 'checkbox' || type == 'radio') && !element.checked ||
331
+ (type == 'submit' || type == 'image') &&
332
+ element.form && element.form.clk != element || (false && tag == 'select' &&
333
+ element.selectedIndex == -1)))
334
+ return null;
335
+
336
+ if (tag == 'select') {
337
+ index = element.selectedIndex;
338
+ // print("i",index);
339
+ if (index < 0)
340
+ // return null;
341
+ index = 0;
342
+ array = [];
343
+ options = element.options;
344
+ one = (type == 'select-one');
345
+ imax = (one ? index+1 : options.length);
346
+ i = (one ? index : 0);
347
+ for( i; i < imax; i++) {
348
+ option = options[i];
349
+ if (option && option.selected) {
350
+ value = option.value;
351
+ if (one)
352
+ return value;
353
+ array.push(value);
354
+ }
355
+ }
356
+ if (array.length === 0) {
357
+ if (element.options[0]) {
358
+ array.push( element.options[0].value );
359
+ }
360
+ }
361
+ return array;
362
+ }
363
+
364
+ // print("**",tag,type,element.value,element.innerText);
365
+
366
+ if (type == "file") {
367
+ return Ruby.File.basename(element.value);
368
+ }
369
+
370
+ if (tag == "textarea") {
371
+ return element.innerText;
372
+ }
373
+
374
+ return element.value;
375
+ };
376
+
377
+
378
+ /**
379
+ * Clears the form data. Takes the following actions on the form's input fields:
380
+ * - input text fields will have their 'value' property set to the empty string
381
+ * - select elements will have their 'selectedIndex' property set to -1
382
+ * - checkbox and radio inputs will have their 'checked' property set to false
383
+ * - inputs of type submit, button, reset, and hidden will *not* be effected
384
+ * - button elements will *not* be effected
385
+ *
386
+ *
387
+ * @name clearForm
388
+ */
389
+ var __clearForm__ = function(form) {
390
+ var i,
391
+ j, jmax,
392
+ elements,
393
+ resetable = ['input','select','textarea'];
394
+ for(i=0; i<resetable.lenth; i++){
395
+ elements = form.getElementsByTagName(resetable[i]);
396
+ jmax = elements.length;
397
+ for(j=0;j<jmax;j++){
398
+ __clearField__(elements[j]);
399
+ }
400
+ }
401
+ };
402
+
403
+ /**
404
+ * Clears the selected form element. Takes the following actions on the element:
405
+ * - input text fields will have their 'value' property set to the empty string
406
+ * - select elements will have their 'selectedIndex' property set to -1
407
+ * - checkbox and radio inputs will have their 'checked' property set to false
408
+ * - inputs of type submit, button, reset, and hidden will *not* be effected
409
+ * - button elements will *not* be effected
410
+ *
411
+ * @name clearFields
412
+ */
413
+ var __clearField__ = function(element) {
414
+ var type = element.type,
415
+ tag = element.tagName.toLowerCase();
416
+ if (type == 'text' || type == 'password' || tag == 'textarea')
417
+ element.value = '';
418
+ else if (type == 'checkbox' || type == 'radio')
419
+ element.checked = false;
420
+ else if (tag == 'select')
421
+ element.selectedIndex = -1;
422
+ };
423
+
424
+
425
+ // Serialize an array of key/values into a query string
426
+ var __param__= function( array, boundary ) {
427
+ var serialized = [];
428
+ if(boundary) {
429
+ for(i=0; i<array.length; i++){
430
+ if (array[i].filename === null) {
431
+ continue;
432
+ }
433
+ serialized.push( "--"+boundary + "\r\n" );
434
+ var fn = array[i].filename ? '; filename="'+array[i].value+'"' : "";
435
+ if (fn) {
436
+ var mime_type = "text/plain";
437
+ var transfer_encoding;
438
+ if (array[i].filename.match(/\.jpe?g$/)) {
439
+ mime_type = "image/jpeg";
440
+ transfer_encoding = "base64";
441
+ }
442
+ var content;
443
+ if (transfer_encoding === "base64") {
444
+ Ruby.require("base64");
445
+ content = Ruby.eval("lambda { |fn| Base64.encode64(File.read(fn)) }").call(array[i].filename);
446
+ } else {
447
+ content = Ruby.File.read(array[i].filename);
448
+ }
449
+ // FIX: better mime types
450
+ array[i].value = [ "Content-Type: "+mime_type ];
451
+ if(transfer_encoding) {
452
+ array[i].value.push("Content-Transfer-Encoding: "+transfer_encoding);
453
+ }
454
+ array[i].value.push("Content-Length: "+content.length);
455
+ array[i].value.push("");
456
+ array[i].value.push(content);
457
+ array[i].value = array[i].value.join("\r\n");
458
+ }
459
+ serialized.push('Content-Disposition: form-data; name="'+array[i].name+'"'+fn+'\r\n\r\n');
460
+ serialized.push(array[i].value);
461
+ serialized.push( "\r\n" );
462
+ }
463
+ serialized.push( "--"+boundary + "--\r\n" );
464
+ var v = serialized.join("");
465
+ // print("vvvv",v);
466
+ return v;
467
+ } else {
468
+ // Serialize the key/values
469
+ for(i=0; i<array.length; i++){
470
+ serialized[ serialized.length ] =
471
+ encodeURIComponent(array[i].name) + '=' +
472
+ encodeURIComponent(array[i].value);
473
+ }
474
+
475
+ // Return the resulting serialization
476
+ return serialized.join("&").replace(/%20/g, "+");
477
+ }
478
+ };
479
+
480
+ // Local Variables:
481
+ // espresso-indent-level:4
482
+ // c-basic-offset:4
483
+ // tab-width:4
484
+ // End: