1
/*----------------------------------------------------------------------------\
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 |
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 |
45
| 2002-10-10 | (1.1) Added reload method that reloads the XML file from the |
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 |
53
|-----------------------------------------------------------------------------|
54
| Created 2001-09-27 | All changes are in the log above. | Updated 2003-05-06 |
55
\----------------------------------------------------------------------------*/
58
webFXTreeConfig.loadingText = "Loading...";
59
webFXTreeConfig.loadErrorTextTemplate = "Error loading \"%1%\"";
60
webFXTreeConfig.emptyErrorTextTemplate = "Error \"%1%\" does not contain any tree items";
66
function WebFXLoadTree(sText, sXmlSrc, sAction, sBehavior, sIcon, sOpenIcon) {
68
this.WebFXTree = WebFXTree;
69
this.WebFXTree(sText, sAction, sBehavior, sIcon, sOpenIcon);
71
// setup default property values
77
// check start state and load if open
79
_startLoadXmlTree(this.src, this);
81
// and create loading item if not
82
this._loadingItem = new WebFXTreeItem(webFXTreeConfig.loadingText);
83
this.add(this._loadingItem);
87
WebFXLoadTree.prototype = new WebFXTree;
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) {
94
_startLoadXmlTree(this.src, this);
96
this._webfxtree_expand();
100
* WebFXLoadTreeItem class
103
function WebFXLoadTreeItem(sText, sXmlSrc, sAction, eParent, sIcon, sOpenIcon) {
105
this.WebFXTreeItem = WebFXTreeItem;
106
this.WebFXTreeItem(sText, sAction, eParent, sIcon, sOpenIcon);
108
// setup default property values
110
this.loading = false;
114
// check start state and load if open
116
_startLoadXmlTree(this.src, this);
118
// and create loading item if not
119
this._loadingItem = new WebFXTreeItem(webFXTreeConfig.loadingText);
120
this.add(this._loadingItem);
124
WebFXLoadTreeItem.prototype = new WebFXTreeItem;
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) {
131
_startLoadXmlTree(this.src, this);
133
this._webfxtreeitem_expand();
136
// reloads the src file if already loaded
137
WebFXLoadTree.prototype.reload =
138
WebFXLoadTreeItem.prototype.reload = function () {
139
// if loading do nothing
141
var open = this.open;
143
while (this.childNodes.length > 0)
144
this.childNodes[this.childNodes.length - 1].remove();
148
this._loadingItem = new WebFXTreeItem(webFXTreeConfig.loadingText);
149
this.add(this._loadingItem);
154
else if (this.open && !this.loading)
155
_startLoadXmlTree(this.src, this);
162
// creates the xmlhttp object and starts the load of the xml document
163
function _startLoadXmlTree(sSrc, jsNode) {
164
if (jsNode.loading || jsNode.loaded)
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);
174
// call in new thread to allow ui to update
175
window.setTimeout(function () {
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");
187
var icon = oNode.getAttribute("icon");
188
var openIcon = oNode.getAttribute("openIcon");
189
var src = oNode.getAttribute("src");
190
var target = oNode.getAttribute("target");
193
if (src != null && src != "")
194
jsNode = new WebFXLoadTreeItem(text, src, action, parent, icon, openIcon);
196
jsNode = new WebFXTreeItem(text, action, parent, icon, openIcon);
199
jsNode.target = target;
201
// go through childNOdes
202
var cs = oNode.childNodes;
204
for (var i = 0; i < l; i++) {
205
if (cs[i].tagName == "tree")
206
jsNode.add( _xmlTreeToJsTree(cs[i]), true );
212
// Inserts an xml document as a subtree to the provided node
213
function _xmlFileLoaded(oXmlDoc, jsParentNode) {
214
if (jsParentNode.loaded)
218
var bAnyChildren = false;
219
jsParentNode.loaded = true;
220
jsParentNode.loading = false;
222
// check that the load of the xml file went well
223
if( oXmlDoc == null || oXmlDoc.documentElement == null) {
225
jsParentNode.errorText = parseTemplateString(webFXTreeConfig.loadErrorTextTemplate,
229
// there is one extra level of tree elements
230
var root = oXmlDoc.documentElement;
232
// loop through all tree children
233
var cs = root.childNodes;
235
for (var i = 0; i < l; i++) {
236
if (cs[i].tagName == "tree") {
239
jsParentNode.add( _xmlTreeToJsTree(cs[i]), true);
243
// if no children we got an error
245
jsParentNode.errorText = parseTemplateString(webFXTreeConfig.emptyErrorTextTemplate,
250
if (jsParentNode._loadingItem != null) {
251
jsParentNode._loadingItem.remove();
256
// indent now that all items are added
257
jsParentNode.indent();
260
// show error in status bar
261
if (jsParentNode.errorText != "")
262
window.status = jsParentNode.errorText;
265
// parses a string and replaces %n% with argument nr n
266
function parseTemplateString(sTemplate) {
267
var args = arguments;
270
s = s.replace(/\%\%/g, "%");
272
for (var i = 1; i < args.length; i++)
273
s = s.replace( new RegExp("\%" + i + "\%", "g"), args[i] )
b'\\ No newline at end of file'