-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
62 lines (48 loc) · 1.47 KB
/
main.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
// (function() {
// select function
var select = document.querySelector('select');
var qframe = document.querySelector('.quick-frame');
var qexpand = document.querySelector('.quick-expand');
var form = document.querySelector('.tabs form');
window.onload = addToSelect();
form.addEventListener('submit', function (e) {
e.preventDefault();
var newObj = {};
var filled = form.elements;
for(var i = 1;i <= 3;i++){
if(filled['qtitle' + i].value&&filled['qurl' + i].value){
newObj[filled['qtitle' + i].value] = filled['qurl' + i].value;
}
}
saveOnLocalstorage(newObj);
});
function saveOnLocalstorage(obj){
localStorage.clear();
localStorage.setItem('reports', JSON.stringify(obj));
addToSelect();
}
function addToSelect(){
if(select.length >= 0){
for(var j = 0;j < select.length;j++){
select.remove(j);
}
}
var newList = JSON.parse(localStorage.getItem('reports'));
for(key in newList) {
var opt = document.createElement("option");
opt.value = newList[key];
opt.text = key;
select.add(opt, null);
displayIframe();
//don't forget the _blank
}
}
function displayIframe(){
if(select.selectedIndex > -1){qframe.src =select.options[0].value;}
}
select.addEventListener('change', function (e) {
var newReport = e.target.value;
qframe.src = newReport;
qexpand.href = newReport;
});
// })();//end