~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-tools/webdoc/plugins/sidebar-plugin/dependencies/xtree/xmlextras.js

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//<script>
 
2
//////////////////
 
3
// Helper Stuff //
 
4
//////////////////
 
5
 
 
6
// used to find the Automation server name
 
7
function getDomDocumentPrefix() {
 
8
        if (getDomDocumentPrefix.prefix)
 
9
                return getDomDocumentPrefix.prefix;
 
10
        
 
11
        var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
 
12
        var o;
 
13
        for (var i = 0; i < prefixes.length; i++) {
 
14
                try {
 
15
                        // try to create the objects
 
16
                        o = new ActiveXObject(prefixes[i] + ".DomDocument");
 
17
                        return getDomDocumentPrefix.prefix = prefixes[i];
 
18
                }
 
19
                catch (ex) {};
 
20
        }
 
21
        
 
22
        throw new Error("Could not find an installed XML parser");
 
23
}
 
24
 
 
25
function getXmlHttpPrefix() {
 
26
        if (getXmlHttpPrefix.prefix)
 
27
                return getXmlHttpPrefix.prefix;
 
28
        
 
29
        var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
 
30
        var o;
 
31
        for (var i = 0; i < prefixes.length; i++) {
 
32
                try {
 
33
                        // try to create the objects
 
34
                        o = new ActiveXObject(prefixes[i] + ".XmlHttp");
 
35
                        return getXmlHttpPrefix.prefix = prefixes[i];
 
36
                }
 
37
                catch (ex) {};
 
38
        }
 
39
        
 
40
        throw new Error("Could not find an installed XML parser");
 
41
}
 
42
 
 
43
//////////////////////////
 
44
// Start the Real stuff //
 
45
//////////////////////////
 
46
 
 
47
 
 
48
// XmlHttp factory
 
49
function XmlHttp() {}
 
50
 
 
51
XmlHttp.create = function () {
 
52
        try {
 
53
                if (window.XMLHttpRequest) {
 
54
                        var req = new XMLHttpRequest();
 
55
                        
 
56
                        // some versions of Moz do not support the readyState property
 
57
                        // and the onreadystate event so we patch it!
 
58
                        if (req.readyState == null) {
 
59
                                req.readyState = 1;
 
60
                                req.addEventListener("load", function () {
 
61
                                        req.readyState = 4;
 
62
                                        if (typeof req.onreadystatechange == "function")
 
63
                                                req.onreadystatechange();
 
64
                                }, false);
 
65
                        }
 
66
                        
 
67
                        return req;
 
68
                }
 
69
                if (window.ActiveXObject) {
 
70
                        return new ActiveXObject(getXmlHttpPrefix() + ".XmlHttp");
 
71
                }
 
72
        }
 
73
        catch (ex) {}
 
74
        // fell through
 
75
        throw new Error("Your browser does not support XmlHttp objects");
 
76
};
 
77
 
 
78
// XmlDocument factory
 
79
function XmlDocument() {}
 
80
 
 
81
XmlDocument.create = function () {
 
82
        try {
 
83
                // DOM2
 
84
                if (document.implementation && document.implementation.createDocument) {
 
85
                        var doc = document.implementation.createDocument("", "", null);
 
86
                        
 
87
                        // some versions of Moz do not support the readyState property
 
88
                        // and the onreadystate event so we patch it!
 
89
                        if (doc.readyState == null) {
 
90
                                doc.readyState = 1;
 
91
                                doc.addEventListener("load", function () {
 
92
                                        doc.readyState = 4;
 
93
                                        if (typeof doc.onreadystatechange == "function")
 
94
                                                doc.onreadystatechange();
 
95
                                }, false);
 
96
                        }
 
97
                        
 
98
                        return doc;
 
99
                }
 
100
                if (window.ActiveXObject)
 
101
                        return new ActiveXObject(getDomDocumentPrefix() + ".DomDocument");
 
102
        }
 
103
        catch (ex) {}
 
104
        throw new Error("Your browser does not support XmlDocument objects");
 
105
};
 
106
 
 
107
// Create the loadXML method and xml getter for Mozilla
 
108
if (window.DOMParser &&
 
109
        window.XMLSerializer &&
 
110
        window.Node && Node.prototype && Node.prototype.__defineGetter__) {
 
111
 
 
112
        // XMLDocument did not extend the Document interface in some versions
 
113
        // of Mozilla. Extend both!
 
114
        XMLDocument.prototype.loadXML = 
 
115
        Document.prototype.loadXML = function (s) {
 
116
                
 
117
                // parse the string to a new doc        
 
118
                var doc2 = (new DOMParser()).parseFromString(s, "text/xml");
 
119
                
 
120
                // remove all initial children
 
121
                while (this.hasChildNodes())
 
122
                        this.removeChild(this.lastChild);
 
123
                        
 
124
                // insert and import nodes
 
125
                for (var i = 0; i < doc2.childNodes.length; i++) {
 
126
                        this.appendChild(this.importNode(doc2.childNodes[i], true));
 
127
                }
 
128
        };
 
129
        
 
130
        
 
131
        /*
 
132
         * xml getter
 
133
         *
 
134
         * This serializes the DOM tree to an XML String
 
135
         *
 
136
         * Usage: var sXml = oNode.xml
 
137
         *
 
138
         */
 
139
        // XMLDocument did not extend the Document interface in some versions
 
140
        // of Mozilla. Extend both!
 
141
        XMLDocument.prototype.__defineGetter__("xml", function () {
 
142
                return (new XMLSerializer()).serializeToString(this);
 
143
        });
 
144
        Document.prototype.__defineGetter__("xml", function () {
 
145
                return (new XMLSerializer()).serializeToString(this);
 
146
        });
 
147
}
 
 
b'\\ No newline at end of file'