diff --git a/src/index.html b/src/index.html index 3d95333..6f69aba 100644 --- a/src/index.html +++ b/src/index.html @@ -10,7 +10,7 @@ Public APIs
- +

Public APIs

@@ -51,8 +51,5 @@ - diff --git a/src/scripts.js b/src/scripts.js index a9e143b..cc79944 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -1,5 +1,52 @@ - loadJSON(function(response) { - var items = JSON.parse(response); + function loadJSON(callback) { + var xobj = new XMLHttpRequest(); + xobj.overrideMimeType("application/json"); + xobj.open('GET', 'https://raw.githubusercontent.com/toddmotto/public-apis/master/json/entries.min.json', true); // Replace 'my_data' with the path to your file + xobj.onreadystatechange = function () { + if (xobj.readyState == 4 && xobj.status == "200") { + // Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode + callback(xobj.responseText); + } + }; + xobj.send(null); + } + +function filterRows() { + + var input, filter, table, tr, td, i; + + input = document.getElementById("searchbox"); + filter = input.value.toUpperCase(); + table = document.getElementById("entries"); + tr = table.getElementsByTagName("tr"); + + // Loop through all table rows and hide those who don't match the search + for (i = 0; i < tr.length; i++) { + + displayRows = false; + + title = tr[i].getElementsByTagName("td")[0]; + if (title) { + if (title.innerHTML.toUpperCase().indexOf(filter) > -1) { + displayRows = true; + } + } + section = tr[i].getElementsByTagName("td")[4]; + if (section) { + if (section.innerHTML.toUpperCase().indexOf(filter) > -1) { + displayRows = true; + } + } + if (displayRows) { + tr[i].style.display = ""; + } else { + tr[i].style.display = "none"; + } + } +} + +loadJSON(function(response) { + var items = JSON.parse(response); new Vue({ data: { filter: '' @@ -19,7 +66,7 @@ methods: { filtered(item) { let show = true; - + if(this.filter.length) { show = false; @@ -38,50 +85,8 @@ }); } - return show; } } }).$mount('#app'); }); - -function loadJSON(callback) { - var xobj = new XMLHttpRequest(); - xobj.overrideMimeType("application/json"); - xobj.open('GET', 'https://raw.githubusercontent.com/toddmotto/public-apis/master/json/entries.min.json', true); // Replace 'my_data' with the path to your file - xobj.onreadystatechange = function () { - if (xobj.readyState == 4 && xobj.status == "200") { - // Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode - callback(xobj.responseText); - } - }; - xobj.send(null); - } - -function filterRows() { - var input, filter, table, tr, td, i; - input = document.getElementById("searchbox"); - filter = input.value.toUpperCase(); - table = document.getElementById("entries"); - tr = table.getElementsByTagName("tr"); - - // Loop through all table rows and hide those who don't match the search - for (i = 0; i < tr.length; i++) { - title = tr[i].getElementsByTagName("td")[0]; - section = tr[i].getElementsByTagName("td")[4]; - if (title) { - if (title.innerHTML.toUpperCase().indexOf(filter) > -1) { - tr[i].style.display = ""; - } else { - tr[i].style.display = "none"; - } - } - if (section) { - if (section.innerHTML.toUpperCase().indexOf(filter) > -1) { - tr[i].style.display = ""; - } else { - tr[i].style.display = "none"; - } - } - } -} \ No newline at end of file diff --git a/src/styles.css b/src/styles.css index 37d6612..09c9574 100644 --- a/src/styles.css +++ b/src/styles.css @@ -19,10 +19,10 @@ body { } #entries { - border-collapse: collapse; /* Collapse borders */ - border: 1px solid #ddd; /* Add a grey border */ - font-size: 18px; /* Increase font-size */ - width: 100%; /* Full-width */ + border-collapse: collapse; + border: 1px solid #ddd; + font-size: 18px; + width: 100%; } #entries th { @@ -38,11 +38,11 @@ body { } #searchbox { - border: 1px solid #ddd; /* Add a grey border */ + border: 1px solid #ddd; border-radius: 50px; - margin-bottom: 12px; /* Add some space below the input */ - font-size: 16px; /* Increase font-size */ - padding: 12px 20px 12px 40px; /* Add some padding */ + margin-bottom: 12px; + font-size: 16px; + padding: 12px 20px 12px 40px; text-align: center; - width: 50%; /* Full-width */ + width: 50%; } \ No newline at end of file