summaryrefslogtreecommitdiff
path: root/includes/js/dijit/tests/ondijitclick.html
blob: 36de0e0c76113304607b7b37f372e781769b70df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

	<title>Test Dijit Internal Event: "ondijitclick"</title>

	<script type="text/javascript" src="../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
	<script type="text/javascript">
		dojo.require("doh.runner");
		dojo.require("dijit._Widget");
		dojo.require("dojo.parser");

		dojo.declare("dijit.WidgetWithOndijitclick",
			dijit._Widget,
			{
				clickCount: 0,
				_onClick: function() {
					this.clickCount++;
				},
				postCreate: function() {
					this.connect(this.domNode, "ondijitclick", "_onClick");
				}
			}
		);

		dojo.addOnLoad(function(){
			doh.register("ondijitclick",
				[
					{
						name: "ondijitclick fires once on a space-key-up",
						runTest: function(t){
							var w = dijit.byId("widget1");
							if (dojo.isSafari){ // safari has error
								this.name += " * SKIPPED *";
								return;
							}

							// simulate space up
							if (document.createEvent){
								var e = document.createEvent("KeyboardEvent");
								e.initKeyEvent("keyup",true,true,null,false,false,false,false,32,0);
								w.domNode.focus();
								w.clickCount = 0;
								w.domNode.dispatchEvent(e);
								t.is(1, w.clickCount);
							}
						}
					},
					{
						name: "ondijitclick fires once on an enter-key-down",
						runTest: function(t){
							var w = dijit.byId("widget1");
							if (dojo.isSafari){ // safari has error
								this.name += " * SKIPPED *";
								return;
							}

							// simulate enter down
							if (document.createEvent && !dojo.isSafari){
								var e = document.createEvent("KeyboardEvent");
								e.initKeyEvent("keydown",true,true,null,false,false,false,false,13,0);
								w.domNode.focus();
								w.clickCount = 0;
								w.domNode.dispatchEvent(e);
								t.is(1, w.clickCount);
							}
						}
					},
					{
						name: "ondijitclick fires once on a mouse click",
						runTest: function(t){
							var w = dijit.byId("widget1");

							// simulate enter up
							if (document.createEvent){
								var e = document.createEvent("MouseEvents");
								e.initMouseEvent('click', true, true, document.defaultView, 1, 0, 0, 3, 3, false, false, false, false, 0, w.domNode);
								w.clickCount = 0;
								w.domNode.dispatchEvent(e);
								t.is(1, w.clickCount);
							}
						}
					}
				]
			);
			doh.run();
		});

	</script>
</head>
<body class="tundra">
	<div id="widget1" dojoType="dijit.WidgetWithOndijitclick"></div>
</body>
</html>