| 1 |
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" > |
| 2 |
<head> |
| 3 |
<title>Testing surface.destroy()</title> |
| 4 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 5 |
<style type="text/css"> |
| 6 |
@import "../../../dojo/resources/dojo.css"; |
| 7 |
@import "../../../dijit/tests/css/dijitTests.css"; |
| 8 |
</style> |
| 9 |
<script type="text/javascript" src="../../../dojo/dojo.js" data-dojo-config="isDebug: true"></script> |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
<script type="text/javascript"> |
| 17 |
dojo.require("dojox.gfx"); |
| 18 |
dojo.require("dojox.gfx.registry"); |
| 19 |
|
| 20 |
surface = null; |
| 21 |
|
| 22 |
createSurface = function(){ |
| 23 |
surface = dojox.gfx.createSurface("test", 500, 500); |
| 24 |
surface.whenLoaded(makeShapes); |
| 25 |
}; |
| 26 |
|
| 27 |
makeShapes = function(){ |
| 28 |
var path = surface.createPath(""); |
| 29 |
|
| 30 |
// form concentric circles |
| 31 |
var center = {x: 250, y: 250}; |
| 32 |
for(var r = 200; r > 0; r -= 30){ |
| 33 |
// make two 180 degree arcs to form a circle |
| 34 |
var start = {x: center.x, y: center.y - r}; |
| 35 |
var end = {x: center.x, y: center.y + r}; |
| 36 |
path.moveTo(start).arcTo(r, r, 0, true, true, end).arcTo(r, r, 0, true, true, start).closePath(); |
| 37 |
} |
| 38 |
// set visual attributes |
| 39 |
path.setFill("red").setStroke("black"); |
| 40 |
}; |
| 41 |
|
| 42 |
cleanUp = function(){ |
| 43 |
if(surface){ |
| 44 |
var id = surface.children[0].getUID(); |
| 45 |
surface.destroy(); |
| 46 |
surface = null; |
| 47 |
var t = dojo.byId("test").innerHTML; |
| 48 |
if(t){ |
| 49 |
console.error("Garbage detected: " + t); |
| 50 |
return; |
| 51 |
} |
| 52 |
if (dojox.gfx.shape.byId(id)){ |
| 53 |
console.log("Shape not disposed."); |
| 54 |
return; |
| 55 |
} |
| 56 |
console.log("The parent node was cleaned up properly."); |
| 57 |
} |
| 58 |
createSurface(); |
| 59 |
} |
| 60 |
|
| 61 |
dojo.addOnLoad(createSurface); |
| 62 |
</script> |
| 63 |
</head> |
| 64 |
<body> |
| 65 |
<h1>Testing surface.destroy()</h1> |
| 66 |
<p><button onclick="cleanUp();">Regenerate</button></p> |
| 67 |
<p><em>See the firebug log for detailed reports.</em></p> |
| 68 |
<div id="test" style="width: 500px; height: 500px;"></div> |
| 69 |
<p>That's all Folks!</p> |
| 70 |
</body> |
| 71 |
</html> |