1
- function loadJSON ( callback ) {
2
- var xobj = new XMLHttpRequest ( ) ;
3
- xobj . overrideMimeType ( "application/json" ) ;
4
- xobj . open ( 'GET' , 'https://raw.githubusercontent.com/toddmotto/public-apis/master/json/entries.min.json' , true ) ;
5
- xobj . onreadystatechange = function ( ) {
6
- if ( xobj . readyState == 4 && xobj . status == "200" ) {
7
- // Required use of an anonymous callback as .open will NOT return a value
8
- // but simply returns undefined in asynchronous mode
9
- callback ( xobj . responseText ) ;
10
- }
11
- } ;
12
- xobj . send ( null ) ;
13
- }
14
-
15
- function filterRows ( ) {
16
-
17
- var input , filter , table , tr , td , i ;
18
-
19
- input = document . getElementById ( "searchbox" ) ;
20
- filter = input . value . toUpperCase ( ) ;
21
- table = document . getElementById ( "entries" ) ;
22
- tr = table . getElementsByTagName ( "tr" ) ;
23
-
24
- // Loop through all table rows and hide those who don't match the search
25
- for ( i = 0 ; i < tr . length ; i ++ ) {
26
-
27
- displayRows = false ;
28
-
29
- title = tr [ i ] . getElementsByTagName ( "td" ) [ 0 ] ;
30
- if ( title ) {
31
- if ( title . innerHTML . toUpperCase ( ) . indexOf ( filter ) > - 1 ) {
32
- displayRows = true ;
33
- }
34
- }
35
- section = tr [ i ] . getElementsByTagName ( "td" ) [ 4 ] ;
36
- if ( section ) {
37
- if ( section . innerHTML . toUpperCase ( ) . indexOf ( filter ) > - 1 ) {
38
- displayRows = true ;
39
- }
40
- }
41
- if ( displayRows ) {
42
- tr [ i ] . style . display = "" ;
43
- } else {
44
- tr [ i ] . style . display = "none" ;
45
- }
46
- }
47
- }
48
-
49
- loadJSON ( function ( response ) {
50
- var items = JSON . parse ( response ) ;
1
+ loadJSON ( function ( response ) {
2
+ var items = JSON . parse ( response ) ;
51
3
new Vue ( {
52
4
data : {
53
5
filter : ''
54
6
} ,
55
7
computed : {
56
8
data ( ) {
57
- let output = [ ] ;
58
- for ( var category in items ) {
59
- for ( var api in items [ category ] ) {
60
- items [ category ] [ api ] . Category = category ;
61
- output . push ( items [ category ] [ api ] ) ;
62
- }
63
- }
64
- return output ;
9
+ return items . entries ;
65
10
}
66
11
} ,
67
12
methods : {
68
13
filtered ( item ) {
69
14
let show = true ;
70
-
15
+
71
16
if ( this . filter . length ) {
72
17
73
18
show = false ;
@@ -91,3 +36,37 @@ loadJSON(function(response) {
91
36
}
92
37
} ) . $mount ( '#app' ) ;
93
38
} ) ;
39
+
40
+ function loadJSON ( callback ) {
41
+ var xobj = new XMLHttpRequest ( ) ;
42
+ xobj . overrideMimeType ( "application/json" ) ;
43
+ xobj . open ( 'GET' , 'https://raw.githubusercontent.com/toddmotto/public-apis/master/json/entries.min.json' , true ) ;
44
+ xobj . onreadystatechange = function ( ) {
45
+ if ( xobj . readyState == 4 && xobj . status == "200" ) {
46
+ // Required use of an anonymous callback as .open will NOT return a value
47
+ // but simply returns undefined in asynchronous mode
48
+ callback ( xobj . responseText ) ;
49
+ }
50
+ } ;
51
+ xobj . send ( null ) ;
52
+ }
53
+
54
+ function filterRows ( ) {
55
+ var input , filter , table , tr , td , i ;
56
+ input = document . getElementById ( "searchbox" ) ;
57
+ filter = input . value . toUpperCase ( ) ;
58
+ table = document . getElementById ( "entries" ) ;
59
+ tr = table . getElementsByTagName ( "tr" ) ;
60
+
61
+ // Loop through all table rows and hide those who don't match the search
62
+ for ( i = 0 ; i < tr . length ; i ++ ) {
63
+ td = tr [ i ] . getElementsByTagName ( "td" ) [ 0 ] ;
64
+ if ( td ) {
65
+ if ( td . innerHTML . toUpperCase ( ) . indexOf ( filter ) > - 1 ) {
66
+ tr [ i ] . style . display = "" ;
67
+ } else {
68
+ tr [ i ] . style . display = "none" ;
69
+ }
70
+ }
71
+ }
72
+ }
0 commit comments