Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1318 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.widget.TreeTimeoutIterator");
13
dojo.provide("dojo.widget.TreeTimeoutIterator");
12
dojo.require("dojo.event.*");
14
dojo.require("dojo.event.*");
13
dojo.require("dojo.json");
15
dojo.require("dojo.json");
14
dojo.require("dojo.io.*");
16
dojo.require("dojo.io.*");
15
dojo.require("dojo.widget.TreeCommon");
17
dojo.require("dojo.widget.TreeCommon");
16
dojo.declare("dojo.widget.TreeTimeoutIterator", null, function (elem, callFunc, callObj) {
18
dojo.declare("dojo.widget.TreeTimeoutIterator", null, function (elem, callFunc, callObj) {
17
	var _this = this;
19
	var _this = this;
18
	this.currentParent = elem;
20
	this.currentParent = elem;
19
	this.callFunc = callFunc;
21
	this.callFunc = callFunc;
20
	this.callObj = callObj ? callObj : this;
22
	this.callObj = callObj ? callObj : this;
21
	this.stack = [];
23
	this.stack = [];
22
}, {maxStackDepth:Number.POSITIVE_INFINITY, stack:null, currentParent:null, currentIndex:0, filterFunc:function () {
24
}, {maxStackDepth:Number.POSITIVE_INFINITY, stack:null, currentParent:null, currentIndex:0, filterFunc:function () {
23
	return true;
25
	return true;
24
}, finishFunc:function () {
26
}, finishFunc:function () {
25
	return true;
27
	return true;
26
}, setFilter:function (func, obj) {
28
}, setFilter:function (func, obj) {
27
	this.filterFunc = func;
29
	this.filterFunc = func;
28
	this.filterObj = obj;
30
	this.filterObj = obj;
29
}, setMaxLevel:function (level) {
31
}, setMaxLevel:function (level) {
30
	this.maxStackDepth = level - 2;
32
	this.maxStackDepth = level - 2;
31
}, forward:function (timeout) {
33
}, forward:function (timeout) {
32
	var _this = this;
34
	var _this = this;
33
	if (this.timeout) {
35
	if (this.timeout) {
34
		var tid = setTimeout(function () {
36
		var tid = setTimeout(function () {
35
			_this.processNext();
37
			_this.processNext();
36
			clearTimeout(tid);
38
			clearTimeout(tid);
37
		}, _this.timeout);
39
		}, _this.timeout);
38
	} else {
40
	} else {
39
		return this.processNext();
41
		return this.processNext();
40
	}
42
	}
41
}, start:function (processFirst) {
43
}, start:function (processFirst) {
42
	if (processFirst) {
44
	if (processFirst) {
43
		return this.callFunc.call(this.callObj, this.currentParent, this);
45
		return this.callFunc.call(this.callObj, this.currentParent, this);
44
	}
46
	}
45
	return this.processNext();
47
	return this.processNext();
46
}, processNext:function () {
48
}, processNext:function () {
47
	var handler;
49
	var handler;
48
	var _this = this;
50
	var _this = this;
49
	var found;
51
	var found;
50
	var next;
52
	var next;
51
	if (this.maxStackDepth == -2) {
53
	if (this.maxStackDepth == -2) {
52
		return;
54
		return;
53
	}
55
	}
54
	while (true) {
56
	while (true) {
55
		var children = this.currentParent.children;
57
		var children = this.currentParent.children;
56
		if (children && children.length) {
58
		if (children && children.length) {
57
			do {
59
			do {
58
				next = children[this.currentIndex];
60
				next = children[this.currentIndex];
59
			} while (this.currentIndex++ < children.length && !(found = this.filterFunc.call(this.filterObj, next)));
61
			} while (this.currentIndex++ < children.length && !(found = this.filterFunc.call(this.filterObj, next)));
60
			if (found) {
62
			if (found) {
61
				if (next.isFolder && this.stack.length <= this.maxStackDepth) {
63
				if (next.isFolder && this.stack.length <= this.maxStackDepth) {
62
					this.moveParent(next, 0);
64
					this.moveParent(next, 0);
63
				}
65
				}
64
				return this.callFunc.call(this.callObj, next, this);
66
				return this.callFunc.call(this.callObj, next, this);
65
			}
67
			}
66
		}
68
		}
67
		if (this.stack.length) {
69
		if (this.stack.length) {
68
			this.popParent();
70
			this.popParent();
69
			continue;
71
			continue;
70
		}
72
		}
71
		break;
73
		break;
72
	}
74
	}
73
	return this.finishFunc.call(this.finishObj);
75
	return this.finishFunc.call(this.finishObj);
74
}, setFinish:function (func, obj) {
76
}, setFinish:function (func, obj) {
75
	this.finishFunc = func;
77
	this.finishFunc = func;
76
	this.finishObj = obj;
78
	this.finishObj = obj;
77
}, popParent:function () {
79
}, popParent:function () {
78
	var p = this.stack.pop();
80
	var p = this.stack.pop();
79
	this.currentParent = p[0];
81
	this.currentParent = p[0];
80
	this.currentIndex = p[1];
82
	this.currentIndex = p[1];
81
}, moveParent:function (nextParent, nextIndex) {
83
}, moveParent:function (nextParent, nextIndex) {
82
	this.stack.push([this.currentParent, this.currentIndex]);
84
	this.stack.push([this.currentParent, this.currentIndex]);
83
	this.currentParent = nextParent;
85
	this.currentParent = nextParent;
84
	this.currentIndex = nextIndex;
86
	this.currentIndex = nextIndex;
85
}});
87
}});
86
 
88