forked from mnater/Hyphenator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modalLangDialog.html
66 lines (61 loc) · 2.15 KB
/
modalLangDialog.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Hyphenator.js: select language</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
'use strict';
function getUALang() {
var ul = window.navigator.language || window.navigator.userLanguage;
ul = ul.substring(0, 2);
return ul;
}
function getMsgText(lang) {
var text, supportedLangs = window.dialogArguments;
if (!!supportedLangs[lang] && supportedLangs[lang].prompt !== '') {
text = supportedLangs[lang].prompt;
} else {
text = supportedLangs.en.prompt;
}
return text;
}
function populate(el, ul) {
var supportedLangs = window.dialogArguments,
opEl,
lang;
for (lang in supportedLangs) {
if (supportedLangs.hasOwnProperty(lang)) {
opEl = window.document.createElement('option');
opEl.setAttribute('value', lang);
if (lang === ul) {
opEl.setAttribute('selected', 'selected');
}
opEl.appendChild(window.document.createTextNode(lang));
el.appendChild(opEl);
}
}
}
window.onload = function () {
var msgOut = window.document.getElementById('msg'),
lngOut = window.document.getElementById('langsel'),
goBtn = window.document.getElementById('go'),
ul = getUALang();
msgOut.appendChild(window.document.createTextNode(getMsgText(ul)));
populate(lngOut, ul);
goBtn.onclick = function () {
window.returnValue = lngOut.value;
window.close();
};
};
</script>
</head>
<body>
<h1>Hyphenator.js</h1>
<p id="msg"></p>
<form action="#">
<select id="langsel" size="1"></select>
<input type="submit" id="go" value="→">
</form>
</body>
</html>