Updated
This commit is contained in:
270
master/examples/SimpleTree.html
Normal file
270
master/examples/SimpleTree.html
Normal file
@@ -0,0 +1,270 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>dijit.Tree</title>
|
||||
<script type="text/javascript" src="../../../../dojo/dojo.js"
|
||||
data-dojo-config="parseOnLoad: true, isDebug: true">
|
||||
</script>
|
||||
<style type="text/css">
|
||||
body, html { font-family:helvetica,arial,sans-serif; font-size:90%; }
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
dojo.require("doh.runner");
|
||||
dojo.require("dojo.parser");
|
||||
dojo.require("dijit.dijit"); // optimize: load dijit layer
|
||||
|
||||
dojo.require("dojo.data.ItemFileReadStore");
|
||||
dojo.require("dijit.Tree");
|
||||
|
||||
dojo.require("dijit._BidiSupport");
|
||||
|
||||
dojo.addOnLoad(function(){
|
||||
doh.register("parse", function(){
|
||||
dojo.parser.parse();
|
||||
});
|
||||
|
||||
var treeRtl, treeLtr, treeAuto, buttonLtr, buttonRtl, buttonAuto;
|
||||
|
||||
function expandNode(tree, node){
|
||||
var d = new doh.Deferred();
|
||||
|
||||
if(!node.isExpandable){
|
||||
return;
|
||||
}
|
||||
if(!node.isExpanded){
|
||||
tree._onExpandoClick({node: node});
|
||||
}
|
||||
//node.expand();
|
||||
setTimeout(d.getTestCallback(function(){
|
||||
dojo.forEach(node.getChildren(), function(child){expandNode(tree,child)});
|
||||
}), 100);
|
||||
return d;
|
||||
};
|
||||
function expandAll(tree){
|
||||
expandNode(tree,tree.rootNode);
|
||||
};
|
||||
|
||||
|
||||
function testNodeAuto(node,textDir){
|
||||
|
||||
doh.is(node.tree._checkContextual(node.label), node.labelNode.dir, "direction of " + node.tree.id +" : rootNode");
|
||||
|
||||
if(!node.item.children){
|
||||
return;
|
||||
}
|
||||
dojo.forEach(node.getChildren(), function(childNode){
|
||||
//doh.is(textDir, childNode.labelNode.dir, "direction of " + childNode.tree.id + " element: " + i);
|
||||
testNodeAuto(childNode,textDir);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
function testNode(node,textDir){
|
||||
|
||||
doh.is(textDir, node.labelNode.dir, "direction of " + node.tree.id +" : rootNode");
|
||||
|
||||
if(!node.item.children){
|
||||
return;
|
||||
}
|
||||
dojo.forEach(node.getChildren(), function(childNode){
|
||||
//doh.is(textDir, childNode.labelNode.dir, "direction of " + childNode.tree.id + " element: " + i);
|
||||
testNode(childNode,textDir);
|
||||
});
|
||||
|
||||
};
|
||||
function expandedNodesTextDirTest(tree, textDir){
|
||||
|
||||
textDir == "auto" ? testNodeAuto(tree.rootNode, textDir) : testNode(tree.rootNode, textDir);
|
||||
|
||||
};
|
||||
|
||||
doh.register("paths", [
|
||||
{
|
||||
name: "initial dirs",
|
||||
|
||||
setUp: function(){
|
||||
treeRtl = dijit.byId("treeRtl");
|
||||
treeLtr = dijit.byId("treeLtr");
|
||||
treeAuto = dijit.byId("treeAuto");
|
||||
},
|
||||
|
||||
runTest: function(){
|
||||
var d = new doh.Deferred();
|
||||
|
||||
setTimeout(d.getTestCallback(function(){
|
||||
doh.is("rtl", treeRtl.rootNode.labelNode.dir, "direction of treeRtl: rootNode");
|
||||
doh.is("ltr", treeLtr.rootNode.labelNode.dir, "direction of treeLtr: rootNode");
|
||||
doh.is("ltr", treeAuto.rootNode.labelNode.dir, "direction of treeAuto: rootNode");
|
||||
var rtlChildren = treeRtl.rootNode.getChildren(), ltrChildren = treeLtr.rootNode.getChildren(),
|
||||
autoChildren = treeAuto.rootNode.getChildren();
|
||||
for(var i = 0 ; i < rtlChildren.length ; i++){
|
||||
doh.is("rtl", rtlChildren[i].labelNode.dir, "direction of treeRtl element: " + i);
|
||||
doh.is("ltr", ltrChildren[i].labelNode.dir, "direction of treeLtr element: " + i);
|
||||
doh.is(treeAuto._checkContextual(autoChildren[i].label), autoChildren[i].labelNode.dir, "direction of treeAuto element: " + autoChildren[i].label);
|
||||
};
|
||||
}), 100);
|
||||
|
||||
return d;
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "expanded RTL",
|
||||
|
||||
runTest: function(){
|
||||
var d = expandAll(treeRtl);
|
||||
|
||||
expandedNodesTextDirTest(treeRtl, "rtl");
|
||||
|
||||
return d;
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "expanded LTR",
|
||||
|
||||
runTest: function(){
|
||||
var d = expandAll(treeLtr);
|
||||
|
||||
expandedNodesTextDirTest(treeLtr, "ltr");
|
||||
|
||||
return d;
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "expanded AUTO",
|
||||
|
||||
runTest: function(){
|
||||
var d = expandAll(treeAuto);
|
||||
|
||||
expandedNodesTextDirTest(treeAuto, "auto");
|
||||
|
||||
return d;
|
||||
|
||||
}
|
||||
}
|
||||
]);
|
||||
doh.register("Dynamic change textDir", [
|
||||
{
|
||||
name: 'check "set("textDir", textDir)" function',
|
||||
|
||||
setUp: function(){
|
||||
treeRtl = dijit.byId("treeRtl");
|
||||
treeLtr = dijit.byId("treeLtr");
|
||||
treeAuto = dijit.byId("treeAuto");
|
||||
buttonLtr = dojo.byId("buttonLtr");
|
||||
buttonRtl = dojo.byId("buttonRtl");
|
||||
buttonAuto = dojo.byId("buttonAuto");
|
||||
|
||||
},
|
||||
|
||||
runTest: function(){
|
||||
|
||||
dijit.byId("treeRtl").set("textDir", "ltr");
|
||||
|
||||
expandedNodesTextDirTest(treeRtl, "ltr");
|
||||
|
||||
expandedNodesTextDirTest(treeAuto, "auto");
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'set using the buttons: LTR',
|
||||
|
||||
runTest: function(){
|
||||
|
||||
buttonLtr.click();
|
||||
|
||||
expandedNodesTextDirTest(treeRtl, "ltr");
|
||||
|
||||
expandedNodesTextDirTest(treeLtr, "ltr");
|
||||
|
||||
expandedNodesTextDirTest(treeAuto, "ltr");
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'set using the buttons: RTL',
|
||||
|
||||
runTest: function(){
|
||||
|
||||
buttonRtl.click();
|
||||
|
||||
expandedNodesTextDirTest(treeRtl, "rtl");
|
||||
|
||||
expandedNodesTextDirTest(treeLtr, "rtl");
|
||||
|
||||
expandedNodesTextDirTest(treeAuto, "rtl");
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'set using the buttons: AUTO',
|
||||
|
||||
runTest: function(){
|
||||
|
||||
buttonAuto.click();
|
||||
|
||||
expandedNodesTextDirTest(treeRtl, "auto");
|
||||
|
||||
expandedNodesTextDirTest(treeLtr, "auto");
|
||||
|
||||
expandedNodesTextDirTest(treeAuto, "auto");
|
||||
}
|
||||
}
|
||||
]);
|
||||
doh.run();
|
||||
});
|
||||
|
||||
</script>
|
||||
<link id="themeStyles" rel="stylesheet" href="../../../../dijit/themes/claro/claro.css"/>
|
||||
|
||||
</head>
|
||||
<body class=" claro ">
|
||||
<div data-dojo-type="dojo.data.ItemFileReadStore" data-dojo-id="continentStore" data-dojo-props='url:"../../../../dijit/tests/_BidiSupport/_data/countriesHeb.json"'>
|
||||
</div>
|
||||
<div data-dojo-id="continentModel" data-dojo-type="dijit.tree.ForestStoreModel" data-dojo-props='store:continentStore, query:{type:"continent"},
|
||||
rootId:"continentRoot", rootLabel:"Continents!", childrenAttrs:["children"]'></div>
|
||||
|
||||
<table>
|
||||
<tr><td>
|
||||
<label for="treeAuto" >
|
||||
<b> I'm a Contextual Tree </b>
|
||||
</label>
|
||||
<div data-dojo-type="dijit.Tree" id="treeAuto" data-dojo-props='model:continentModel, openOnClick:true, textDir:"auto"'>
|
||||
</div>
|
||||
</td>
|
||||
<td></td><td></td><td></td><td></td><td></td><td></td><td></td>
|
||||
<td>
|
||||
<label for="treeLtr" >
|
||||
<b> I'm a LTR Tree </b>
|
||||
</label>
|
||||
<div data-dojo-type="dijit.Tree" id="treeLtr" data-dojo-props='model:continentModel, openOnClick:true, textDir:"ltr"'>
|
||||
</div>
|
||||
</td>
|
||||
<td></td><td></td><td></td><td></td><td></td><td></td><td></td>
|
||||
<td>
|
||||
<label for="treeRtl" >
|
||||
<b> I'm a RTL Tree </b>
|
||||
</label>
|
||||
<div data-dojo-type="dijit.Tree" id="treeRtl" data-dojo-props='model:continentModel, openOnClick:true, textDir:"rtl"'>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<input id= "buttonRtl" type="button" value="RTL"
|
||||
onclick="dijit.byId('treeAuto').set('textDir','rtl');
|
||||
dijit.byId('treeLtr').set('textDir','rtl');
|
||||
dijit.byId('treeRtl').set('textDir','rtl');"
|
||||
/>
|
||||
<input id= "buttonLtr" type="button" value="LTR"
|
||||
onclick="dijit.byId('treeAuto').set('textDir','ltr');
|
||||
dijit.byId('treeLtr').set('textDir','ltr');
|
||||
dijit.byId('treeRtl').set('textDir','ltr');"
|
||||
/>
|
||||
<input id= "buttonAuto" type="button" value="AUTO"
|
||||
onclick="dijit.byId('treeAuto').set('textDir','auto');
|
||||
dijit.byId('treeLtr').set('textDir','auto');
|
||||
dijit.byId('treeRtl').set('textDir','auto');"
|
||||
/>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user