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