1 | <!DOCTYPE html> |
---|
2 | <html> |
---|
3 | <head> |
---|
4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
---|
5 | <title>_Widget on() test</title> |
---|
6 | <style type="text/css"> |
---|
7 | @import "../themes/claro/document.css"; |
---|
8 | @import "../themes/claro/claro.css"; |
---|
9 | @import "css/dijitTests.css"; |
---|
10 | </style> |
---|
11 | |
---|
12 | <script type="text/javascript" src="../../dojo/dojo.js" |
---|
13 | data-dojo-config="isDebug: true"></script> |
---|
14 | <script> |
---|
15 | dojo.require("doh.runner"); |
---|
16 | dojo.require("dojo.parser"); |
---|
17 | dojo.require("dojo.on"); |
---|
18 | dojo.require("dojo._base.declare"); |
---|
19 | dojo.require("dijit._Widget"); |
---|
20 | dojo.require("dijit.registry"); |
---|
21 | |
---|
22 | |
---|
23 | dojo.ready(function(){ |
---|
24 | var mousedOver, clicked; |
---|
25 | |
---|
26 | doh.register("on", [ |
---|
27 | function setup(){ |
---|
28 | dojo.declare("MyWidget", [dijit._Widget], { |
---|
29 | postCreate: function(){ |
---|
30 | dojo.on(this.domNode, "click", dojo.hitch(this, "onFooBar")); |
---|
31 | }, |
---|
32 | onFooBar: function(){ |
---|
33 | // This is called whenever the widget is clicked |
---|
34 | }, |
---|
35 | foobar: function(){ |
---|
36 | // A widget.on("foobar") should go to onFooBar() (above), not here |
---|
37 | } |
---|
38 | }); |
---|
39 | |
---|
40 | dojo.parser.parse(); |
---|
41 | }, |
---|
42 | |
---|
43 | function connect(){ |
---|
44 | // This should work despite the fact that the function onMouseOver has |
---|
45 | // multiple capital letters |
---|
46 | dijit.registry.byId("myWidget").on("mouseover", function(){ |
---|
47 | mousedOver = true; |
---|
48 | console.log("mouseover event"); |
---|
49 | }); |
---|
50 | |
---|
51 | // Likewise, this should work despite the fact that the function onFooBar has |
---|
52 | // multiple capital letters |
---|
53 | dijit.registry.byId("myWidget").on("foobar", function(){ |
---|
54 | clicked = true; |
---|
55 | console.log("click event"); |
---|
56 | }); |
---|
57 | }, |
---|
58 | |
---|
59 | function test(){ |
---|
60 | var myWidget = dijit.registry.byId("myWidget"); |
---|
61 | |
---|
62 | // Test that _Widget.on() catches click event |
---|
63 | doh.f(clicked, "clicked"); |
---|
64 | dojo.on.emit(myWidget.domNode, "click", { |
---|
65 | bubbles: true, |
---|
66 | cancelable: true, |
---|
67 | which: 1 |
---|
68 | }); |
---|
69 | doh.t(clicked, "clicked"); |
---|
70 | |
---|
71 | // Test that _Widget.on() catches mouseover event |
---|
72 | doh.f(mousedOver, "mousedOver"); |
---|
73 | dojo.on.emit(myWidget.domNode, "mouseover", { |
---|
74 | bubbles: true, |
---|
75 | cancelable: true, |
---|
76 | which: 1 |
---|
77 | }); |
---|
78 | doh.t(mousedOver, "mousedOver"); |
---|
79 | } |
---|
80 | ]); |
---|
81 | |
---|
82 | doh.run(); |
---|
83 | }); |
---|
84 | |
---|
85 | </script> |
---|
86 | </head> |
---|
87 | <body class="claro"> |
---|
88 | <div id="myWidget" data-dojo-type="MyWidget"> |
---|
89 | mouseover and click events to console |
---|
90 | </div> |
---|
91 | </body> |
---|
92 | </html> |
---|