Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2
	"http://www.w3.org/TR/html4/strict.dtd">
3
<html>
4
	<head>
5
		<title>Testing dojo.behavior</title>
6
		<style type="text/css">
7
			@import "../resources/dojo.css";
8
		</style>
9
		<script type="text/javascript"
10
			src="../dojo.js" djConfig="isDebug: false"></script>
11
		<script type="text/javascript">
12
			dojo.require("doh.runner");
13
			dojo.require("dojo.behavior");
14
 
15
			var applyCount = 0;
16
 
17
			var behaviorObj = {
18
				".bar": 		function(elem){
19
					dojo.style(elem, "opacity", 0.5);
20
					applyCount++;
21
				},
22
				".foo > span":	function(elem){
23
					elem.style.fontStyle = "italic";
24
					applyCount++;
25
				}
26
			}
27
 
28
			var topicCount = 0;
29
			dojo.subscribe("/foo", function(){ topicCount++; });
30
 
31
			// no behaviors should be executed when onload fires
32
			dojo.addOnLoad(function(){
33
				doh.register("t",
34
					[
35
						function add(t){
36
							t.f(dojo.behavior._behaviors[".bar"]);
37
							t.f(dojo.behavior._behaviors[".foo > span"]);
38
							dojo.behavior.add(behaviorObj);
39
							// make sure they got plopped in
40
							t.t(dojo.behavior._behaviors[".bar"]);
41
							t.is(1, dojo.behavior._behaviors[".bar"].length);
42
							t.t(dojo.behavior._behaviors[".foo > span"]);
43
							t.is(1, dojo.behavior._behaviors[".foo > span"].length);
44
						},
45
						function apply(t){
46
							t.is(0, applyCount);
47
							dojo.behavior.apply();
48
							t.is(2, applyCount);
49
 
50
							// reapply and make sure we only match once
51
							dojo.behavior.apply();
52
							t.is(2, applyCount);
53
						},
54
						function reapply(t){
55
							t.is(2, applyCount);
56
							// add the rules again
57
							dojo.behavior.add(behaviorObj);
58
							dojo.behavior.apply();
59
							t.is(4, applyCount);
60
							// dojo.behavior.apply();
61
							// t.is(4, applyCount);
62
							// dojo.query(".bar").styles("opacity", 1.0);
63
						},
64
						function topics(t){
65
							t.is(0, topicCount);
66
							dojo.behavior.add({ ".foo": "/foo" });
67
							dojo.behavior.apply();
68
							t.is(2, topicCount);
69
 
70
							dojo.behavior.add({ ".foo": {
71
									"onfocus": "/foo"
72
								}
73
							});
74
							dojo.behavior.apply();
75
							t.is(2, topicCount);
76
							dojo.byId("blah").focus();
77
							t.is(3, topicCount);
78
							dojo.byId("blah").blur();
79
							dojo.byId("blah").focus();
80
							t.is(4, topicCount);
81
 
82
						}
83
					]
84
				);
85
				doh.run();
86
			});
87
		</script>
88
	</head>
89
	<body>
90
		<div class="foo" id="fooOne">
91
			<span>.foo &gt; span</span>
92
			<div class="bar">
93
				<span>.foo &gt; .bar &gt; span</span>
94
			</div>
95
		</div>
96
		<input type="text" id="blah" class="foo blah" name="thinger" value="thinger">
97
	</body>
98
</html>