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/html/frame.js
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
$debug("Defining HTMLFrameElement");
|
2
|
+
/*
|
3
|
+
* HTMLFrameElement - DOM Level 2
|
4
|
+
*/
|
5
|
+
var HTMLFrameElement = function(ownerDocument) {
|
6
|
+
this.HTMLElement = HTMLElement;
|
7
|
+
this.HTMLElement(ownerDocument);
|
8
|
+
};
|
9
|
+
HTMLFrameElement.prototype = new HTMLElement;
|
10
|
+
__extend__(HTMLFrameElement.prototype, {
|
11
|
+
get frameBorder(){
|
12
|
+
return this.getAttribute('border')||"";
|
13
|
+
},
|
14
|
+
set frameBorder(value){
|
15
|
+
this.setAttribute('border', value);
|
16
|
+
},
|
17
|
+
get longDesc(){
|
18
|
+
return this.getAttribute('longdesc')||"";
|
19
|
+
},
|
20
|
+
set longDesc(value){
|
21
|
+
this.setAttribute('longdesc', value);
|
22
|
+
},
|
23
|
+
get marginHeight(){
|
24
|
+
return this.getAttribute('marginheight')||"";
|
25
|
+
},
|
26
|
+
set marginHeight(value){
|
27
|
+
this.setAttribute('marginheight', value);
|
28
|
+
},
|
29
|
+
get marginWidth(){
|
30
|
+
return this.getAttribute('marginwidth')||"";
|
31
|
+
},
|
32
|
+
set marginWidth(value){
|
33
|
+
this.setAttribute('marginwidth', value);
|
34
|
+
},
|
35
|
+
get name(){
|
36
|
+
return this.getAttribute('name')||"";
|
37
|
+
},
|
38
|
+
set name(value){
|
39
|
+
this.setAttribute('name', value);
|
40
|
+
},
|
41
|
+
get noResize(){
|
42
|
+
return this.getAttribute('noresize')||"";
|
43
|
+
},
|
44
|
+
set noResize(value){
|
45
|
+
this.setAttribute('noresize', value);
|
46
|
+
},
|
47
|
+
get scrolling(){
|
48
|
+
return this.getAttribute('scrolling')||"";
|
49
|
+
},
|
50
|
+
set scrolling(value){
|
51
|
+
this.setAttribute('scrolling', value);
|
52
|
+
},
|
53
|
+
get src(){
|
54
|
+
return this.getAttribute('src')||"";
|
55
|
+
},
|
56
|
+
set src(value){
|
57
|
+
this.setAttribute('src', value);
|
58
|
+
|
59
|
+
if (value && value.length > 0){
|
60
|
+
var save = $master.first_script_window;
|
61
|
+
try {
|
62
|
+
var $env = this.ownerDocument._parentWindow.$envx;
|
63
|
+
var $inner = this.ownerDocument._parentWindow["$inner"];
|
64
|
+
$master.first_script_window = $inner;
|
65
|
+
$env.loadFrame(this, $env.location(value));
|
66
|
+
} finally {
|
67
|
+
$master.first_script_window = save;
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
var event = this.ownerDocument.createEvent();
|
72
|
+
event.initEvent("load");
|
73
|
+
this.dispatchEvent( event, false );
|
74
|
+
}
|
75
|
+
},
|
76
|
+
get contentDocument(){
|
77
|
+
if (!this._content)
|
78
|
+
return null;
|
79
|
+
return this._content.document;
|
80
|
+
},
|
81
|
+
get contentWindow(){
|
82
|
+
return this._content;
|
83
|
+
},
|
84
|
+
onload: function(event){
|
85
|
+
return __eval__(this.getAttribute('onload')||'', this)
|
86
|
+
}
|
87
|
+
});
|
88
|
+
|
89
|
+
// $w.HTMLFrameElement = HTMLFrameElement;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
$debug("Defining HTMLFrameSetElement");
|
2
|
+
/*
|
3
|
+
* HTMLFrameSetElement - DOM Level 2
|
4
|
+
*/
|
5
|
+
var HTMLFrameSetElement = function(ownerDocument) {
|
6
|
+
this.HTMLElement = HTMLElement;
|
7
|
+
this.HTMLElement(ownerDocument);
|
8
|
+
};
|
9
|
+
HTMLFrameSetElement.prototype = new HTMLElement;
|
10
|
+
__extend__(HTMLFrameSetElement.prototype, {
|
11
|
+
get cols(){
|
12
|
+
return this.getAttribute('cols');
|
13
|
+
},
|
14
|
+
set cols(value){
|
15
|
+
this.setAttribute('cols', value);
|
16
|
+
},
|
17
|
+
get rows(){
|
18
|
+
return this.getAttribute('rows');
|
19
|
+
},
|
20
|
+
set rows(value){
|
21
|
+
this.setAttribute('rows', value);
|
22
|
+
}
|
23
|
+
});
|
24
|
+
|
25
|
+
// $w.HTMLFrameSetElement = HTMLFrameSetElement;
|
data/src/html/head.js
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
$debug("Defining HTMLHeadElement");
|
2
|
+
/*
|
3
|
+
* HTMLHeadElement - DOM Level 2
|
4
|
+
*/
|
5
|
+
var HTMLHeadElement = function(ownerDocument) {
|
6
|
+
this.HTMLElement = HTMLElement;
|
7
|
+
this.HTMLElement(ownerDocument);
|
8
|
+
};
|
9
|
+
HTMLHeadElement.prototype = new HTMLElement;
|
10
|
+
__extend__(HTMLHeadElement.prototype, {
|
11
|
+
get profile(){
|
12
|
+
return this.getAttribute('profile');
|
13
|
+
},
|
14
|
+
set profile(value){
|
15
|
+
this.setAttribute('profile', value);
|
16
|
+
},
|
17
|
+
//we override this so we can apply browser behavior specific to head children
|
18
|
+
//like loading scripts
|
19
|
+
appendChild : function(newChild) {
|
20
|
+
var newChild = HTMLElement.prototype.appendChild.apply(this,[newChild]);
|
21
|
+
//__evalScript__(newChild);
|
22
|
+
return newChild;
|
23
|
+
},
|
24
|
+
insertBefore : function(newChild, refChild) {
|
25
|
+
var newChild = HTMLElement.prototype.insertBefore.apply(this,[newChild]);
|
26
|
+
//__evalScript__(newChild);
|
27
|
+
return newChild;
|
28
|
+
}
|
29
|
+
});
|
30
|
+
|
31
|
+
var __evalScript__ = function(newChild){
|
32
|
+
//check to see if this is a script element and apply a script loading strategy
|
33
|
+
//the check against the ownerDocument isnt really enough to support frames in
|
34
|
+
// the long run, but for now it's ok
|
35
|
+
if(newChild.nodeType == DOMNode.ELEMENT_NODE &&
|
36
|
+
newChild.ownerDocument == window.document ){
|
37
|
+
if(newChild.nodeName.toUpperCase() == "SCRIPT"){
|
38
|
+
$debug("loading script via policy. ");
|
39
|
+
$policy.loadScript(newChild);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
};
|
43
|
+
|
44
|
+
// $w.HTMLHeadElement = HTMLHeadElement;
|
data/src/html/html.js
ADDED
File without changes
|
@@ -0,0 +1,340 @@
|
|
1
|
+
/*
|
2
|
+
* parser.js
|
3
|
+
*/
|
4
|
+
/*
|
5
|
+
* HTML Parser By John Resig (ejohn.org)
|
6
|
+
* Original code by Erik Arvidsson, Mozilla Public License
|
7
|
+
* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
|
8
|
+
*
|
9
|
+
* // Use like so:
|
10
|
+
* HTMLParser(htmlString, {
|
11
|
+
* start: function(tag, attrs, unary) {},
|
12
|
+
* end: function(tag) {},
|
13
|
+
* chars: function(text) {},
|
14
|
+
* comment: function(text) {}
|
15
|
+
* });
|
16
|
+
*
|
17
|
+
* // or to get an XML string:
|
18
|
+
* HTMLtoXML(htmlString);
|
19
|
+
*
|
20
|
+
* // or to get an XML DOM Document
|
21
|
+
* HTMLtoDOM(htmlString);
|
22
|
+
*
|
23
|
+
* // or to inject into an existing document/DOM node
|
24
|
+
* HTMLtoDOM(htmlString, document);
|
25
|
+
* HTMLtoDOM(htmlString, document.body);
|
26
|
+
*
|
27
|
+
*/
|
28
|
+
var html2dom, html2xml;
|
29
|
+
|
30
|
+
(function(){
|
31
|
+
|
32
|
+
// Regular Expressions for parsing tags and attributes
|
33
|
+
var startTag = /^<([\w\:\-]+)((?:\s+[\w\:\-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,
|
34
|
+
endTag = /^<\/([\w\:\-]+)[^>]*>/,
|
35
|
+
attr = /([\w\:\-]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;
|
36
|
+
// Empty Elements - HTML 4.01
|
37
|
+
var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed");
|
38
|
+
|
39
|
+
// Block Elements - HTML 4.01
|
40
|
+
var block = makeMap("address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul");
|
41
|
+
|
42
|
+
// Inline Elements - HTML 4.01
|
43
|
+
var inline = makeMap("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var");
|
44
|
+
|
45
|
+
// Elements that you can, intentionally, leave open
|
46
|
+
// (and which close themselves)
|
47
|
+
var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");
|
48
|
+
|
49
|
+
// Attributes that have their values filled in disabled="disabled"
|
50
|
+
var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");
|
51
|
+
|
52
|
+
// Special Elements (can contain anything)
|
53
|
+
var special = makeMap("script,style");
|
54
|
+
|
55
|
+
var HTMLParser = function( html, handler ) {
|
56
|
+
var index, chars, match, stack = [], last = html;
|
57
|
+
stack.last = function(){
|
58
|
+
return this[ this.length - 1 ];
|
59
|
+
};
|
60
|
+
|
61
|
+
while ( html ) {
|
62
|
+
//$log("HTMLParser: chunking... ");
|
63
|
+
chars = true;
|
64
|
+
|
65
|
+
// Make sure we're not in a script or style element
|
66
|
+
if ( !stack.last() || !special[ stack.last() ] ) {
|
67
|
+
|
68
|
+
//$log("HTMLParser: ... ");
|
69
|
+
// Comment
|
70
|
+
if ( html.indexOf("<!--") === 0 ) {
|
71
|
+
//$log("HTMLParser: comment ");
|
72
|
+
index = html.indexOf("-->");
|
73
|
+
|
74
|
+
if ( index >= 0 ) {
|
75
|
+
if ( handler.comment )
|
76
|
+
handler.comment( html.substring( 4, index ) );
|
77
|
+
html = html.substring( index + 3 );
|
78
|
+
chars = false;
|
79
|
+
}
|
80
|
+
|
81
|
+
// end tag
|
82
|
+
} else if ( html.indexOf("</") === 0 ) {
|
83
|
+
//$log("HTMLParser: endtag ");
|
84
|
+
match = html.match( endTag );
|
85
|
+
|
86
|
+
if ( match ) {
|
87
|
+
//$log("HTMLParser: endtag match : "+match[0]);
|
88
|
+
html = html.substring( match[0].length );
|
89
|
+
match[0].replace( endTag, parseEndTag );
|
90
|
+
chars = false;
|
91
|
+
}
|
92
|
+
|
93
|
+
// start tag
|
94
|
+
} else if ( html.indexOf("<") === 0 ) {
|
95
|
+
//$log("HTMLParser: starttag ");
|
96
|
+
match = html.match( startTag );
|
97
|
+
|
98
|
+
if ( match ) {
|
99
|
+
//$log("HTMLParser: starttag match : "+match[0]);
|
100
|
+
html = html.substring( match[0].length );
|
101
|
+
match[0].replace( startTag, parseStartTag );
|
102
|
+
chars = false;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
if ( chars ) {
|
107
|
+
//$log("HTMLParser: other ");
|
108
|
+
index = html.indexOf("<");
|
109
|
+
var text = index < 0 ? html : html.substring( 0, index );
|
110
|
+
html = index < 0 ? "" : html.substring( index );
|
111
|
+
if ( handler.chars ){
|
112
|
+
//$log("HTMLParser: chars " + text);
|
113
|
+
handler.chars( text );
|
114
|
+
}
|
115
|
+
}
|
116
|
+
} else {
|
117
|
+
//$log("HTMLParser: special ");
|
118
|
+
html = html.replace(new RegExp("(.*)<\/" + stack.last() + "[^>]*>"), function(all, text){
|
119
|
+
text = text.replace(/<!--(.*?)-->/g, "$1").
|
120
|
+
replace(/<!\[CDATA\[(.*?)]]>/g, "$1");
|
121
|
+
if ( handler.chars ){
|
122
|
+
//$log("HTMLParser: special chars " + text);
|
123
|
+
handler.chars( text );
|
124
|
+
}
|
125
|
+
return "";
|
126
|
+
});
|
127
|
+
parseEndTag( "", stack.last() );
|
128
|
+
}
|
129
|
+
if ( html == last ){throw "Parse Error: " + html;}
|
130
|
+
last = html;
|
131
|
+
}
|
132
|
+
|
133
|
+
// Clean up any remaining tags
|
134
|
+
parseEndTag();
|
135
|
+
|
136
|
+
function parseStartTag( tag, tagName, rest, unary ) {
|
137
|
+
if ( block[ tagName ] ) {
|
138
|
+
while ( stack.last() && inline[ stack.last() ] ) {
|
139
|
+
parseEndTag( "", stack.last() );
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
if ( closeSelf[ tagName ] && stack.last() == tagName ) {
|
144
|
+
parseEndTag( "", tagName );
|
145
|
+
}
|
146
|
+
|
147
|
+
unary = empty[ tagName ] || !!unary;
|
148
|
+
|
149
|
+
if ( !unary )
|
150
|
+
stack.push( tagName );
|
151
|
+
|
152
|
+
if ( handler.start ) {
|
153
|
+
var attrs = [];
|
154
|
+
|
155
|
+
rest.replace(attr, function(match, name) {
|
156
|
+
var value = arguments[2] ? arguments[2] :
|
157
|
+
arguments[3] ? arguments[3] :
|
158
|
+
arguments[4] ? arguments[4] :
|
159
|
+
fillAttrs[name] ? name : "";
|
160
|
+
|
161
|
+
attrs.push({
|
162
|
+
name: name,
|
163
|
+
value: value,
|
164
|
+
escaped: value.replace(/(^|[^\\])"/g, '$1\\\"') //"
|
165
|
+
});
|
166
|
+
});
|
167
|
+
|
168
|
+
if ( handler.start ){
|
169
|
+
//$log("unary ? : "+unary);
|
170
|
+
handler.start( tagName, attrs, unary );
|
171
|
+
}
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
function parseEndTag( tag, tagName ) {
|
176
|
+
var pos;
|
177
|
+
// If no tag name is provided, clean shop
|
178
|
+
if ( !tagName ){
|
179
|
+
pos = 0;
|
180
|
+
}else{
|
181
|
+
// Find the closest opened tag of the same type
|
182
|
+
for ( pos = stack.length - 1; pos >= 0; pos-- ){
|
183
|
+
//$log("parseEndTag : "+stack[ pos ] );
|
184
|
+
if ( stack[ pos ] == tagName ){
|
185
|
+
break;
|
186
|
+
}
|
187
|
+
}
|
188
|
+
}
|
189
|
+
if ( pos >= 0 ) {
|
190
|
+
// Close all the open elements, up the stack
|
191
|
+
for ( var i = stack.length - 1; i >= pos; i-- ){
|
192
|
+
if ( handler.end ){
|
193
|
+
//$log("end : "+stack[ i ] );
|
194
|
+
handler.end( stack[ i ] );
|
195
|
+
}
|
196
|
+
}
|
197
|
+
// Remove the open elements from the stack
|
198
|
+
//$log("setting stack length : " + stack.length + " -> " +pos );
|
199
|
+
stack.length = pos;
|
200
|
+
}
|
201
|
+
}
|
202
|
+
};
|
203
|
+
|
204
|
+
html2xml = function( html ) {
|
205
|
+
var results = "";
|
206
|
+
|
207
|
+
HTMLParser(html, {
|
208
|
+
start: function( tag, attrs, unary ) {
|
209
|
+
results += "<" + tag;
|
210
|
+
|
211
|
+
for ( var i = 0; i < attrs.length; i++ )
|
212
|
+
results += " " + attrs[i].name + '="' + attrs[i].escaped + '"';
|
213
|
+
|
214
|
+
results += (unary ? "/" : "") + ">";
|
215
|
+
},
|
216
|
+
end: function( tag ) {
|
217
|
+
results += "</" + tag + ">";
|
218
|
+
},
|
219
|
+
chars: function( text ) {
|
220
|
+
results += text;
|
221
|
+
},
|
222
|
+
comment: function( text ) {
|
223
|
+
results += "<!--" + text + "-->";
|
224
|
+
}
|
225
|
+
});
|
226
|
+
|
227
|
+
return results;
|
228
|
+
};
|
229
|
+
|
230
|
+
html2dom = function( html, doc ) {
|
231
|
+
// There can be only one of these elements
|
232
|
+
var one = makeMap("html,head,body,title");
|
233
|
+
|
234
|
+
// Enforce a structure for the document
|
235
|
+
/*var structure = {
|
236
|
+
link: "head",
|
237
|
+
base: "head"
|
238
|
+
};*/
|
239
|
+
|
240
|
+
if ( !doc ) {
|
241
|
+
if ( typeof DOMDocument != "undefined" ){
|
242
|
+
doc = new DOMDocument();
|
243
|
+
}else if ( typeof document != "undefined" && document.implementation && document.implementation.createDocument ){
|
244
|
+
doc = document.implementation.createDocument("", "", null);
|
245
|
+
}else if ( typeof ActiveX != "undefined" ){
|
246
|
+
doc = new ActiveXObject("Msxml.DOMDocument");
|
247
|
+
}
|
248
|
+
} else {
|
249
|
+
doc = doc.ownerDocument ||
|
250
|
+
doc.getOwnerDocument && doc.getOwnerDocument() ||
|
251
|
+
doc;
|
252
|
+
}
|
253
|
+
|
254
|
+
var elems = [],
|
255
|
+
documentElement = doc.documentElement ||
|
256
|
+
doc.getDocumentElement && doc.getDocumentElement();
|
257
|
+
|
258
|
+
// If we're dealing with an empty document then we
|
259
|
+
// need to pre-populate it with the HTML document structure
|
260
|
+
/*if ( !documentElement && doc.createElement ) (function(){
|
261
|
+
//$log("HTMLtoDOM: adding structure... ");
|
262
|
+
var html = doc.createElement("html");
|
263
|
+
var head = doc.createElement("head");
|
264
|
+
head.appendChild( doc.createElement("title") );
|
265
|
+
html.appendChild( head );
|
266
|
+
html.appendChild( doc.createElement("body") );
|
267
|
+
doc.appendChild( html );
|
268
|
+
doc.documentElement = html;
|
269
|
+
})();*/
|
270
|
+
|
271
|
+
// Find all the unique elements
|
272
|
+
/*if ( doc.getElementsByTagName ){
|
273
|
+
for ( var i in one ){
|
274
|
+
one[ i ] = doc.getElementsByTagName( i )[0];
|
275
|
+
}
|
276
|
+
}*/
|
277
|
+
|
278
|
+
// If we're working with a document, inject contents into
|
279
|
+
// the body element
|
280
|
+
var curParentNode;// = one.body;
|
281
|
+
|
282
|
+
//$log("HTMLtoDOM: Parsing... ");
|
283
|
+
HTMLParser( html, {
|
284
|
+
start: function( tagName, attrs, unary ) {
|
285
|
+
|
286
|
+
var elem;
|
287
|
+
//$log("HTMLtoDOM: createElement... " + tagName);
|
288
|
+
elem = doc.createElement( tagName );
|
289
|
+
|
290
|
+
|
291
|
+
for ( var attr in attrs ){
|
292
|
+
//$log("HTMLtoDOM: setAttribute... " + attrs[ attr ].name);
|
293
|
+
elem.setAttribute( attrs[ attr ].name, attrs[ attr ].value );
|
294
|
+
}
|
295
|
+
|
296
|
+
if ( !doc.documentElement ){
|
297
|
+
//$log("HTMLtoDOM: documentElement... " + elem.nodeName);
|
298
|
+
doc.documentElement = elem;
|
299
|
+
doc.appendChild( elem );
|
300
|
+
}
|
301
|
+
|
302
|
+
else if ( curParentNode && curParentNode.appendChild ){
|
303
|
+
//$log("HTMLtoDOM: curParentNode.appendChild... " + curParentNode.nodeName + " -> " +elem.nodeName);
|
304
|
+
curParentNode.appendChild( elem );
|
305
|
+
}
|
306
|
+
|
307
|
+
if ( !unary ) {
|
308
|
+
//$log("start : push into elems[] " + tagName);
|
309
|
+
elems.push( elem );
|
310
|
+
curParentNode = elem;
|
311
|
+
}
|
312
|
+
},
|
313
|
+
end: function( tag ) {
|
314
|
+
//$log(tag + " : elems.lengths : "+elems.length);
|
315
|
+
elems.length -= 1;
|
316
|
+
|
317
|
+
// Init the new parentNode
|
318
|
+
curParentNode = elems[ elems.length - 1 ];
|
319
|
+
|
320
|
+
},
|
321
|
+
chars: function( text ) {
|
322
|
+
curParentNode.appendChild( doc.createTextNode( text ) );
|
323
|
+
},
|
324
|
+
comment: function( text ) {
|
325
|
+
curParentNode.appendChild( doc.createComment( text ) );
|
326
|
+
}
|
327
|
+
});
|
328
|
+
|
329
|
+
//$log("HTMLtoDOM: doc... " + doc);
|
330
|
+
return doc;
|
331
|
+
};
|
332
|
+
|
333
|
+
function makeMap(str){
|
334
|
+
var obj = {}, items = str.split(",");
|
335
|
+
for ( var i = 0; i < items.length; i++ )
|
336
|
+
obj[ items[i] ] = true;
|
337
|
+
return obj;
|
338
|
+
};
|
339
|
+
|
340
|
+
})( );
|