-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetnamespaces.js
88 lines (80 loc) · 2.93 KB
/
getnamespaces.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var xhrq = new XMLHttpRequest;
function NamespaceLookup()
{
xhrq = new XMLHttpRequest;
var lang = document.forms[0].elements["lang"].value;
var family = document.forms[0].elements["family"].value;
if (family != "commons" && family != "meta" && lang == '') {
return false;
}
xmlurl = "getnamespaces.php?lang=" + lang + "&family=" + family
xhrq.open("GET", xmlurl, true);
try
{
xhrq.overrideMimeType('text/xml');
}
catch (e)
{
//xhrq.overridemimetype niet ondersteund
}
xhrq.onreadystatechange = NamespaceReadyStateChange;
xhrq.send(null);
}
function NamespaceReadyStateChange()
{
if (xhrq.readyState != 4){
return;
}
if (xhrq.status == 200) {
result = xhrq.responseXML;
// Get all the zip code tags returned from the request.
var els = result.getElementsByTagName("namespace");
var error = false;
//Clear select
document.forms[0].elements["namespaces"].options.length=0
// Add an option for all namespaces
var option = document.createElement("OPTION");
option.text = "All";
option.value = "-1";
try {
document.forms[0].elements["namespaces"].add(option, null);
} catch(ex) {
// For IE.
document.forms[0].elements["namespaces"].add(option);
}
// Add an option for the main namespace
var option = document.createElement("OPTION");
option.text = "Articles";
option.value = "0";
try {
document.forms[0].elements["namespaces"].add(option, null);
} catch(ex) {
// For IE.
document.forms[0].elements["namespaces"].add(option);
}
// Add an option to to the drop-down list for each zip code
// returned from the request.
for (var i = 0; i < els.length; i++) {
option = document.createElement("OPTION");
option.text = els[i].getAttribute('ns_name');
option.value = els[i].getAttribute('ns_id');
if (els[i].getAttribute('ns_name') == 'error') {
error = true;
}
try {
document.forms[0].elements["namespaces"].add(option, null);
} catch(ex) {
// For IE.
document.forms[0].elements["namespaces"].add(option);
}
}
// Show the drop down list and set focus on it.
if (error == false) {
document.getElementById("namespacesstatus").innerHTML = "";
document.forms[0].elements["namespaces"].style.visibility = "";
} else {
document.getElementById("namespacesstatus").innerHTML = "Could not lookup namespaces. Please check the selected project.";
document.forms[0].elements["namespaces"].style.visibility = "hidden";
}
}
}