2 function loadFile(url
, callback
) {
3 var xmlhttp
= new XMLHttpRequest();
4 xmlhttp
.onreadystatechange = function() {
5 if (xmlhttp
.readyState
== 4 && xmlhttp
.status
== 200) {
6 callback(xmlhttp
.responseText
, url
);
9 xmlhttp
.open('GET', url
, true);
13 function setupImageList(select
, items
, onselection
) {
17 function setupSelectList(select
, items
, onselection
) {
18 for (var i
= 0; i
< items
.length
; i
+= 1) {
19 var option
= document
.createElement("OPTION");
20 option
.innerHTML
= items
[i
];
21 select
.appendChild(option
);
24 select
.addEventListener("change", function(e
) {
25 onselection(items
[select
.selectedIndex
]);
28 if (select
.selectedIndex
>= 0) {
29 onselection(items
[select
.selectedIndex
]);
33 <div id="currentLanguages">
34 <span onclick="firmwarewizard.changeLanguage('en')">en</span> |
35 <span onclick="firmwarewizard.changeLanguage('de')">de</span> |
36 <span onclick="firmwarewizard.changeLanguage('pl')">pl</span>
40 // Change the translation of the entire document
41 function updateI18n() {
42 var mapping
= translations
[config
.language
];
43 for (var id
in mapping
) {
44 var elements
= document
.getElementsByClassName(id
);
45 for (var i
in elements
) {
46 if (elements
.hasOwnProperty(i
)) {
47 elements
[i
].innerHTML
= mapping
[id
];
53 function setupAutocompleteList(input
, items
, onselection
) {
54 // the setupAutocompleteList function takes two arguments,
55 // the text field element and an array of possible autocompleted values:
56 var currentFocus
= -1;
58 // execute a function when someone writes in the text field:
59 input
.addEventListener("input", function(e
) {
63 var value
= this.value
;
64 // close any already open lists of autocompleted values
66 if (!value
) { return false; }
68 // create a DIV element that will contain the items (values):
69 var list
= document
.createElement("DIV");
70 list
.setAttribute("id", this.id
+ "-autocomplete-list");
71 list
.setAttribute("class", "autocomplete-items");
72 // append the DIV element as a child of the autocomplete container:
73 this.parentNode
.appendChild(list
);
75 // for each item in the array...
77 for (var i
= 0; i
< items
.length
; i
+= 1) {
80 var j
= item
.toUpperCase().indexOf(value
.toUpperCase());
87 var div
= document
.createElement("DIV");
88 div
.innerHTML
= "...";
89 list
.appendChild(div
);
92 var div
= document
.createElement("DIV");
93 // make the matching letters bold:
94 div
.innerHTML
= item
.substr(0, j
)
95 + "<strong>" + item
.substr(j
, value
.length
) + "</strong>"
96 + item
.substr(j
+ value
.length
)
97 + "<input type='hidden' value='" + item
+ "'>";
99 div
.addEventListener("click", function(e
) {
100 // set text field to selected value
101 input
.value
= this.getElementsByTagName("input")[0].value
;
102 // close the list of autocompleted values,
103 // (or any other open lists of autocompleted values:
106 onselection(input
.value
);
109 list
.appendChild(div
);
114 // execute a function presses a key on the keyboard:
115 input
.addEventListener("keydown", function(e
) {
116 var x
= document
.getElementById(this.id
+ "-autocomplete-list");
117 if (x
) x
= x
.getElementsByTagName("div");
118 if (e
.keyCode
== 40) {
121 // and and make the current item more visible:
123 } else if (e
.keyCode
== 38) {
126 // and and make the current item more visible:
128 } else if (e
.keyCode
== 13) {
129 // If the ENTER key is pressed, prevent the form from being submitted,
131 if (currentFocus
> -1) {
132 // and simulate a click on the "active" item:
133 if (x
) x
[currentFocus
].click();
138 function setActive(x
) {
139 // a function to classify an item as "active":
140 if (!x
) return false;
141 // start by removing the "active" class on all items:
142 for (var i
= 0; i
< x
.length
; i
++) {
143 x
[i
].classList
.remove("autocomplete-active");
145 if (currentFocus
>= x
.length
) currentFocus
= 0;
146 if (currentFocus
< 0) currentFocus
= (x
.length
- 1);
147 // add class "autocomplete-active":
148 x
[currentFocus
].classList
.add("autocomplete-active");
151 function closeAllLists(elmnt
) {
152 // close all autocomplete lists in the document,
153 // except the one passed as an argument:
154 var x
= document
.getElementsByClassName("autocomplete-items");
155 for (var i
= 0; i
< x
.length
; i
++) {
156 if (elmnt
!= x
[i
] && elmnt
!= input
) {
157 x
[i
].parentNode
.removeChild(x
[i
]);
162 // execute a function when someone clicks in the document:
163 document
.addEventListener("click", function (e
) {
164 closeAllLists(e
.target
);
169 return document
.getElementById(id
);
172 function updateImages(target
, images
) {
173 if (target
&& images
) {
174 for(var i
in images
) {
175 var image
= images
[i
];
176 if (image
.type
== "sysupgrade") {
177 $("sysupgrade-image").href
= "https://" + target
+ "/" + image
.name
;
178 $("sysupgrade-image").style
.display
= "inline";
180 if (image
.type
== "factory") {
181 $("factory-image").href
= "https://" + target
+ "/" + image
.name
;
182 $("factory-image").style
.display
= "inline";
186 $("sysupgrade-image").style
.display
= "none";
187 $("factory-image").style
.display
= "none";
195 loadFile(config
.data
, function(data
) {
196 var obj
= JSON
.parse(data
);
197 setupSelectList($("releases"), Object
.keys(obj
), function(release
) {
198 setupAutocompleteList($("models"), Object
.keys(obj
[release
]), function(model
) {
199 console
.log("clicked " + model
);
200 var target
= obj
[release
][model
].target
;
201 var images
= obj
[release
][model
].images
202 updateImages(target
, images
);