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.TreeCommon");
13
dojo.provide("dojo.widget.TreeCommon");
12
dojo.require("dojo.widget.*");
14
dojo.require("dojo.widget.*");
13
dojo.declare("dojo.widget.TreeCommon", null, {listenTreeEvents:[], listenedTrees:{}, listenNodeFilter:null, listenTree:function (tree) {
15
dojo.declare("dojo.widget.TreeCommon", null, {listenTreeEvents:[], listenedTrees:{}, listenNodeFilter:null, listenTree:function (tree) {
14
	var _this = this;
16
	var _this = this;
15
	if (this.listenedTrees[tree.widgetId]) {
17
	if (this.listenedTrees[tree.widgetId]) {
16
		return;
18
		return;
17
	}
19
	}
18
	dojo.lang.forEach(this.listenTreeEvents, function (event) {
20
	dojo.lang.forEach(this.listenTreeEvents, function (event) {
19
		var eventHandler = "on" + event.charAt(0).toUpperCase() + event.substr(1);
21
		var eventHandler = "on" + event.charAt(0).toUpperCase() + event.substr(1);
20
		dojo.event.topic.subscribe(tree.eventNames[event], _this, eventHandler);
22
		dojo.event.topic.subscribe(tree.eventNames[event], _this, eventHandler);
21
	});
23
	});
22
	var filter;
24
	var filter;
23
	if (this.listenNodeFilter) {
25
	if (this.listenNodeFilter) {
24
		this.processDescendants(tree, this.listenNodeFilter, this.listenNode, true);
26
		this.processDescendants(tree, this.listenNodeFilter, this.listenNode, true);
25
	}
27
	}
26
	this.listenedTrees[tree.widgetId] = true;
28
	this.listenedTrees[tree.widgetId] = true;
27
}, listenNode:function () {
29
}, listenNode:function () {
28
}, unlistenNode:function () {
30
}, unlistenNode:function () {
29
}, unlistenTree:function (tree, nodeFilter) {
31
}, unlistenTree:function (tree, nodeFilter) {
30
	var _this = this;
32
	var _this = this;
31
	if (!this.listenedTrees[tree.widgetId]) {
33
	if (!this.listenedTrees[tree.widgetId]) {
32
		return;
34
		return;
33
	}
35
	}
34
	dojo.lang.forEach(this.listenTreeEvents, function (event) {
36
	dojo.lang.forEach(this.listenTreeEvents, function (event) {
35
		var eventHandler = "on" + event.charAt(0).toUpperCase() + event.substr(1);
37
		var eventHandler = "on" + event.charAt(0).toUpperCase() + event.substr(1);
36
		dojo.event.topic.unsubscribe(tree.eventNames[event], _this, eventHandler);
38
		dojo.event.topic.unsubscribe(tree.eventNames[event], _this, eventHandler);
37
	});
39
	});
38
	if (this.listenNodeFilter) {
40
	if (this.listenNodeFilter) {
39
		this.processDescendants(tree, this.listenNodeFilter, this.unlistenNode, true);
41
		this.processDescendants(tree, this.listenNodeFilter, this.unlistenNode, true);
40
	}
42
	}
41
	delete this.listenedTrees[tree.widgetId];
43
	delete this.listenedTrees[tree.widgetId];
42
}, checkPathCondition:function (domElement, condition) {
44
}, checkPathCondition:function (domElement, condition) {
43
	while (domElement && !domElement.widgetId) {
45
	while (domElement && !domElement.widgetId) {
44
		if (condition.call(null, domElement)) {
46
		if (condition.call(null, domElement)) {
45
			return true;
47
			return true;
46
		}
48
		}
47
		domElement = domElement.parentNode;
49
		domElement = domElement.parentNode;
48
	}
50
	}
49
	return false;
51
	return false;
50
}, domElement2TreeNode:function (domElement) {
52
}, domElement2TreeNode:function (domElement) {
51
	while (domElement && !domElement.widgetId) {
53
	while (domElement && !domElement.widgetId) {
52
		domElement = domElement.parentNode;
54
		domElement = domElement.parentNode;
53
	}
55
	}
54
	if (!domElement) {
56
	if (!domElement) {
55
		return null;
57
		return null;
56
	}
58
	}
57
	var widget = dojo.widget.byId(domElement.widgetId);
59
	var widget = dojo.widget.byId(domElement.widgetId);
58
	if (!widget.isTreeNode) {
60
	if (!widget.isTreeNode) {
59
		return null;
61
		return null;
60
	}
62
	}
61
	return widget;
63
	return widget;
62
}, processDescendants:function (elem, filter, func, skipFirst) {
64
}, processDescendants:function (elem, filter, func, skipFirst) {
63
	var _this = this;
65
	var _this = this;
64
	if (!skipFirst) {
66
	if (!skipFirst) {
65
		if (!filter.call(_this, elem)) {
67
		if (!filter.call(_this, elem)) {
66
			return;
68
			return;
67
		}
69
		}
68
		func.call(_this, elem);
70
		func.call(_this, elem);
69
	}
71
	}
70
	var stack = [elem];
72
	var stack = [elem];
71
	while (elem = stack.pop()) {
73
	while (elem = stack.pop()) {
72
		dojo.lang.forEach(elem.children, function (elem) {
74
		dojo.lang.forEach(elem.children, function (elem) {
73
			if (filter.call(_this, elem)) {
75
			if (filter.call(_this, elem)) {
74
				func.call(_this, elem);
76
				func.call(_this, elem);
75
				stack.push(elem);
77
				stack.push(elem);
76
			}
78
			}
77
		});
79
		});
78
	}
80
	}
79
}});
81
}});
80
 
82