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.Checkbox");
14
dojo.require("dojo.widget.*");
15
dojo.require("dojo.widget.HtmlWidget");
16
dojo.require("dojo.event.*");
17
dojo.require("dojo.html.style");
18
dojo.require("dojo.html.selection");
19
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 () {
20
	dojo.widget.Checkbox.superclass.postMixInProperties.apply(this, arguments);
21
	if (!this.disabled && this.tabIndex == "") {
22
		this.tabIndex = "0";
23
	}
24
}, fillInTemplate:function () {
25
	this._setInfo();
26
}, postCreate:function () {
27
	var notcon = true;
28
	this.id = this.id != "" ? this.id : this.widgetId;
29
	if (this.id != "") {
30
		var labels = document.getElementsByTagName("label");
31
		if (labels != null && labels.length > 0) {
32
			for (var i = 0; i < labels.length; i++) {
33
				if (labels[i].htmlFor == this.id) {
34
					labels[i].id = (labels[i].htmlFor + "label");
35
					this._connectEvents(labels[i]);
36
					dojo.widget.wai.setAttr(this.domNode, "waiState", "labelledby", labels[i].id);
37
					break;
38
				}
39
			}
40
		}
41
	}
42
	this._connectEvents(this.domNode);
43
	this.inputNode.checked = this.checked;
44
}, _connectEvents:function (node) {
45
	dojo.event.connect(node, "onmouseover", this, "mouseOver");
46
	dojo.event.connect(node, "onmouseout", this, "mouseOut");
47
	dojo.event.connect(node, "onkey", this, "onKey");
48
	dojo.event.connect(node, "onclick", this, "_onClick");
49
	dojo.html.disableSelection(node);
50
}, _onClick:function (e) {
51
	if (this.disabled == false) {
52
		this.checked = !this.checked;
53
		this._setInfo();
54
	}
55
	e.preventDefault();
56
	e.stopPropagation();
57
	this.onClick();
58
}, setValue:function (bool) {
59
	if (this.disabled == false) {
60
		this.checked = bool;
61
		this._setInfo();
62
	}
63
}, onClick:function () {
64
}, onKey:function (e) {
65
	var k = dojo.event.browser.keys;
66
	if (e.key == " ") {
67
		this._onClick(e);
68
	}
69
}, mouseOver:function (e) {
70
	this._hover(e, true);
71
}, mouseOut:function (e) {
72
	this._hover(e, false);
73
}, _hover:function (e, isOver) {
74
	if (this.disabled == false) {
75
		var state = this.checked ? "On" : "Off";
76
		var style = "dojoHtmlCheckbox" + state + "Hover";
77
		if (isOver) {
78
			dojo.html.addClass(this.imageNode, style);
79
		} else {
80
			dojo.html.removeClass(this.imageNode, style);
81
		}
82
	}
83
}, _setInfo:function () {
84
	var state = "dojoHtmlCheckbox" + (this.disabled ? "Disabled" : "") + (this.checked ? "On" : "Off");
85
	dojo.html.setClass(this.imageNode, "dojoHtmlCheckbox " + state);
86
	this.inputNode.checked = this.checked;
87
	if (this.disabled) {
88
		this.inputNode.setAttribute("disabled", true);
89
	} else {
90
		this.inputNode.removeAttribute("disabled");
91
	}
92
	dojo.widget.wai.setAttr(this.domNode, "waiState", "checked", this.checked);
93
}});
94
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 () {
95
}, postCreate:function (args, frag) {
96
	this.inputNode.checked = this.checked;
97
	if (this.disabled) {
98
		this.inputNode.setAttribute("disabled", true);
99
	}
100
}, _onClick:function () {
101
	this.onClick();
102
}});
103