summaryrefslogtreecommitdiff
path: root/js/dojo/dojox/dtl/demos/demo_Events.html
blob: ec181b93eb7e76d9209f9edb287fab9532c225a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<html>
	<head>
			<title>Demo using dojox.dtl._Templated</title>
	    <script type="text/javascript" src="../../../dojo/dojo.js"
				djConfig="isDebug: true, parseOnLoad: true"></script>
			<style type="text/css">
				@import "../../../dijit/themes/tundra/tundra.css";
			</style>
	    <script type="text/javascript">
					dojo.require("dijit._WidgetBase");
					dojo.require("dojox.dtl._DomTemplated");
					dojo.require("dijit.form.Button");

					dojo.declare("Fruit", [dijit._WidgetBase, dojox.dtl._DomTemplated], {
						widgetsInTemplate: true,
						items: ["apple", "banana", "orange"],
						keyUp: function(e){
							if((e.type == "click" || e.keyCode == dojo.keys.ENTER) && this.input.value){
								var i = dojo.indexOf(this.items, this.input.value);
								if(i != -1){
									this.items.splice(i, 1);
								}else{
									this.items.push(this.input.value);
								}
								this.input.value = "";
								this.render();
							}
						},
						postCreate: function(){
						 	this.render();
							dojo.connect(this.button, "onClick", this, "keyUp");
						},
						debug: function(e, verb, fruit){
							console.debug("You " + verb + " a:", fruit);
						},
						// Note, the load tag here is superfluous, since _DomTemplate has a dojo.require for it.
						templateString: '{% load dojox.dtl.contrib.dijit %}<div><input dojoAttachEvent="onkeyup: keyUp" dojoAttachPoint="input"> <button dojoType="dijit.form.Button" dojoAttachPoint="button">Add/Remove Item</button><ul><!--{% for item in items %}--><li onclick="debug \'ate\' item"><!--{{ item }}--></li><!--{% endfor %}--></ul></div>'
					});

	        dojo.require("dojo.parser");
	    </script>
	</head>
	<body class="tundra">
		<div dojoType="Fruit"></div>
	</body>
</html>