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,67 @@
1
+ /**
2
+ * @author thatcher
3
+ */
4
+ $debug("Defining XPathResult");
5
+ /*
6
+ * XPathResult
7
+ */
8
+ /*
9
+ $w.__defineGetter__("XPathResult", function(){
10
+ return XPathResult;
11
+ });
12
+ */
13
+
14
+ var XPathResult = function(impl) {
15
+ this.current = 0;
16
+ this.impl = impl;
17
+ };
18
+
19
+ __extend__( XPathResult, {
20
+ ANY_TYPE: 0,
21
+ NUMBER_TYPE: 1,
22
+ STRING_TYPE: 2,
23
+ BOOLEAN_TYPE: 3,
24
+ UNORDERED_NODE_ITERATOR_TYPE: 4,
25
+ ORDERED_NODEITERATOR_TYPE: 5,
26
+ UNORDERED_NODE_SNAPSHOT_TYPE: 6,
27
+ ORDERED_NODE_SNAPSHOT_TYPE: 7,
28
+ ANY_ORDERED_NODE_TYPE: 8,
29
+ FIRST_ORDERED_NODE_TYPE: 9
30
+ });
31
+
32
+ __extend__(XPathResult.prototype, {
33
+ get booleanValue(){
34
+ this.impl.booleanValue();
35
+ },
36
+ get stringValue(){
37
+ this.impl.stringValue();
38
+ },
39
+ /*
40
+ get invalidIteration(){
41
+ throw new Error("implement invalidIteration");
42
+ //TODO
43
+ },
44
+ */
45
+ get numberValue(){
46
+ this.impl.numberValue();
47
+ },
48
+ /*
49
+ get resultType(){
50
+ throw new Error("implement resultType");
51
+ //TODO
52
+ },
53
+ */
54
+ get singleNodeValue(){
55
+ return this.impl.nodeSetValue()[0];
56
+ },
57
+ get snapshotLength(){
58
+ return this.impl.nodeSetValue().length;
59
+ },
60
+ snapshotItem: function(index){
61
+ return this.impl.nodeSetValue()[index];
62
+ },
63
+ iterateNext: function(){
64
+ return this.impl.nodeSetValue()[this.current++];
65
+ }
66
+ });
67
+
data/src/xpath/util.js ADDED
@@ -0,0 +1,551 @@
1
+ // Copyright 2005 Google
2
+ //
3
+ // Author: Steffen Meschkat <mesch@google.com>
4
+ //
5
+ // Miscellaneous utility and placeholder functions.
6
+
7
+ // Dummy implmentation for the logging functions. Replace by something
8
+ // useful when you want to debug.
9
+ function xpathLog(msg) {print(msg)};
10
+ function xpathLog(msg) {/*print(msg)*/};
11
+ function xsltLog(msg) {};
12
+ function xsltLogXml(msg) {};
13
+
14
+ /* ENVJS CHANGE */
15
+ var ajaxsltIsIE6 = false; // navigator.appVersion.match(/MSIE 6.0/);
16
+
17
+ // Throws an exception if false.
18
+ function assert(b) {
19
+ if (!b) {
20
+ throw "Assertion failed";
21
+ }
22
+ }
23
+
24
+ // Splits a string s at all occurrences of character c. This is like
25
+ // the split() method of the string object, but IE omits empty
26
+ // strings, which violates the invariant (s.split(x).join(x) == s).
27
+ function stringSplit(s, c) {
28
+ var a = s.indexOf(c);
29
+ if (a == -1) {
30
+ return [ s ];
31
+ }
32
+ var parts = [];
33
+ parts.push(s.substr(0,a));
34
+ while (a != -1) {
35
+ var a1 = s.indexOf(c, a + 1);
36
+ if (a1 != -1) {
37
+ parts.push(s.substr(a + 1, a1 - a - 1));
38
+ } else {
39
+ parts.push(s.substr(a + 1));
40
+ }
41
+ a = a1;
42
+ }
43
+ return parts;
44
+ }
45
+
46
+ // The following function does what document.importNode(node, true)
47
+ // would do for us here; however that method is broken in Safari/1.3,
48
+ // so we have to emulate it.
49
+ function xmlImportNode(doc, node) {
50
+ if (node.nodeType == DOMNode.TEXT_NODE) {
51
+ return domCreateTextNode(doc, node.nodeValue);
52
+
53
+ } else if (node.nodeType == DOMNode.CDATA_SECTION_NODE) {
54
+ return domCreateCDATASection(doc, node.nodeValue);
55
+
56
+ } else if (node.nodeType == DOMNode.ELEMENT_NODE) {
57
+ var newNode = domCreateElement(doc, node.nodeName);
58
+ for (var i = 0; i < node.attributes.length; ++i) {
59
+ var an = node.attributes[i];
60
+ var name = an.nodeName;
61
+ var value = an.nodeValue;
62
+ domSetAttribute(newNode, name, value);
63
+ }
64
+
65
+ for (var c = node.firstChild; c; c = c.nextSibling) {
66
+ var cn = arguments.callee(doc, c);
67
+ domAppendChild(newNode, cn);
68
+ }
69
+
70
+ return newNode;
71
+
72
+ } else {
73
+ return domCreateComment(doc, node.nodeName);
74
+ }
75
+ }
76
+
77
+ // A set data structure. It can also be used as a map (i.e. the keys
78
+ // can have values other than 1), but we don't call it map because it
79
+ // would be ambiguous in this context. Also, the map is iterable, so
80
+ // we can use it to replace for-in loops over core javascript Objects.
81
+ // For-in iteration breaks when Object.prototype is modified, which
82
+ // some clients of the maps API do.
83
+ //
84
+ // NOTE(mesch): The set keys by the string value of its element, NOT
85
+ // by the typed value. In particular, objects can't be used as keys.
86
+ //
87
+ // @constructor
88
+ function Set() {
89
+ this.keys = [];
90
+ }
91
+
92
+ Set.prototype.size = function() {
93
+ return this.keys.length;
94
+ }
95
+
96
+ // Adds the entry to the set, ignoring if it is present.
97
+ Set.prototype.add = function(key, opt_value) {
98
+ var value = opt_value || 1;
99
+ if (!this.contains(key)) {
100
+ this[':' + key] = value;
101
+ this.keys.push(key);
102
+ }
103
+ }
104
+
105
+ // Sets the entry in the set, adding if it is not yet present.
106
+ Set.prototype.set = function(key, opt_value) {
107
+ var value = opt_value || 1;
108
+ if (!this.contains(key)) {
109
+ this[':' + key] = value;
110
+ this.keys.push(key);
111
+ } else {
112
+ this[':' + key] = value;
113
+ }
114
+ }
115
+
116
+ // Increments the key's value by 1. This works around the fact that
117
+ // numbers are always passed by value, never by reference, so that we
118
+ // can't increment the value returned by get(), or the iterator
119
+ // argument. Sets the key's value to 1 if it doesn't exist yet.
120
+ Set.prototype.inc = function(key) {
121
+ if (!this.contains(key)) {
122
+ this[':' + key] = 1;
123
+ this.keys.push(key);
124
+ } else {
125
+ this[':' + key]++;
126
+ }
127
+ }
128
+
129
+ Set.prototype.get = function(key) {
130
+ if (this.contains(key)) {
131
+ return this[':' + key];
132
+ } else {
133
+ var undefined;
134
+ return undefined;
135
+ }
136
+ }
137
+
138
+ // Removes the entry from the set.
139
+ Set.prototype.remove = function(key) {
140
+ if (this.contains(key)) {
141
+ delete this[':' + key];
142
+ removeFromArray(this.keys, key, true);
143
+ }
144
+ }
145
+
146
+ // Tests if an entry is in the set.
147
+ Set.prototype.contains = function(entry) {
148
+ return typeof this[':' + entry] != 'undefined';
149
+ }
150
+
151
+ // Gets a list of values in the set.
152
+ Set.prototype.items = function() {
153
+ var list = [];
154
+ for (var i = 0; i < this.keys.length; ++i) {
155
+ var k = this.keys[i];
156
+ var v = this[':' + k];
157
+ list.push(v);
158
+ }
159
+ return list;
160
+ }
161
+
162
+
163
+ // Invokes function f for every key value pair in the set as a method
164
+ // of the set.
165
+ Set.prototype.map = function(f) {
166
+ for (var i = 0; i < this.keys.length; ++i) {
167
+ var k = this.keys[i];
168
+ f.call(this, k, this[':' + k]);
169
+ }
170
+ }
171
+
172
+ Set.prototype.clear = function() {
173
+ for (var i = 0; i < this.keys.length; ++i) {
174
+ delete this[':' + this.keys[i]];
175
+ }
176
+ this.keys.length = 0;
177
+ }
178
+
179
+
180
+ // Applies the given function to each element of the array, preserving
181
+ // this, and passing the index.
182
+ function mapExec(array, func) {
183
+ for (var i = 0; i < array.length; ++i) {
184
+ func.call(this, array[i], i);
185
+ }
186
+ }
187
+
188
+ // Returns an array that contains the return value of the given
189
+ // function applied to every element of the input array.
190
+ function mapExpr(array, func) {
191
+ var ret = [];
192
+ for (var i = 0; i < array.length; ++i) {
193
+ ret.push(func(array[i]));
194
+ }
195
+ return ret;
196
+ };
197
+
198
+ // Reverses the given array in place.
199
+ function reverseInplace(array) {
200
+ for (var i = 0; i < array.length / 2; ++i) {
201
+ var h = array[i];
202
+ var ii = array.length - i - 1;
203
+ array[i] = array[ii];
204
+ array[ii] = h;
205
+ }
206
+ }
207
+
208
+ // Removes value from array. Returns the number of instances of value
209
+ // that were removed from array.
210
+ function removeFromArray(array, value, opt_notype) {
211
+ var shift = 0;
212
+ for (var i = 0; i < array.length; ++i) {
213
+ if (array[i] === value || (opt_notype && array[i] == value)) {
214
+ array.splice(i--, 1);
215
+ shift++;
216
+ }
217
+ }
218
+ return shift;
219
+ }
220
+
221
+ // Shallow-copies an array to the end of another array
222
+ // Basically Array.concat, but works with other non-array collections
223
+ function copyArray(dst, src) {
224
+ if (!src) return;
225
+ var dstLength = dst.length;
226
+ for (var i = src.length - 1; i >= 0; --i) {
227
+ dst[i+dstLength] = src[i];
228
+ }
229
+ }
230
+
231
+ /**
232
+ * This is an optimization for copying attribute lists in IE. IE includes many
233
+ * extraneous properties in its DOM attribute lists, which take require
234
+ * significant extra processing when evaluating attribute steps. With this
235
+ * function, we ignore any such attributes that has an empty string value.
236
+ */
237
+ function copyArrayIgnoringAttributesWithoutValue(dst, src)
238
+ {
239
+ if (!src) return;
240
+ for (var i = src.length - 1; i >= 0; --i) {
241
+ // this test will pass so long as the attribute has a non-empty string
242
+ // value, even if that value is "false", "0", "undefined", etc.
243
+ if (src[i].nodeValue) {
244
+ dst.push(src[i]);
245
+ }
246
+ }
247
+ }
248
+
249
+ // Returns the text value of a node; for nodes without children this
250
+ // is the nodeValue, for nodes with children this is the concatenation
251
+ // of the value of all children. Browser-specific optimizations are used by
252
+ // default; they can be disabled by passing "true" in as the second parameter.
253
+ function xmlValue(node, disallowBrowserSpecificOptimization) {
254
+ if (!node) {
255
+ return '';
256
+ }
257
+
258
+ var ret = '';
259
+ if (node.nodeType == DOMNode.TEXT_NODE ||
260
+ node.nodeType == DOMNode.CDATA_SECTION_NODE) {
261
+ ret += node.nodeValue;
262
+
263
+ } else if (node.nodeType == DOMNode.ATTRIBUTE_NODE) {
264
+ if (ajaxsltIsIE6) {
265
+ ret += xmlValueIE6Hack(node);
266
+ } else {
267
+ ret += node.nodeValue;
268
+ }
269
+ } else if (node.nodeType == DOMNode.ELEMENT_NODE ||
270
+ node.nodeType == DOMNode.DOCUMENT_NODE ||
271
+ node.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
272
+ if (!disallowBrowserSpecificOptimization) {
273
+ // IE, Safari, Opera, and friends
274
+ var innerText = node.innerText;
275
+ if (innerText != undefined) {
276
+ return innerText;
277
+ }
278
+ // Firefox
279
+ var textContent = node.textContent;
280
+ if (textContent != undefined) {
281
+ return textContent;
282
+ }
283
+ }
284
+ // pobrecito!
285
+ var len = node.childNodes.length;
286
+ for (var i = 0; i < len; ++i) {
287
+ ret += arguments.callee(node.childNodes[i]);
288
+ }
289
+ }
290
+ return ret;
291
+ }
292
+
293
+ function xmlValueIE6Hack(node) {
294
+ // Issue 19, IE6 mangles href attribute when it's a javascript: url
295
+ var nodeName = node.nodeName;
296
+ var nodeValue = node.nodeValue;
297
+ if (nodeName.length != 4) return nodeValue;
298
+ if (!/^href$/i.test(nodeName)) return nodeValue;
299
+ if (!/^javascript:/.test(nodeValue)) return nodeValue;
300
+ return unescape(nodeValue);
301
+ }
302
+
303
+ // Returns the representation of a node as XML text.
304
+ function xmlText(node, opt_cdata) {
305
+ var buf = [];
306
+ xmlTextR(node, buf, opt_cdata);
307
+ return buf.join('');
308
+ }
309
+
310
+ function xmlTextR(node, buf, cdata) {
311
+ if (node.nodeType == DOMNode.TEXT_NODE) {
312
+ buf.push(xmlEscapeText(node.nodeValue));
313
+
314
+ } else if (node.nodeType == DOMNode.CDATA_SECTION_NODE) {
315
+ if (cdata) {
316
+ buf.push(node.nodeValue);
317
+ } else {
318
+ buf.push('<![CDATA[' + node.nodeValue + ']]>');
319
+ }
320
+
321
+ } else if (node.nodeType == DOMNode.COMMENT_NODE) {
322
+ buf.push('<!--' + node.nodeValue + '-->');
323
+
324
+ } else if (node.nodeType == DOMNode.ELEMENT_NODE) {
325
+ buf.push('<' + xmlFullNodeName(node));
326
+ for (var i = 0; i < node.attributes.length; ++i) {
327
+ var a = node.attributes[i];
328
+ if (a && a.nodeName && a.nodeValue) {
329
+ buf.push(' ' + xmlFullNodeName(a) + '="' +
330
+ xmlEscapeAttr(a.nodeValue) + '"');
331
+ }
332
+ }
333
+
334
+ if (node.childNodes.length == 0) {
335
+ buf.push('/>');
336
+ } else {
337
+ buf.push('>');
338
+ for (var i = 0; i < node.childNodes.length; ++i) {
339
+ arguments.callee(node.childNodes[i], buf, cdata);
340
+ }
341
+ buf.push('</' + xmlFullNodeName(node) + '>');
342
+ }
343
+
344
+ } else if (node.nodeType == DOMNode.DOCUMENT_NODE ||
345
+ node.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) {
346
+ for (var i = 0; i < node.childNodes.length; ++i) {
347
+ arguments.callee(node.childNodes[i], buf, cdata);
348
+ }
349
+ }
350
+ }
351
+
352
+ function xmlFullNodeName(n) {
353
+ if (n.prefix && n.nodeName.indexOf(n.prefix + ':') != 0) {
354
+ return n.prefix + ':' + n.nodeName;
355
+ } else {
356
+ return n.nodeName;
357
+ }
358
+ }
359
+
360
+ // Escape XML special markup chracters: tag delimiter < > and entity
361
+ // reference start delimiter &. The escaped string can be used in XML
362
+ // text portions (i.e. between tags).
363
+ function xmlEscapeText(s) {
364
+ return ('' + s).replace(/&/g, '&amp;').replace(/</g, '&lt;').
365
+ replace(/>/g, '&gt;');
366
+ }
367
+
368
+ // Escape XML special markup characters: tag delimiter < > entity
369
+ // reference start delimiter & and quotes ". The escaped string can be
370
+ // used in double quoted XML attribute value portions (i.e. in
371
+ // attributes within start tags).
372
+ function xmlEscapeAttr(s) {
373
+ return xmlEscapeText(s).replace(/\"/g, '&quot;');
374
+ }
375
+
376
+ // Escape markup in XML text, but don't touch entity references. The
377
+ // escaped string can be used as XML text (i.e. between tags).
378
+ function xmlEscapeTags(s) {
379
+ return s.replace(/</g, '&lt;').replace(/>/g, '&gt;');
380
+ }
381
+
382
+ /**
383
+ * Wrapper function to access the owner document uniformly for document
384
+ * and other nodes: for the document node, the owner document is the
385
+ * node itself, for all others it's the ownerDocument property.
386
+ *
387
+ * @param {Node} node
388
+ * @return {Document}
389
+ */
390
+ function xmlOwnerDocument(node) {
391
+ if (node.nodeType == DOMNode.DOCUMENT_NODE) {
392
+ return node;
393
+ } else {
394
+ return node.ownerDocument;
395
+ }
396
+ }
397
+
398
+ // Wrapper around DOM methods so we can condense their invocations.
399
+ function domGetAttribute(node, name) {
400
+ return node.getAttribute(name);
401
+ }
402
+
403
+ function domSetAttribute(node, name, value) {
404
+ return node.setAttribute(name, value);
405
+ }
406
+
407
+ function domRemoveAttribute(node, name) {
408
+ return node.removeAttribute(name);
409
+ }
410
+
411
+ function domAppendChild(node, child) {
412
+ return node.appendChild(child);
413
+ }
414
+
415
+ function domRemoveChild(node, child) {
416
+ return node.removeChild(child);
417
+ }
418
+
419
+ function domReplaceChild(node, newChild, oldChild) {
420
+ return node.replaceChild(newChild, oldChild);
421
+ }
422
+
423
+ function domInsertBefore(node, newChild, oldChild) {
424
+ return node.insertBefore(newChild, oldChild);
425
+ }
426
+
427
+ function domRemoveNode(node) {
428
+ return domRemoveChild(node.parentNode, node);
429
+ }
430
+
431
+ function domCreateTextNode(doc, text) {
432
+ return doc.createTextNode(text);
433
+ }
434
+
435
+ function domCreateElement(doc, name) {
436
+ return doc.createElement(name);
437
+ }
438
+
439
+ function domCreateAttribute(doc, name) {
440
+ return doc.createAttribute(name);
441
+ }
442
+
443
+ function domCreateCDATASection(doc, data) {
444
+ return doc.createCDATASection(data);
445
+ }
446
+
447
+ function domCreateComment(doc, text) {
448
+ return doc.createComment(text);
449
+ }
450
+
451
+ function domCreateDocumentFragment(doc) {
452
+ return doc.createDocumentFragment();
453
+ }
454
+
455
+ function domGetElementById(doc, id) {
456
+ return doc.getElementById(id);
457
+ }
458
+
459
+ // Same for window methods.
460
+ function windowSetInterval(win, fun, time) {
461
+ return win.setInterval(fun, time);
462
+ }
463
+
464
+ function windowClearInterval(win, id) {
465
+ return win.clearInterval(id);
466
+ }
467
+
468
+ /**
469
+ * Escape the special regular expression characters when the regular expression
470
+ * is specified as a string.
471
+ *
472
+ * Based on: http://simonwillison.net/2006/Jan/20/escape/
473
+ */
474
+ RegExp.escape = (function() {
475
+ var specials = [
476
+ '/', '.', '*', '+', '?', '|', '^', '$',
477
+ '(', ')', '[', ']', '{', '}', '\\'
478
+ ];
479
+
480
+ var sRE = new RegExp(
481
+ '(\\' + specials.join('|\\') + ')', 'g'
482
+ );
483
+
484
+ return function(text) {
485
+ return text.replace(sRE, '\\$1');
486
+ }
487
+ })();
488
+
489
+ /**
490
+ * Determines whether a predicate expression contains a "positional selector".
491
+ * A positional selector filters nodes from the nodelist input based on their
492
+ * position within that list. When such selectors are encountered, the
493
+ * evaluation of the predicate cannot be depth-first, because the positional
494
+ * selector may be based on the result of evaluating predicates that precede
495
+ * it.
496
+ */
497
+ function predicateExprHasPositionalSelector(expr, isRecursiveCall) {
498
+ if (!expr) {
499
+ return false;
500
+ }
501
+ if (!isRecursiveCall && exprReturnsNumberValue(expr)) {
502
+ // this is a "proximity position"-based predicate
503
+ return true;
504
+ }
505
+ if (expr instanceof FunctionCallExpr) {
506
+ var value = expr.name.value;
507
+ return (value == 'last' || value == 'position');
508
+ }
509
+ if (expr instanceof BinaryExpr) {
510
+ return (
511
+ predicateExprHasPositionalSelector(expr.expr1, true) ||
512
+ predicateExprHasPositionalSelector(expr.expr2, true));
513
+ }
514
+ return false;
515
+ }
516
+
517
+ function exprReturnsNumberValue(expr) {
518
+ if (expr instanceof FunctionCallExpr) {
519
+ var isMember = {
520
+ last: true
521
+ , position: true
522
+ , count: true
523
+ , 'string-length': true
524
+ , number: true
525
+ , sum: true
526
+ , floor: true
527
+ , ceiling: true
528
+ , round: true
529
+ };
530
+ return isMember[expr.name.value];
531
+ }
532
+ else if (expr instanceof UnaryMinusExpr) {
533
+ return true;
534
+ }
535
+ else if (expr instanceof BinaryExpr) {
536
+ var isMember = {
537
+ '+': true
538
+ , '-': true
539
+ , '*': true
540
+ , mod: true
541
+ , div: true
542
+ };
543
+ return isMember[expr.op.value];
544
+ }
545
+ else if (expr instanceof NumberExpr) {
546
+ return true;
547
+ }
548
+ return false;
549
+ }
550
+
551
+