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

« back to all changes in this revision

Viewing changes to external/mono-tools/webdoc/xtree/xloadtree.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
 
/*----------------------------------------------------------------------------\
2
 
|                               XLoadTree 1.11                                |
3
 
|-----------------------------------------------------------------------------|
4
 
|                         Created by Erik Arvidsson                           |
5
 
|                  (http://webfx.eae.net/contact.html#erik)                   |
6
 
|                      For WebFX (http://webfx.eae.net/)                      |
7
 
|-----------------------------------------------------------------------------|
8
 
| An extension to xTree that allows sub trees to be loaded at runtime by      |
9
 
| reading XML files from the server. Works with IE5+ and Mozilla 1.0+         |
10
 
|-----------------------------------------------------------------------------|
11
 
|                   Copyright (c) 1999 - 2002 Erik Arvidsson                  |
12
 
|-----------------------------------------------------------------------------|
13
 
| This software is provided "as is", without warranty of any kind, express or |
14
 
| implied, including  but not limited  to the warranties of  merchantability, |
15
 
| fitness for a particular purpose and noninfringement. In no event shall the |
16
 
| authors or  copyright  holders be  liable for any claim,  damages or  other |
17
 
| liability, whether  in an  action of  contract, tort  or otherwise, arising |
18
 
| from,  out of  or in  connection with  the software or  the  use  or  other |
19
 
| dealings in the software.                                                   |
20
 
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
21
 
| This  software is  available under the  three different licenses  mentioned |
22
 
| below.  To use this software you must chose, and qualify, for one of those. |
23
 
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
24
 
| The WebFX Non-Commercial License          http://webfx.eae.net/license.html |
25
 
| Permits  anyone the right to use the  software in a  non-commercial context |
26
 
| free of charge.                                                             |
27
 
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
28
 
| The WebFX Commercial license           http://webfx.eae.net/commercial.html |
29
 
| Permits the  license holder the right to use  the software in a  commercial |
30
 
| context. Such license must be specifically obtained, however it's valid for |
31
 
| any number of  implementations of the licensed software.                    |
32
 
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
33
 
| GPL - The GNU General Public License    http://www.gnu.org/licenses/gpl.txt |
34
 
| Permits anyone the right to use and modify the software without limitations |
35
 
| as long as proper  credits are given  and the original  and modified source |
36
 
| code are included. Requires  that the final product, software derivate from |
37
 
| the original  source or any  software  utilizing a GPL  component, such  as |
38
 
| this, is also licensed under the GPL license.                               |
39
 
|-----------------------------------------------------------------------------|
40
 
| 2001-09-27 | Original Version Posted.                                       |
41
 
| 2002-01-19 | Added some simple error handling and string templates for      |
42
 
|            | reporting the errors.                                          |
43
 
| 2002-01-28 | Fixed loading issues in IE50 and IE55 that made the tree load  |
44
 
|            | twice.                                                         |
45
 
| 2002-10-10 | (1.1) Added reload method that reloads the XML file from the   |
46
 
|            | server.                                                        |
47
 
/ 2003-05-06 | Added support for target attribute                             |
48
 
|-----------------------------------------------------------------------------|
49
 
| Dependencies: xtree.js - original xtree library                             |
50
 
|               xtree.css - simple css styling of xtree                       |
51
 
|               xmlextras.js - provides xml http objects and xml document     |
52
 
|                              objects                                        |
53
 
|-----------------------------------------------------------------------------|
54
 
| Created 2001-09-27 | All changes are in the log above. | Updated 2003-05-06 |
55
 
\----------------------------------------------------------------------------*/
56
 
 
57
 
 
58
 
webFXTreeConfig.loadingText = "Loading...";
59
 
webFXTreeConfig.loadErrorTextTemplate = "Error loading \"%1%\"";
60
 
webFXTreeConfig.emptyErrorTextTemplate = "Error \"%1%\" does not contain any tree items";
61
 
 
62
 
/*
63
 
 * WebFXLoadTree class
64
 
 */
65
 
 
66
 
function WebFXLoadTree(sText, sXmlSrc, sAction, sBehavior, sIcon, sOpenIcon) {
67
 
        // call super
68
 
        this.WebFXTree = WebFXTree;
69
 
        this.WebFXTree(sText, sAction, sBehavior, sIcon, sOpenIcon);
70
 
 
71
 
        // setup default property values
72
 
        this.src = sXmlSrc;
73
 
        this.loading = false;
74
 
        this.loaded = false;
75
 
        this.errorText = "";
76
 
 
77
 
        // check start state and load if open
78
 
        if (this.open)
79
 
                _startLoadXmlTree(this.src, this);
80
 
        else {
81
 
                // and create loading item if not
82
 
                this._loadingItem = new WebFXTreeItem(webFXTreeConfig.loadingText);
83
 
                this.add(this._loadingItem);
84
 
        }
85
 
}
86
 
 
87
 
WebFXLoadTree.prototype = new WebFXTree;
88
 
 
89
 
// override the expand method to load the xml file
90
 
WebFXLoadTree.prototype._webfxtree_expand = WebFXTree.prototype.expand;
91
 
WebFXLoadTree.prototype.expand = function() {
92
 
        if (!this.loaded && !this.loading) {
93
 
                // load
94
 
                _startLoadXmlTree(this.src, this);
95
 
        }
96
 
        this._webfxtree_expand();
97
 
};
98
 
 
99
 
/*
100
 
 * WebFXLoadTreeItem class
101
 
 */
102
 
 
103
 
function WebFXLoadTreeItem(sText, sXmlSrc, sAction, eParent, sIcon, sOpenIcon) {
104
 
        // call super
105
 
        this.WebFXTreeItem = WebFXTreeItem;
106
 
        this.WebFXTreeItem(sText, sAction, eParent, sIcon, sOpenIcon);
107
 
 
108
 
        // setup default property values
109
 
        this.src = sXmlSrc;
110
 
        this.loading = false;
111
 
        this.loaded = false;
112
 
        this.errorText = "";
113
 
 
114
 
        // check start state and load if open
115
 
        if (this.open)
116
 
                _startLoadXmlTree(this.src, this);
117
 
        else {
118
 
                // and create loading item if not
119
 
                this._loadingItem = new WebFXTreeItem(webFXTreeConfig.loadingText);
120
 
                this.add(this._loadingItem);
121
 
        }
122
 
}
123
 
 
124
 
WebFXLoadTreeItem.prototype = new WebFXTreeItem;
125
 
 
126
 
// override the expand method to load the xml file
127
 
WebFXLoadTreeItem.prototype._webfxtreeitem_expand = WebFXTreeItem.prototype.expand;
128
 
WebFXLoadTreeItem.prototype.expand = function() {
129
 
        if (!this.loaded && !this.loading) {
130
 
                // load
131
 
                _startLoadXmlTree(this.src, this);
132
 
        }
133
 
        this._webfxtreeitem_expand();
134
 
};
135
 
 
136
 
// reloads the src file if already loaded
137
 
WebFXLoadTree.prototype.reload =
138
 
WebFXLoadTreeItem.prototype.reload = function () {
139
 
        // if loading do nothing
140
 
        if (this.loaded) {
141
 
                var open = this.open;
142
 
                // remove
143
 
                while (this.childNodes.length > 0)
144
 
                        this.childNodes[this.childNodes.length - 1].remove();
145
 
 
146
 
                this.loaded = false;
147
 
 
148
 
                this._loadingItem = new WebFXTreeItem(webFXTreeConfig.loadingText);
149
 
                this.add(this._loadingItem);
150
 
 
151
 
                if (open)
152
 
                        this.expand();
153
 
        }
154
 
        else if (this.open && !this.loading)
155
 
                _startLoadXmlTree(this.src, this);
156
 
};
157
 
 
158
 
/*
159
 
 * Helper functions
160
 
 */
161
 
 
162
 
// creates the xmlhttp object and starts the load of the xml document
163
 
function _startLoadXmlTree(sSrc, jsNode) {
164
 
        if (jsNode.loading || jsNode.loaded)
165
 
                return;
166
 
        jsNode.loading = true;
167
 
        var xmlHttp = XmlHttp.create();
168
 
        xmlHttp.open("GET", sSrc, true);        // async
169
 
        xmlHttp.onreadystatechange = function () {
170
 
                if (xmlHttp.readyState == 4) {
171
 
                        _xmlFileLoaded(xmlHttp.responseXML, jsNode);
172
 
                }
173
 
        };
174
 
        // call in new thread to allow ui to update
175
 
        window.setTimeout(function () {
176
 
                xmlHttp.send(null);
177
 
        }, 10);
178
 
}
179
 
 
180
 
 
181
 
// Converts an xml tree to a js tree. See article about xml tree format
182
 
function _xmlTreeToJsTree(oNode) {
183
 
        // retreive attributes
184
 
        var text = oNode.getAttribute("text");
185
 
        var action = oNode.getAttribute("action");
186
 
        var parent = null;
187
 
        var icon = oNode.getAttribute("icon");
188
 
        var openIcon = oNode.getAttribute("openIcon");
189
 
        var src = oNode.getAttribute("src");
190
 
        var target = oNode.getAttribute("target");
191
 
        // create jsNode
192
 
        var jsNode;
193
 
        if (src != null && src != "")
194
 
                jsNode = new WebFXLoadTreeItem(text, src, action, parent, icon, openIcon);
195
 
        else
196
 
                jsNode = new WebFXTreeItem(text, action, parent, icon, openIcon);
197
 
 
198
 
        if (target != "")
199
 
                jsNode.target = target;
200
 
 
201
 
        // go through childNOdes
202
 
        var cs = oNode.childNodes;
203
 
        var l = cs.length;
204
 
        for (var i = 0; i < l; i++) {
205
 
                if (cs[i].tagName == "tree")
206
 
                        jsNode.add( _xmlTreeToJsTree(cs[i]), true );
207
 
        }
208
 
 
209
 
        return jsNode;
210
 
}
211
 
 
212
 
// Inserts an xml document as a subtree to the provided node
213
 
function _xmlFileLoaded(oXmlDoc, jsParentNode) {
214
 
        if (jsParentNode.loaded)
215
 
                return;
216
 
 
217
 
        var bIndent = false;
218
 
        var bAnyChildren = false;
219
 
        jsParentNode.loaded = true;
220
 
        jsParentNode.loading = false;
221
 
 
222
 
        // check that the load of the xml file went well
223
 
        if( oXmlDoc == null || oXmlDoc.documentElement == null) {
224
 
                alert(oXmlDoc.xml);
225
 
                jsParentNode.errorText = parseTemplateString(webFXTreeConfig.loadErrorTextTemplate,
226
 
                                                        jsParentNode.src);
227
 
        }
228
 
        else {
229
 
                // there is one extra level of tree elements
230
 
                var root = oXmlDoc.documentElement;
231
 
 
232
 
                // loop through all tree children
233
 
                var cs = root.childNodes;
234
 
                var l = cs.length;
235
 
                for (var i = 0; i < l; i++) {
236
 
                        if (cs[i].tagName == "tree") {
237
 
                                bAnyChildren = true;
238
 
                                bIndent = true;
239
 
                                jsParentNode.add( _xmlTreeToJsTree(cs[i]), true);
240
 
                        }
241
 
                }
242
 
 
243
 
                // if no children we got an error
244
 
                if (!bAnyChildren)
245
 
                        jsParentNode.errorText = parseTemplateString(webFXTreeConfig.emptyErrorTextTemplate,
246
 
                                                                                jsParentNode.src);
247
 
        }
248
 
 
249
 
        // remove dummy
250
 
        if (jsParentNode._loadingItem != null) {
251
 
                jsParentNode._loadingItem.remove();
252
 
                bIndent = true;
253
 
        }
254
 
 
255
 
        if (bIndent) {
256
 
                // indent now that all items are added
257
 
                jsParentNode.indent();
258
 
        }
259
 
 
260
 
        // show error in status bar
261
 
        if (jsParentNode.errorText != "")
262
 
                window.status = jsParentNode.errorText;
263
 
}
264
 
 
265
 
// parses a string and replaces %n% with argument nr n
266
 
function parseTemplateString(sTemplate) {
267
 
        var args = arguments;
268
 
        var s = sTemplate;
269
 
 
270
 
        s = s.replace(/\%\%/g, "%");
271
 
 
272
 
        for (var i = 1; i < args.length; i++)
273
 
                s = s.replace( new RegExp("\%" + i + "\%", "g"), args[i] )
274
 
 
275
 
        return s;
276
 
}
 
 
b'\\ No newline at end of file'