Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

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