Subversion Repositories Applications.papyrus

Rev

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