-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs_fvk.js
105 lines (91 loc) · 2.69 KB
/
js_fvk.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//script for fvk.html
//easy tool
var $= function(el){
if(el[0]=="#"){
return document.querySelector(el);
}else{
return document.querySelectorAll(el)
}
};
var ajax= function( method, url, body, callback ){
if (body=='undefined') body=null;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if ( xhr.readyState == 4 ) {
if (xhr.status == 200 ) {
callback(xhr.responseText)
console.log(xhr.responseText)
}else{
console.log('there get data from ' + url + ' fialed ')
}
}
};
xhr.open( method, url, true );
xhr.send( body )
};
//start
window.onload=function(){
function hiddenAll(){
Array.prototype.forEach.call( $('.router'),function(item,index,array){
item.style.display= 'none' });
console.log("hiddenAll!!")
};
//add listen on hashchange
window.onhashchange=function(event){
hiddenAll();
var hash= window.location.hash;
var sections=hash.split('/');
//add index when use a second class router
// if( sections[0]=='#section_b' && sections[1]==undefined ){ sections= ['#section_b','section_b_a'] };
//mark the entery button with the id what you want to show
sections.forEach(function(item,index,array){
if(item[0]!='#'){ item= '#'+item };
if( $(item) ){ $(item).style.display= 'block' }
})
};
//router inital when loaded page;
var h = window.location.hash;
if(h==""){
window.location.hash = "#section_a" //the default show;
}else{
window.location.hash = "";//the browser will consider that no change happen when hash string is equal;
window.location.hash = h //emitte hashchanged event
};
//scetion_a part
//model_aa
var model_aa_input=$('#model_aa').children[1],
model_aa_screen=$('#model_aa').children[2];
model_aa_input.addEventListener('keyup',function(){
model_aa_screen.innerText= this.value
});
//model_ab
var model_ab_input_a= $('#model_ab').children[1],
model_ab_input_b= $('#model_ab').children[2],
model_ab_screen= $('#model_ab').children[3];
function model_ab_plus(){
var reslut= parseInt(model_ab_input_b.value)+ parseInt( model_ab_input_a.value);
model_ab_screen.innerText= reslut;
};
model_ab_input_a.addEventListener( 'change',function(){
model_ab_plus()
});
model_ab_input_b.addEventListener( 'change',function(){
model_ab_plus()
})
//model_ab inital
model_ab_plus();
//section_b part
//section_b_a
//add listener
var model_b_a_button= $('#model_b_a').children[0],
model_b_a_screen= $('#model_b_a').children[2],
model_b_a_clear= $('#model_b_a').children[1];
model_b_a_button.onclick= function(){
ajax('get','./data.txt',undefined,function(r){
model_b_a_screen.innerText=r;
})
};
model_b_a_clear.onclick= function(){
model_b_a_screen.innerText=null;
}
}