| 1 | <html> |
| 2 | <head> |
| 3 | <title>Demo using dojox.dtl._DomTemplated</title> |
| 4 | <script type="text/javascript" src="../../../dojo/dojo.js" |
| 5 | data-dojo-config="async:true, isDebug: true, parseOnLoad: true"></script> |
| 6 | <style type="text/css"> |
| 7 | @import "../../../dijit/themes/tundra/tundra.css"; |
| 8 | #pane { |
| 9 | border: 1px solid darkblue; |
| 10 | } |
| 11 | </style> |
| 12 | <script type="text/javascript"> |
| 13 | require(["dojo/_base/declare", |
| 14 | "dojo/keys", |
| 15 | "dojo/_base/array", |
| 16 | "dijit/_WidgetBase", |
| 17 | "dojox/dtl/_DomTemplated", |
| 18 | "dijit/form/Button", |
| 19 | "dijit/layout/ContentPane", |
| 20 | "dojo/parser", |
| 21 | "dojox/dtl/tag/logic"], |
| 22 | function(declare, keys, array, _WidgetBase, _DomTemplated, Button, ContentPane){ |
| 23 | |
| 24 | declare("Fruit", [_WidgetBase, _DomTemplated], { |
| 25 | widgetsInTemplate: true, |
| 26 | items: ["apple", "banana", "orange"], |
| 27 | keyUp: function(e){ |
| 28 | if((e.type == "click" || e.keyCode == keys.ENTER) && this.input.value){ |
| 29 | console.debug(this.button); |
| 30 | var i = array.indexOf(this.items, this.input.value); |
| 31 | if(i != -1){ |
| 32 | this.items.splice(i, 1); |
| 33 | }else{ |
| 34 | this.items.push(this.input.value); |
| 35 | } |
| 36 | this.input.value = ""; |
| 37 | this.render(); |
| 38 | } |
| 39 | }, |
| 40 | templateString: '<div><input data-dojo-attach-event="onkeyup:keyUp" data-dojo-attach-point="input"> <button data-dojo-type="dijit.form.Button" data-dojo-attach-point="button" data-dojo-attach-event="onClick: keyUp">Add/Remove Item</button><div id="pane" data-dojo-type="dijit.layout.ContentPane parsed"><ul><!--{% for item in items %}--><li><button data-dojo-type="dijit.form.Button parsed" title="Fruit: {{ item }}" otherAttr2="x_{{item}}"><!--{{ item }}--><script type="dojo/on" data-dojo-event="click" data-dojo-args="e">console.debug("You clicked", this.containerNode.innerHTML);</' + 'script></button></li><!--{% endfor %}--></ul></div></div>' |
| 41 | }); |
| 42 | } |
| 43 | ); |
| 44 | |
| 45 | </script> |
| 46 | </head> |
| 47 | <body class="tundra"> |
| 48 | <div data-dojo-type="Fruit" id="dtl"></div> |
| 49 | </body> |
| 50 | </html> |