2150 |
mathias |
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
|
|
2 |
"http://www.w3.org/TR/html4/strict.dtd">
|
|
|
3 |
<html>
|
|
|
4 |
<head>
|
|
|
5 |
<title>Dijit I18N Demo</title>
|
|
|
6 |
|
|
|
7 |
<script>
|
|
|
8 |
var djConfig = {parseOnLoad: true, isDebug: true},
|
|
|
9 |
locale,
|
|
|
10 |
lang,
|
|
|
11 |
bidi;
|
|
|
12 |
|
|
|
13 |
// read in HREF arguments
|
|
|
14 |
if(window.location.href.indexOf("?") > -1){
|
|
|
15 |
var str = window.location.href.substr(window.location.href.indexOf("?")+1);
|
|
|
16 |
var ary = str.split(/&/);
|
|
|
17 |
for(var i=0; i<ary.length; i++){
|
|
|
18 |
var split = ary[i].split(/=/),
|
|
|
19 |
key = split[0],
|
|
|
20 |
value = split[1];
|
|
|
21 |
switch(key){
|
|
|
22 |
case "locale":
|
|
|
23 |
djConfig.locale = locale = value;
|
|
|
24 |
lang = locale.replace(/-.*/, "");
|
|
|
25 |
break;
|
|
|
26 |
case "dir":
|
|
|
27 |
document.getElementsByTagName("html")[0].dir = value;
|
|
|
28 |
bidi = value;
|
|
|
29 |
break;
|
|
|
30 |
}
|
|
|
31 |
}
|
|
|
32 |
}
|
|
|
33 |
</script>
|
|
|
34 |
<style type="text/css">
|
|
|
35 |
@import "../../dojo/resources/dojo.css";
|
|
|
36 |
@import "../themes/tundra/tundra.css";
|
|
|
37 |
@import "../themes/tundra/tundra_rtl.css";
|
|
|
38 |
@import "../tests/css/dijitTests.css";
|
|
|
39 |
@import "i18n/flags.css";
|
|
|
40 |
</style>
|
|
|
41 |
|
|
|
42 |
<script type="text/javascript" src="../../dojo/dojo.js"></script>
|
|
|
43 |
|
|
|
44 |
<script language="JavaScript" type="text/javascript">
|
|
|
45 |
dojo.require("dojo.data.ItemFileReadStore");
|
|
|
46 |
dojo.require("dijit.Tree");
|
|
|
47 |
dojo.require("dijit._Calendar");
|
|
|
48 |
dojo.require("dijit.form.DateTextBox");
|
|
|
49 |
dojo.require("dijit.form.CurrencyTextBox");
|
|
|
50 |
dojo.require("dijit.form.NumberSpinner");
|
|
|
51 |
dojo.require("dijit.form.ComboBox");
|
|
|
52 |
dojo.require("dijit.Menu");
|
|
|
53 |
dojo.require("dojo.parser");
|
|
|
54 |
dojo.addOnLoad(function(){
|
|
|
55 |
dojo.byId("locale").innerHTML = locale || "default";
|
|
|
56 |
dojo.byId("dir").innerHTML = bidi || "default";
|
|
|
57 |
});
|
|
|
58 |
</script>
|
|
|
59 |
|
|
|
60 |
</head>
|
|
|
61 |
<body class="tundra">
|
|
|
62 |
<div dojoType="dojo.data.ItemFileReadStore" jsId="store"
|
|
|
63 |
url="i18n/data.json"></div>
|
|
|
64 |
|
|
|
65 |
<h1 class="testTitle" dir="ltr">Dijit I18N Demo (locale=<span id="locale"></span> dir=<span id="dir"></span>)</h1>
|
|
|
66 |
|
|
|
67 |
<table width="100%">
|
|
|
68 |
<tr>
|
|
|
69 |
<td width="30%" style="vertical-align: top;">
|
|
|
70 |
<div dojoType="dijit.Tree" id="mytree" store="store" label="Continents" childrenAttr="languages">
|
|
|
71 |
<!-- Override all the data access functions to work from the I18N data store -->
|
|
|
72 |
<script type="dojo/method" event="getItemChildren" args="item, onComplete">
|
|
|
73 |
switch(item ? store.getValue(item, "type") : "top"){
|
|
|
74 |
case "top":
|
|
|
75 |
return store.fetch({query: {type:'continent'}, onComplete: onComplete});
|
|
|
76 |
case "continent":
|
|
|
77 |
return store.fetch({query: {continent: store.getValue(item, "iso")}, onComplete: onComplete});
|
|
|
78 |
case "country":
|
|
|
79 |
return dijit.Tree.prototype.getItemChildren.apply(this, arguments);
|
|
|
80 |
}
|
|
|
81 |
</script>
|
|
|
82 |
<script type="dojo/method" event="mayHaveChildren" args="item">
|
|
|
83 |
if(!item){ return true; } // top level
|
|
|
84 |
var type = store.getValue(item, "type");
|
|
|
85 |
return (type == "continent" || type == "country");
|
|
|
86 |
</script>
|
|
|
87 |
|
|
|
88 |
<!-- override functions for display of each node -->
|
|
|
89 |
<script type="dojo/method" event="getIconClass" args="item">
|
|
|
90 |
var icon =
|
|
|
91 |
(item && store.getValue(item, "type") == "country") ?
|
|
|
92 |
("countryIcon country" + store.getValue(item, "iso") + "Icon") :
|
|
|
93 |
null;
|
|
|
94 |
return icon;
|
|
|
95 |
</script>
|
|
|
96 |
<script type="dojo/method" event="getLabel" args="item">
|
|
|
97 |
var localizedName = lang && store.getValue(item, lang);
|
|
|
98 |
return localizedName || (store.getLabel(item) + " \u202b" + "(" + store.getIdentity(item) + ")\u202c");
|
|
|
99 |
</script>
|
|
|
100 |
|
|
|
101 |
<!-- clicking a node refreshes the page with new locale setting -->
|
|
|
102 |
<script type="dojo/method" event="onClick" args="item, node">
|
|
|
103 |
var type = store.getValue(item, "type");
|
|
|
104 |
if(type == "language"){
|
|
|
105 |
var lang = store.getIdentity(item),
|
|
|
106 |
locale = lang + "-" + store.getIdentity(node.getParent().item).toLowerCase(),
|
|
|
107 |
dir = /ar|fa|he|ps|ur|yi/i.test(lang) ? "rtl" : "ltr";
|
|
|
108 |
window.location.href = window.location.href.replace(/\?.*/, "") + "?locale=" + locale + "&dir=" + dir;
|
|
|
109 |
}else{
|
|
|
110 |
alert("Please click a language, not a country or continent.");
|
|
|
111 |
}
|
|
|
112 |
</script>
|
|
|
113 |
</div>
|
|
|
114 |
</td>
|
|
|
115 |
<td style="vertical-align: top;">
|
|
|
116 |
<p dir="ltr">
|
|
|
117 |
Use the tree to select a language or a language/country combo; the page will reload
|
|
|
118 |
in the specified locale. Note that tree is also rerendered using the specified language for top level tree items.
|
|
|
119 |
Arabic and Hebrew display right-to-left so be sure to try those.
|
|
|
120 |
</p>
|
|
|
121 |
<input dojoType="dijit._Calendar"/>
|
|
|
122 |
|
|
|
123 |
<p>Some form controls:</p>
|
|
|
124 |
|
|
|
125 |
<label for="date">Date:</label>
|
|
|
126 |
<input id="date" dojoType="dijit.form.DateTextBox" value="2006-07-04"/>
|
|
|
127 |
<br/>
|
|
|
128 |
<label for="spinner">Number spinner:</label>
|
|
|
129 |
<input id="spinner" dojoType="dijit.form.NumberSpinner" value="123456789"/>
|
|
|
130 |
<br/>
|
|
|
131 |
<label for="currency">Currency:</label>
|
|
|
132 |
<input id="currency" type="text" name="income1" value="54775.53"
|
|
|
133 |
dojoType="dijit.form.CurrencyTextBox"
|
|
|
134 |
required="true"
|
|
|
135 |
constraints="{fractional:true}"
|
|
|
136 |
currency="USD"/>
|
|
|
137 |
<br/>
|
|
|
138 |
|
|
|
139 |
<label for="combo1">Simple Combo:</label>
|
|
|
140 |
<select id="combo1" dojoType="dijit.form.ComboBox">
|
|
|
141 |
<option>option #1</option>
|
|
|
142 |
<option>option #2</option>
|
|
|
143 |
<option>option #3</option>
|
|
|
144 |
</select>
|
|
|
145 |
<br/>
|
|
|
146 |
<label for="combo2">Combo on languages and countries:</label>
|
|
|
147 |
<input id="combo2" dojoType="dijit.form.ComboBox"
|
|
|
148 |
value=""
|
|
|
149 |
store="store"
|
|
|
150 |
searchAttr="name"
|
|
|
151 |
name="anything"/>
|
|
|
152 |
</td>
|
|
|
153 |
</tr>
|
|
|
154 |
</table>
|
|
|
155 |
</body>
|
|
|
156 |
</html>
|