Debian Codegraph @

dijit/tests/NodeList-instantiate.html

raw symbols SCIP
1 <html>
2 <head>
3 <title>dojo.NodeList.instantiate() tests</title>
4
5 <style type="text/css">
6 @import "../themes/claro/document.css";
7 @import "css/dijitTests.css";
8 #container { height: 200px; }
9 </style>
10
11 <!-- required: a default dijit theme: -->
12 <link id="themeStyles" rel="stylesheet" href="../../dijit/themes/claro/claro.css"/>
13
14 <!-- required: dojo.js -->
15 <script type="text/javascript" src="../../dojo/dojo.js"
16 data-dojo-config="isDebug: true"></script>
17
18 <!-- not needed, for testing alternate themes -->
19 <script type="text/javascript" src="_testCommon.js"></script>
20
21 <script type="text/javascript">
22 dojo.require("doh.runner");
23 dojo.require("dojo.on");
24 dojo.require("dijit._WidgetBase");
25 dojo.require("dijit.form.Button");
26 dojo.require("dijit.layout.TabContainer");
27 dojo.require("dijit.layout.ContentPane");
28
29 dojo.ready(function(){
30
31 // declare a simple widget to use as a base test:
32 dojo.declare("TestWidget", dijit._WidgetBase, {
33 message: "",
34 postCreate:function(){
35 this.inherited(arguments);
36 this.own(dojo.on(this.domNode, "click", dojo.hitch(this, "workit")));
37 dojo.style(this.domNode, {
38 cursor: "pointer",
39 color: "#333"
40 });
41 this.domNode.innerHTML += this.message +" ("+this.id +")";
42 console.log('created', this.id);
43 },
44 workit: function(){
45 dojo.place(this.domNode, this.domNode.parentNode, "end");
46 }
47 });
48
49 doh.register("Instantiate", [
50 function testWidget(){
51 dojo.query("#list1 li").instantiate(TestWidget, {}).connect("onclick", console.log);
52
53 var li = dijit.byId("TestWidget_0");
54 doh.t(li, "TestWidget_0 exists");
55 doh.is("pointer", dojo.style("TestWidget_0", "cursor"));
56 doh.is("inner (TestWidget_0)", li.domNode.innerHTML);
57 },
58
59 function testWidget2(){
60 dojo.query("#list2 li").instantiate(TestWidget, { message: "woot" });
61
62 li = dijit.byId("TestWidget_12");
63 doh.t(li, "TestWidget_12 exists");
64 doh.is("pointer", dojo.style("TestWidget_12", "cursor"));
65 doh.is("innerwoot (TestWidget_12)", li.domNode.innerHTML);
66 },
67
68 function TabContainer(){
69 // make a tab container from some div, and all it's children div's
70 dojo.query("#container")
71 .forEach(function(n){
72 dojo.query("div", n)
73 // create contentpanes from the children and style them
74 .instantiate(dijit.layout.ContentPane, {})
75 .forEach(function(wn, idx){
76 dojo.mixin(dijit.byNode(wn), { title: "tab" + (idx + 1) })
77 })
78 ;
79 })
80 .instantiate(dijit.layout.TabContainer, {})
81 ;
82 // should we add auto-startup calling?
83 dijit.byId("container").startup();
84
85 var tc = dijit.byId("container");
86 doh.t(tc, "Tab container exists");
87
88 var tabs = tc.tablist.getChildren();
89 doh.is(3, tabs.length);
90 dojo.forEach(tabs, function(tab, i){
91 doh.is("tab" + (i + 1), tab.label);
92 });
93
94 var children = tc.getChildren();
95 doh.is(3, children.length);
96 dojo.forEach(children, function(child, i){ doh.is("pane"+(i+1), child.domNode.innerHTML); })
97 },
98
99 function Buttons(){
100 // bunches of buttons, use you imagination on how to relate them to something
101 dojo.query("#buttonTest").forEach(function(n){
102 dojo.query("button", n).instantiate(dijit.form.Button, {
103 onClick:function(){
104 this.containerNode.innerHTML = this.label + " was clicked";
105 }
106 });
107 });
108
109 var b1 = dijit.byId("b1");
110 doh.t(b1, "button 1 exists");
111 doh.is("button 1", b1.label);
112
113 var b2 = dijit.byId("b2");
114 doh.t(b2, "button 2 exists");
115 doh.is("button 2", b2.label);
116
117 var b3 = dijit.byId("b3");
118 doh.t(b3, "button 3 exists");
119 doh.is("button 3", b3.label);
120
121 var b4 = dijit.byId("b4");
122 doh.t(b4, "button 4 exists");
123 doh.is("button 4", b4.label);
124 }
125 ]);
126
127 doh.run();
128 });
129 </script>
130 </head>
131 <body class="claro">
132
133 <h1>dojo.NodeList.instantiate() tests</h1>
134
135 <h2>Some simple widgets:</h2>
136 <ul id="list1"
137 ><li>inner</li><li>inner</li><li>inner</li><li>inner</li><li>inner</li><li>inner</li><li>inner</li><li>inner</li><li>inner</li
138 ></ul>
139 <ul id="list2"
140 ><li>inner</li><li>inner</li><li>inner</li><li>inner</li><li>inner</li><li>inner</li><li>inner</li><li>inner</li><li>inner</li
141 ></ul>
142
143 <h2>A TabContainer:</h2>
144 <div id="container"
145 ><div>pane1</div
146 ><div>pane2</div
147 ><div>pane3</div
148 ></div>
149
150 <h2>Some Buttons</h2>
151 <div id="buttonTest"
152 ><button id="b1">button 1</button
153 ><button id="b2">button 2</button
154 ><button id="b3">button 3</button
155 ><button id="b4">button 4</button
156 ></div>
157
158 </body>
159 </html>