1
- function add_version_dropdown ( json_loc , target_loc , text ) {
1
+ function assign_href ( a ) {
2
+ var http = new XMLHttpRequest ( ) ;
3
+ http . open ( 'GET' , url + "/" + path ) ;
4
+ http . onreadystatechange = function ( ) {
5
+ console . log ( '%%%%' , this ) ;
6
+ if ( this . readyState == this . DONE ) {
7
+ if ( this . status != 404 ) {
8
+ a . href = url + "/" + path ;
9
+ }
10
+ else {
11
+ a . href = url ;
12
+ }
13
+ }
14
+ } ;
15
+ http . send ( ) ;
16
+ }
2
17
18
+ function add_version_dropdown ( json_loc , target_loc , text ) {
3
19
var dropdown = document . createElement ( "div" ) ;
4
20
dropdown . className = "md-flex__cell md-flex__cell--shrink dropdown" ;
5
21
var button = document . createElement ( "button" ) ;
@@ -21,21 +37,7 @@ function add_version_dropdown(json_loc, target_loc, text) {
21
37
var a = document . createElement ( "a" ) ;
22
38
a . innerHTML = key ;
23
39
a . title = key ;
24
- var url = target_loc + versions [ key ] ;
25
- var http = new XMLHttpRequest ( ) ;
26
- http . open ( 'GET' , url + "/" + path ) ;
27
- http . onreadystatechange = function ( ) {
28
- console . log ( '%%%%' , this ) ;
29
- if ( this . readyState == this . DONE ) {
30
- if ( this . status != 404 ) {
31
- a . href = url + "/" + path ;
32
- }
33
- else {
34
- a . href = url ;
35
- }
36
- }
37
- } ;
38
- http . send ( ) ;
40
+ assign_href ( a ) ;
39
41
content . appendChild ( a ) ;
40
42
}
41
43
}
0 commit comments