| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 |
"http://www.w3.org/TR/html4/strict.dtd"> |
| 3 |
<html> |
| 4 |
<head> |
| 5 |
|
| 6 |
<title>Dojo Toolkit - Declaration test</title> |
| 7 |
<style type="text/css"> |
| 8 |
@import "../themes/claro/document.css"; |
| 9 |
@import "css/dijitTests.css"; |
| 10 |
</style> |
| 11 |
|
| 12 |
|
| 13 |
<link id="themeStyles" rel="stylesheet" href="../../dijit/themes/claro/claro.css"/> |
| 14 |
|
| 15 |
|
| 16 |
<script type="text/javascript" src="../../dojo/dojo.js" |
| 17 |
djConfig="isDebug: true"></script> |
| 18 |
|
| 19 |
|
| 20 |
<script type="text/javascript" src="_testCommon.js"></script> |
| 21 |
|
| 22 |
<script type="text/javascript"> |
| 23 |
dojo.require("dijit.dijit"); // optimize: load dijit layer |
| 24 |
dojo.require("dijit.Declaration"); |
| 25 |
dojo.require("dijit.ProgressBar"); |
| 26 |
dojo.require("dojo.parser"); // scan page for widgets and instantiate them |
| 27 |
dojo.require("doh.runner"); |
| 28 |
|
| 29 |
dojo.ready(function(){ |
| 30 |
doh.register("dijit.Declaration_1.x", [ |
| 31 |
function parse(){ |
| 32 |
// run parser inside of DOH so we can tell if there are any exceptions |
| 33 |
dojo.parser.parse(); |
| 34 |
|
| 35 |
// test instantiation of dojo.Declaration widgets |
| 36 |
doh.t(hideButtonA, "hideButtonA instantiated"); |
| 37 |
doh.t(hideButtonB, "hideButtonB instantiated"); |
| 38 |
doh.t(hideButton2A, "hideButton2A instantiated"); |
| 39 |
doh.t(hideButton2B, "hideButton2B instantiated"); |
| 40 |
}, |
| 41 |
|
| 42 |
function basicTests(){ |
| 43 |
// test <script type="dojo/method"> |
| 44 |
doh.t(HideButton.prototype.myHandler, "myHandler method added to HideButton prototype"); |
| 45 |
doh.t(HideButton2.prototype.myHandler, "myHandler method added to HideButton2 prototype"); |
| 46 |
|
| 47 |
// test prototype extension |
| 48 |
doh.t(mPrototypeExecuted, "m prototype executed"); |
| 49 |
|
| 50 |
// test parameters |
| 51 |
doh.is("blah", m1.foo, "m1.foo"); |
| 52 |
doh.is(73, m2.progress, "m2.progress"); |
| 53 |
|
| 54 |
// test <script type="dojo/connect"> |
| 55 |
doh.t(foo1, "foo1 exists"); |
| 56 |
doh.t(/modified by dojo\/connect event=startup/.test(foo1.domNode.innerHTML), "dojo/connect fired"); |
| 57 |
} |
| 58 |
]); |
| 59 |
|
| 60 |
doh.run(); |
| 61 |
}); |
| 62 |
</script> |
| 63 |
|
| 64 |
</head> |
| 65 |
<body class="claro"> |
| 66 |
<h3>Simple macro:</h3> |
| 67 |
<p>(Check to make sure that links contain employee number) |
| 68 |
<div dojoType="dijit.Declaration" widgetClass="Employee" defaults="{ empid: 123, name: '' }"> |
| 69 |
<span>${name}</span> |
| 70 |
<a href="update.php?id=${empid}">update</a> |
| 71 |
<a href="delete.php?id=${empid}">delete</a> |
| 72 |
</div> |
| 73 |
<div dojoType="Employee" empid="100" name="Alan Allen"></div> |
| 74 |
<div dojoType="Employee" empid="101" name="Bob Brown"></div> |
| 75 |
<div dojoType="Employee" empid="102" name="Cathy Cameron"></div> |
| 76 |
|
| 77 |
<h3>Using dojoAttachEvent, dojoAttachPoint</h3> |
| 78 |
<div dojoType="dijit.Declaration" widgetClass="HideButton"> |
| 79 |
XXX<button dojoAttachEvent="onclick: myHandler" dojoAttachPoint="containerNode"></button>XXX |
| 80 |
<script type='dojo/method' event='myHandler'> |
| 81 |
this.domNode.style.display="none"; |
| 82 |
</script> |
| 83 |
</div> |
| 84 |
<button dojoType="HideButton" jsId="hideButtonA">Click to hide</button> |
| 85 |
<button dojoType="HideButton" jsId="hideButtonB">Click to hide #2</button> |
| 86 |
|
| 87 |
<h3>Extending another widget</h3> |
| 88 |
<p>HideButton2 extends HideButton (above) and changes the template (but keeps the onclick handler).</p> |
| 89 |
<span dojoType="dijit.Declaration" widgetClass="HideButton2" mixins="HideButton"> |
| 90 |
YYY<button dojoAttachEvent="onclick: myHandler" dojoAttachPoint="containerNode"></button>YYY |
| 91 |
</span> |
| 92 |
<button dojoType="HideButton2" jsId="hideButton2A">Hide me extended</button> |
| 93 |
<button dojoType="HideButton2" jsId="hideButton2B">Hide me extended #2</button> |
| 94 |
|
| 95 |
<h3>Using dojo/method:</h3> |
| 96 |
<div dojoType="dijit.Declaration" widgetClass="m" defaults="{ foo: 'thud', progress: 10 }"> |
| 97 |
<script type='dojo/method' event='postCreate'> |
| 98 |
console.log("in postCreate ", this, arguments); |
| 99 |
mPrototypeExecuted = true; |
| 100 |
this.inherited(arguments); |
| 101 |
this.baz.innerHTML += " (created via custom postCreate) "; |
| 102 |
</script> |
| 103 |
|
| 104 |
<p>thinger blah stuff ${foo}</p> |
| 105 |
|
| 106 |
<div style="width:400px" maximum="200" |
| 107 |
progress="${progress}" dojoType="dijit.ProgressBar"></div> |
| 108 |
<p dojoAttachPoint='baz'>baz thud</p> |
| 109 |
</div> |
| 110 |
|
| 111 |
<div dojoType="m" jsId="m1" foo="blah" progress="50"></div> |
| 112 |
<div dojoType="m" jsId="m2" foo="thinger" progress="73"></div> |
| 113 |
|
| 114 |
<h3>Using dojo/connect:</h3> |
| 115 |
<div dojoType="dijit.Declaration" widgetClass="foo" defaults="{ foo: 'thud', progress: 10 }"> |
| 116 |
<script type='dojo/connect' event='startup'> |
| 117 |
this.baz.innerHTML += " (modified by dojo/connect event=startup) "; |
| 118 |
</script> |
| 119 |
|
| 120 |
<p>thinger blah stuff ${foo}</p> |
| 121 |
|
| 122 |
<div style="width:400px" maximum="200" |
| 123 |
progress="${progress}" dojoType="dijit.ProgressBar"></div> |
| 124 |
<p dojoAttachPoint='baz'>baz thud</p> |
| 125 |
</div> |
| 126 |
|
| 127 |
<div dojoType="foo" jsId="foo1" foo="blah" progress="50"></div> |
| 128 |
<div dojoType="foo" jsId="foo2" foo="thinger" progress="73"></div> |
| 129 |
|
| 130 |
</body> |
| 131 |
</html> |