envjs19 0.3.8.20101029121421
Sign up to get free protection for your applications and to get access to all the features.
- data/.jslintrbrc +30 -0
- data/.project +17 -0
- data/CHANGELOG.rdoc +57 -0
- data/DTD/xhtml-lat1.ent +196 -0
- data/DTD/xhtml-special.ent +80 -0
- data/DTD/xhtml-symbol.ent +237 -0
- data/DTD/xhtml.soc +14 -0
- data/DTD/xhtml1-frameset.dtd +1235 -0
- data/DTD/xhtml1-strict.dtd +978 -0
- data/DTD/xhtml1-transitional.dtd +1201 -0
- data/DTD/xhtml1.dcl +192 -0
- data/Makefile +7 -0
- data/Manifest.txt +280 -0
- data/README.rdoc +65 -0
- data/Rakefile +196 -0
- data/Wakefile +11 -0
- data/bin/envjsrb +257 -0
- data/build.properties +9 -0
- data/build.xml +247 -0
- data/gm/jquery.js +6002 -0
- data/gm/mainx.js +2648 -0
- data/gm/sensx.js +135 -0
- data/gm/t.js +6 -0
- data/gm/x.html +76 -0
- data/htmlparser/BrowserTreeBuilder.java +456 -0
- data/htmlparser/README +34 -0
- data/htmlparser/build.sh +38 -0
- data/jsl/jsl +0 -0
- data/jsl/jsl.default.conf +129 -0
- data/jsl/jsl.exe +0 -0
- data/lib/envjs.rb +35 -0
- data/lib/envjs/event_loop.js +206 -0
- data/lib/envjs/net.rb +3 -0
- data/lib/envjs/net/cgi.rb +94 -0
- data/lib/envjs/net/file.rb +69 -0
- data/lib/envjs/options.rb +11 -0
- data/lib/envjs/runtime.rb +346 -0
- data/lib/envjs/tempfile.rb +24 -0
- data/licenses/GPL-LICENSE.txt +278 -0
- data/licenses/MIT-LICENSE.txt +20 -0
- data/src/base64.js +80 -0
- data/src/build.js +6 -0
- data/src/cruft/bad.html +24 -0
- data/src/cruft/dom.js +606 -0
- data/src/cruft/element.js +297 -0
- data/src/cruft/good.html +30 -0
- data/src/cruft/good.js +32 -0
- data/src/cruft/internal.js +81 -0
- data/src/cruft/parser.js +458 -0
- data/src/css/properties.js +293 -0
- data/src/css/rule.js +22 -0
- data/src/css/sizzle.js +717 -0
- data/src/css/stylesheet.js +52 -0
- data/src/dom/attr.js +55 -0
- data/src/dom/cdatasection.js +31 -0
- data/src/dom/characterdata.js +119 -0
- data/src/dom/comment.js +30 -0
- data/src/dom/doctype.js +9 -0
- data/src/dom/document.js +1023 -0
- data/src/dom/dom.js +134 -0
- data/src/dom/element.js +217 -0
- data/src/dom/entities.js +273 -0
- data/src/dom/exception.js +28 -0
- data/src/dom/fragment.js +37 -0
- data/src/dom/implementation.js +140 -0
- data/src/dom/instruction.js +51 -0
- data/src/dom/namednodemap.js +374 -0
- data/src/dom/namespace.js +50 -0
- data/src/dom/node.js +618 -0
- data/src/dom/nodelist.js +195 -0
- data/src/dom/parser.js +1207 -0
- data/src/dom/text.js +73 -0
- data/src/event/event.js +47 -0
- data/src/event/mouseevent.js +4 -0
- data/src/event/uievent.js +8 -0
- data/src/html/a.js +110 -0
- data/src/html/anchor.js +80 -0
- data/src/html/area.js +57 -0
- data/src/html/base.js +26 -0
- data/src/html/blockquote-q.js +19 -0
- data/src/html/body.js +19 -0
- data/src/html/button.js +21 -0
- data/src/html/canvas.js +14 -0
- data/src/html/col-colgroup.js +49 -0
- data/src/html/collection.js +72 -0
- data/src/html/cookie.js +153 -0
- data/src/html/del-ins.js +25 -0
- data/src/html/div.js +28 -0
- data/src/html/document.js +364 -0
- data/src/html/element.js +382 -0
- data/src/html/fieldset.js +19 -0
- data/src/html/form.js +484 -0
- data/src/html/frame.js +89 -0
- data/src/html/frameset.js +25 -0
- data/src/html/head.js +44 -0
- data/src/html/html.js +0 -0
- data/src/html/htmlparser.js +340 -0
- data/src/html/iframe.js +26 -0
- data/src/html/image.js +0 -0
- data/src/html/img.js +62 -0
- data/src/html/input-elements.js +307 -0
- data/src/html/input.js +65 -0
- data/src/html/label.js +26 -0
- data/src/html/legend.js +19 -0
- data/src/html/link.js +82 -0
- data/src/html/map.js +22 -0
- data/src/html/meta.js +37 -0
- data/src/html/object.js +89 -0
- data/src/html/optgroup.js +25 -0
- data/src/html/option.js +103 -0
- data/src/html/param.js +38 -0
- data/src/html/script.js +122 -0
- data/src/html/select.js +132 -0
- data/src/html/style.js +31 -0
- data/src/html/table.js +199 -0
- data/src/html/tbody-thead-tfoot.js +92 -0
- data/src/html/td-th.js +18 -0
- data/src/html/textarea.js +31 -0
- data/src/html/title.js +20 -0
- data/src/html/tr.js +114 -0
- data/src/intro.js +141 -0
- data/src/outro.js +70 -0
- data/src/parser/html5.detailed.js +10762 -0
- data/src/parser/html5.min.js +503 -0
- data/src/parser/html5.pretty.js +10815 -0
- data/src/parser/intro.js +42 -0
- data/src/parser/outro.js +9 -0
- data/src/platform/core.js +323 -0
- data/src/platform/johnson.js +484 -0
- data/src/platform/rhino.js +327 -0
- data/src/platform/static/intro.js +41 -0
- data/src/platform/static/outro.js +30 -0
- data/src/profile/aop.js +238 -0
- data/src/profile/profile.js +402 -0
- data/src/serializer/xml.js +21 -0
- data/src/svg/animatedstring.js +25 -0
- data/src/svg/document.js +25 -0
- data/src/svg/element.js +22 -0
- data/src/svg/locatable.js +17 -0
- data/src/svg/rect.js +18 -0
- data/src/svg/rectelement.js +24 -0
- data/src/svg/stylable.js +49 -0
- data/src/svg/svgelement.js +22 -0
- data/src/svg/transformable.js +15 -0
- data/src/window/css.js +15 -0
- data/src/window/dialog.js +16 -0
- data/src/window/document.js +28 -0
- data/src/window/event.js +265 -0
- data/src/window/history.js +62 -0
- data/src/window/location.js +156 -0
- data/src/window/navigator.js +48 -0
- data/src/window/screen.js +53 -0
- data/src/window/timer.js +21 -0
- data/src/window/window.js +284 -0
- data/src/window/xhr.js +135 -0
- data/src/xpath/expression.js +49 -0
- data/src/xpath/implementation.js +2505 -0
- data/src/xpath/result.js +67 -0
- data/src/xpath/util.js +551 -0
- data/src/xpath/xmltoken.js +149 -0
- data/src/xslt/COPYING +34 -0
- data/src/xslt/ajaxslt-0.8.1/AUTHORS +1 -0
- data/src/xslt/ajaxslt-0.8.1/ChangeLog +136 -0
- data/src/xslt/ajaxslt-0.8.1/Makefile +49 -0
- data/src/xslt/ajaxslt-0.8.1/README +102 -0
- data/src/xslt/ajaxslt-0.8.1/TODO +15 -0
- data/src/xslt/ajaxslt-0.8.1/dom.js +566 -0
- data/src/xslt/ajaxslt-0.8.1/dom_unittest.html +24 -0
- data/src/xslt/ajaxslt-0.8.1/dom_unittest.js +131 -0
- data/src/xslt/ajaxslt-0.8.1/simplelog.js +79 -0
- data/src/xslt/ajaxslt-0.8.1/test/xpath.html +18 -0
- data/src/xslt/ajaxslt-0.8.1/test/xpath_script.js +45 -0
- data/src/xslt/ajaxslt-0.8.1/test/xslt.html +58 -0
- data/src/xslt/ajaxslt-0.8.1/test/xslt_script.js +33 -0
- data/src/xslt/ajaxslt-0.8.1/unittestsuite.html +26 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken.js +149 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.html +18 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.js +811 -0
- data/src/xslt/ajaxslt-0.8.1/xpath_unittest.html +39 -0
- data/src/xslt/ajaxslt-0.8.1/xpath_unittest.js +557 -0
- data/src/xslt/ajaxslt-0.8.1/xpathdebug.js +234 -0
- data/src/xslt/ajaxslt-0.8.1/xslt_unittest.html +138 -0
- data/src/xslt/ajaxslt-0.8.1/xslt_unittest.js +68 -0
- data/src/xslt/implementation.js +625 -0
- data/src/xslt/processor.js +37 -0
- data/src/xslt/util.js +449 -0
- data/test/base64.js +80 -0
- data/test/call-load-test.js +15 -0
- data/test/data.js +45 -0
- data/test/debug.js +53 -0
- data/test/firebug/errorIcon.png +0 -0
- data/test/firebug/firebug.css +209 -0
- data/test/firebug/firebug.html +23 -0
- data/test/firebug/firebug.js +672 -0
- data/test/firebug/firebugx.js +10 -0
- data/test/firebug/infoIcon.png +0 -0
- data/test/firebug/warningIcon.png +0 -0
- data/test/fixtures/html/events.html +171 -0
- data/test/fixtures/html/iframe1.html +46 -0
- data/test/fixtures/html/iframe1a.html +46 -0
- data/test/fixtures/html/iframe2.html +45 -0
- data/test/fixtures/html/iframe3.html +28 -0
- data/test/fixtures/html/iframeN.html +57 -0
- data/test/fixtures/html/malformed.html +181 -0
- data/test/fixtures/html/scope.html +81 -0
- data/test/fixtures/html/trivial.html +19 -0
- data/test/fixtures/html/with_js.html +26 -0
- data/test/fixtures/images/icon-blue.png +0 -0
- data/test/fixtures/js/external_script.js +1 -0
- data/test/fixtures/js/script.js +1 -0
- data/test/fixtures/js/script_error.js +2 -0
- data/test/foo.html +8 -0
- data/test/foo.js +40 -0
- data/test/html/events.html +171 -0
- data/test/html/iframe1.html +46 -0
- data/test/html/iframe1a.html +46 -0
- data/test/html/iframe2.html +45 -0
- data/test/html/iframe3.html +30 -0
- data/test/html/iframeN.html +57 -0
- data/test/html/malformed.html +181 -0
- data/test/html/scope.html +87 -0
- data/test/html/script.js +1 -0
- data/test/html/trivial.html +19 -0
- data/test/html/with_js.html +26 -0
- data/test/index.html +328 -0
- data/test/java-prototype.js +9 -0
- data/test/jquery.js +6002 -0
- data/test/primary-tests.js +26 -0
- data/test/prototype-test.js +13 -0
- data/test/qunit.js +61 -0
- data/test/qunit/qunit/qunit.css +17 -0
- data/test/qunit/qunit/qunit.js +997 -0
- data/test/scope.html +19 -0
- data/test/scope.rb +24 -0
- data/test/smp/dmathieu/index.html +8 -0
- data/test/specs/dist/env.spec.js +1534 -0
- data/test/specs/envjs.spec.css +46 -0
- data/test/specs/parser/html.js +31 -0
- data/test/specs/parser/spec.html +40 -0
- data/test/specs/parser/xml.js +31 -0
- data/test/specs/qunit.bdd.js +210 -0
- data/test/specs/qunit.css +17 -0
- data/test/specs/qunit.js +997 -0
- data/test/specs/template/spec-0.js +31 -0
- data/test/specs/template/spec-1.js +31 -0
- data/test/specs/template/spec.html +40 -0
- data/test/specs/window/css.js +23 -0
- data/test/specs/window/dialog.js +25 -0
- data/test/specs/window/document.js +23 -0
- data/test/specs/window/event.js +25 -0
- data/test/specs/window/history.js +34 -0
- data/test/specs/window/location.js +34 -0
- data/test/specs/window/navigator.js +71 -0
- data/test/specs/window/screen.js +42 -0
- data/test/specs/window/spec.html +48 -0
- data/test/specs/window/timer.js +26 -0
- data/test/specs/window/window.js +53 -0
- data/test/specs/xhr/spec.html +47 -0
- data/test/specs/xhr/xhr.js +31 -0
- data/test/test.js +10 -0
- data/test/unit/dom.js +44 -0
- data/test/unit/elementmembers.js +92 -0
- data/test/unit/events.js +195 -0
- data/test/unit/fixtures/external_script.js +1 -0
- data/test/unit/form.js +40 -0
- data/test/unit/iframe.js +234 -0
- data/test/unit/insertion.js +23 -0
- data/test/unit/multi-window.js +212 -0
- data/test/unit/nu.validator.js +34 -0
- data/test/unit/onload.js +90 -0
- data/test/unit/parser.js +122 -0
- data/test/unit/prototypecompat.js +22 -0
- data/test/unit/proxy.js +6 -0
- data/test/unit/scope.js +209 -0
- data/test/unit/timer.js +115 -0
- data/test/unit/window.js +57 -0
- data/test/x.js +1 -0
- data/test/y.js +1 -0
- metadata +367 -0
data/src/xpath/result.js
ADDED
@@ -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, '&').replace(/</g, '<').
|
365
|
+
replace(/>/g, '>');
|
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, '"');
|
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, '<').replace(/>/g, '>');
|
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
|
+
|