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.RadioGroup");
12
dojo.require("dojo.lang.common");
13
dojo.require("dojo.event.browser");
14
dojo.require("dojo.html.selection");
15
dojo.require("dojo.widget.*");
16
dojo.require("dojo.widget.HtmlWidget");
17
dojo.widget.defineWidget("dojo.widget.RadioGroup", dojo.widget.HtmlWidget, function () {
18
	this.selectedItem = null;
19
	this.items = [];
20
	this.selected = [];
21
	this.groupCssClass = "radioGroup";
22
	this.selectedCssClass = "selected";
23
	this.itemContentCssClass = "itemContent";
24
}, {isContainer:false, templatePath:null, templateCssPath:null, postCreate:function () {
25
	this._parseStructure();
26
	dojo.html.addClass(this.domNode, this.groupCssClass);
27
	this._setupChildren();
28
	dojo.event.browser.addListener(this.domNode, "onclick", dojo.lang.hitch(this, "onSelect"));
29
	if (this.selectedItem) {
30
		this._selectItem(this.selectedItem);
31
	}
32
}, _parseStructure:function () {
33
	if (this.domNode.tagName.toLowerCase() != "ul" && this.domNode.tagName.toLowerCase() != "ol") {
34
		dojo.raise("RadioGroup: Expected ul or ol content.");
35
		return;
36
	}
37
	this.items = [];
38
	var nl = this.domNode.getElementsByTagName("li");
39
	for (var i = 0; i < nl.length; i++) {
40
		if (nl[i].parentNode == this.domNode) {
41
			this.items.push(nl[i]);
42
		}
43
	}
44
}, add:function (node) {
45
	if (node.parentNode != this.domNode) {
46
		this.domNode.appendChild(node);
47
	}
48
	this.items.push(node);
49
	this._setup(node);
50
}, remove:function (node) {
51
	var idx = -1;
52
	for (var i = 0; i < this.items.length; i++) {
53
		if (this.items[i] == node) {
54
			idx = i;
55
			break;
56
		}
57
	}
58
	if (idx < 0) {
59
		return;
60
	}
61
	this.items.splice(idx, 1);
62
	node.parentNode.removeChild(node);
63
}, clear:function () {
64
	for (var i = 0; i < this.items.length; i++) {
65
		this.domNode.removeChild(this.items[i]);
66
	}
67
	this.items = [];
68
}, clearSelections:function () {
69
	for (var i = 0; i < this.items.length; i++) {
70
		dojo.html.removeClass(this.items[i], this.selectedCssClass);
71
	}
72
	this.selectedItem = null;
73
}, _setup:function (node) {
74
	var span = document.createElement("span");
75
	dojo.html.disableSelection(span);
76
	dojo.html.addClass(span, this.itemContentCssClass);
77
	dojo.dom.moveChildren(node, span);
78
	node.appendChild(span);
79
	if (this.selected.length > 0) {
80
		var uid = dojo.html.getAttribute(node, "id");
81
		if (uid && uid == this.selected) {
82
			this.selectedItem = node;
83
		}
84
	}
85
	dojo.event.browser.addListener(node, "onclick", dojo.lang.hitch(this, "onItemSelect"));
86
	if (dojo.html.hasAttribute(node, "onitemselect")) {
87
		var tn = dojo.lang.nameAnonFunc(new Function(dojo.html.getAttribute(node, "onitemselect")), this);
88
		dojo.event.browser.addListener(node, "onclick", dojo.lang.hitch(this, tn));
89
	}
90
}, _setupChildren:function () {
91
	for (var i = 0; i < this.items.length; i++) {
92
		this._setup(this.items[i]);
93
	}
94
}, _selectItem:function (node, event, nofire) {
95
	if (this.selectedItem) {
96
		dojo.html.removeClass(this.selectedItem, this.selectedCssClass);
97
	}
98
	this.selectedItem = node;
99
	dojo.html.addClass(this.selectedItem, this.selectedCssClass);
100
	if (!dj_undef("currentTarget", event)) {
101
		return;
102
	}
103
	if (!nofire) {
104
		if (dojo.render.html.ie) {
105
			this.selectedItem.fireEvent("onclick");
106
		} else {
107
			var e = document.createEvent("MouseEvents");
108
			e.initEvent("click", true, false);
109
			this.selectedItem.dispatchEvent(e);
110
		}
111
	}
112
}, getValue:function () {
113
	return this.selectedItem;
114
}, onSelect:function (e) {
115
}, onItemSelect:function (e) {
116
	if (!dj_undef("currentTarget", e)) {
117
		this._selectItem(e.currentTarget, e);
118
	}
119
}});
120