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.Checkbox");
12
dojo.require("dojo.widget.*");
13
dojo.require("dojo.widget.HtmlWidget");
14
dojo.require("dojo.event.*");
15
dojo.require("dojo.html.style");
16
dojo.require("dojo.html.selection");
17
dojo.widget.defineWidget("dojo.widget.Checkbox", dojo.widget.HtmlWidget, {templateString:"<span style=\"display: inline-block;\" tabIndex=\"${this.tabIndex}\" waiRole=\"checkbox\" id=\"${this.id}\">\n\t<img dojoAttachPoint=\"imageNode\" class=\"dojoHtmlCheckbox\" src=\"${dojoWidgetModuleUri}templates/images/blank.gif\" alt=\"\" />\n\t<input type=\"checkbox\" name=\"${this.name}\" style=\"display: none\" value=\"${this.value}\"\n\t\tdojoAttachPoint=\"inputNode\">\n</span>\n", templateCssString:".dojoHtmlCheckbox {\n\tborder: 0px;\n\twidth: 16px;\n\theight: 16px;\n\tmargin: 2px;\n\tvertical-align: middle;\n}\n\n.dojoHtmlCheckboxOn {\n\tbackground: url(check.gif) 0px 0px;\n}\n.dojoHtmlCheckboxOff {\n\tbackground: url(check.gif) -16px 0px;\n}\n.dojoHtmlCheckboxDisabledOn {\n\tbackground: url(check.gif) -32px 0px;\n}\n.dojoHtmlCheckboxDisabledOff {\n\tbackground: url(check.gif) -48px 0px;\n}\n.dojoHtmlCheckboxOnHover {\n\tbackground: url(check.gif) -64px 0px;\n}\n.dojoHtmlCheckboxOffHover {\n\tbackground: url(check.gif) -80px 0px;\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/Checkbox.css"), name:"", id:"", checked:false, tabIndex:"", value:"on", postMixInProperties:function () {
18
	dojo.widget.Checkbox.superclass.postMixInProperties.apply(this, arguments);
19
	if (!this.disabled && this.tabIndex == "") {
20
		this.tabIndex = "0";
21
	}
22
}, fillInTemplate:function () {
23
	this._setInfo();
24
}, postCreate:function () {
25
	var notcon = true;
26
	this.id = this.id != "" ? this.id : this.widgetId;
27
	if (this.id != "") {
28
		var labels = document.getElementsByTagName("label");
29
		if (labels != null && labels.length > 0) {
30
			for (var i = 0; i < labels.length; i++) {
31
				if (labels[i].htmlFor == this.id) {
32
					labels[i].id = (labels[i].htmlFor + "label");
33
					this._connectEvents(labels[i]);
34
					dojo.widget.wai.setAttr(this.domNode, "waiState", "labelledby", labels[i].id);
35
					break;
36
				}
37
			}
38
		}
39
	}
40
	this._connectEvents(this.domNode);
41
	this.inputNode.checked = this.checked;
42
}, _connectEvents:function (node) {
43
	dojo.event.connect(node, "onmouseover", this, "mouseOver");
44
	dojo.event.connect(node, "onmouseout", this, "mouseOut");
45
	dojo.event.connect(node, "onkey", this, "onKey");
46
	dojo.event.connect(node, "onclick", this, "_onClick");
47
	dojo.html.disableSelection(node);
48
}, _onClick:function (e) {
49
	if (this.disabled == false) {
50
		this.checked = !this.checked;
51
		this._setInfo();
52
	}
53
	e.preventDefault();
54
	e.stopPropagation();
55
	this.onClick();
56
}, setValue:function (bool) {
57
	if (this.disabled == false) {
58
		this.checked = bool;
59
		this._setInfo();
60
	}
61
}, onClick:function () {
62
}, onKey:function (e) {
63
	var k = dojo.event.browser.keys;
64
	if (e.key == " ") {
65
		this._onClick(e);
66
	}
67
}, mouseOver:function (e) {
68
	this._hover(e, true);
69
}, mouseOut:function (e) {
70
	this._hover(e, false);
71
}, _hover:function (e, isOver) {
72
	if (this.disabled == false) {
73
		var state = this.checked ? "On" : "Off";
74
		var style = "dojoHtmlCheckbox" + state + "Hover";
75
		if (isOver) {
76
			dojo.html.addClass(this.imageNode, style);
77
		} else {
78
			dojo.html.removeClass(this.imageNode, style);
79
		}
80
	}
81
}, _setInfo:function () {
82
	var state = "dojoHtmlCheckbox" + (this.disabled ? "Disabled" : "") + (this.checked ? "On" : "Off");
83
	dojo.html.setClass(this.imageNode, "dojoHtmlCheckbox " + state);
84
	this.inputNode.checked = this.checked;
85
	if (this.disabled) {
86
		this.inputNode.setAttribute("disabled", true);
87
	} else {
88
		this.inputNode.removeAttribute("disabled");
89
	}
90
	dojo.widget.wai.setAttr(this.domNode, "waiState", "checked", this.checked);
91
}});
92
dojo.widget.defineWidget("dojo.widget.a11y.Checkbox", dojo.widget.Checkbox, {templateString:"<span class='dojoHtmlCheckbox'>\n\t<input type=\"checkbox\" name=\"${this.name}\" tabIndex=\"${this.tabIndex}\" id=\"${this.id}\" value=\"${this.value}\"\n\t\t dojoAttachEvent=\"onClick: _onClick;\" dojoAttachPoint=\"inputNode\"> \n</span>\n", fillInTemplate:function () {
93
}, postCreate:function (args, frag) {
94
	this.inputNode.checked = this.checked;
95
	if (this.disabled) {
96
		this.inputNode.setAttribute("disabled", true);
97
	}
98
}, _onClick:function () {
99
	this.onClick();
100
}});
101