source: Dev/trunk/src/client/dojox/NodeList/tests/delegate.html

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.6 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2        "http://www.w3.org/TR/html4/strict.dtd">
3<html id="html">
4        <head>
5                <title>NodeList.delegate() test</title>
6                <style type="text/css">
7                        @import "../../resources/dojo.css";
8                </style>
9                <script type="text/javascript"
10                        src="../../../dojo/dojo.js" data-dojo-config="isDebug: true, popup: true"></script>
11                <script type="text/javascript">
12                        dojo.require("dojox.NodeList.delegate");
13                               
14                        dojo.addOnLoad(function(){
15                                // Monitor onclick events on div.blue nodes, or that bubble up to div.blue nodes
16                                dojo.query("div.delegator").delegate("div.blue", "onclick", function(evt){
17                                        // "this" points to the div.blue node
18                                        dojo.style(this, "backgroundColor", "#aaf");
19                                });
20                                dojo.query("div.delegator").delegate("input", "onfocus", function(evt){
21                                        // "this" points to the input node
22                                        console.log("bubbled input event");
23                                        dojo.style(this, "backgroundColor", "black");
24                                });
25
26                                // Generate div.blue nodes inside each wrapper div.
27                                // Runs after the delegate() call to demonstrate that delegate() catches events on "future nodes"
28                                dojo.query("div.wrapper").forEach(function(div){
29                                        for(var i=0; i<4; i++){
30                                                dojo.place(
31                                                        "<div class=" + (i%2?"blue":"red") + ">" +
32                                                                (i%2 && dojo.hasClass(div, "delegator") ? "click me to turn me blue" : "click will have no effect" )+
33                                                                "<span>" + (i%2  && dojo.hasClass(div, "delegator") ? "or click me to turn parent blue" : "nor will a click here") + "</span>"+
34                                                                "focus input to turn it black (not working yet): <input />" +
35                                                        "</div>",
36                                                        div
37                                                );
38                                        }
39                                });
40                        });
41                </script>
42                <style>
43                        div, a { padding: 5px; margin: 5px; display: block; }
44                        div.blue { border: blue solid 2px; }
45                        div.red { border: red solid 2px; }
46                        div.wrapper { border: solid gray 4px; background: #eee; }
47                        div.delegator { background: #ccc; }
48                        span { display: block; border: yellow solid 2px; }
49                </style>
50        </head>
51        <body id="body" class="classy">
52                <h1>Test of NodeList.delegate() method</h1>
53                <div class=blue style="border: 2px dotted black;">
54                        <h3>
55                                This DIV has class=blue but it shouldn't matter because the delegate() connections are on
56                        sub node inside of me.
57                        </h3>
58                        <div class="wrapper delegator">
59                                <h3>This div has a delegate handler on it so clicking the blue DIV's below will have an effect.</h3>
60                        </div>
61                        <div class="wrapper delegator">
62                                <h3>This div has a delegate handler on it so clicking the blue DIV's below will have an effect.</h3>
63                        </div>
64                        <div class="wrapper">
65                                <h3>This div doesn't have a delegate handler on it so clicking the blue DIV's below will have no effect.</h3>
66                        </div>
67                </div>
68        </body>
69</html>
70
Note: See TracBrowser for help on using the repository browser.