]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojo/tests/behavior.html
Comment class stub
[eow] / static / dojo-release-1.1.1 / dojo / tests / behavior.html
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: true, popup: true"></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                         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                                                         var d = new doh.Deferred();
66                                                         t.is(0, topicCount);
67                                                         dojo.behavior.add({ ".foo": "/foo" });
68                                                         dojo.behavior.apply();
69                                                         t.is(2, topicCount);
70
71                                                         dojo.behavior.add({ ".foo": {
72                                                                         "onfocus": "/foo" 
73                                                                 }
74                                                         });
75                                                         dojo.behavior.apply();
76                                                         t.is(2, topicCount);
77                                                         dojo.byId("blah").focus();
78                                                         dojo.byId("blah").blur();
79                                                         dojo.byId("blah").focus();
80                                                         setTimeout(function(){
81                                                                 // blur/focus event generation isn't synchronous on IE
82                                                                 try{
83                                                                         t.is(4, topicCount);
84                                                                         d.callback(true);
85                                                                 }catch(e){
86                                                                         d.errback(e);
87                                                                 }
88                                                         }, 10);
89                                                         return d;
90                                                 }
91                                         ]
92                                 );
93                                 doh.run();
94                         });
95                 </script>
96         </head>
97         <body>
98                 <div class="foo" id="fooOne">
99                         <span>.foo &gt; span</span>     
100                         <div class="bar">
101                                 <span>.foo &gt; .bar &gt; span</span>   
102                         </div>
103                 </div>
104                 <input type="text" id="blah" class="foo blah" name="thinger" value="thinger" tabIndex="0">
105         </body>
106 </html>