From 32481b8f9b35ea0013d645f60aaa6cea7d085601 Mon Sep 17 00:00:00 2001 From: davemachado Date: Wed, 16 Aug 2017 23:27:09 -0400 Subject: [PATCH] use stock JSON entries field for data --- src/index.html | 4 +-- src/scripts.js | 97 ++++++++++++++++++++------------------------------ 2 files changed, 40 insertions(+), 61 deletions(-) diff --git a/src/index.html b/src/index.html index 6f69aba..546b930 100644 --- a/src/index.html +++ b/src/index.html @@ -32,7 +32,7 @@ API Description - Authorization + Auth HTTPS Category @@ -43,7 +43,7 @@ {{ item.Description }} {{ (item.Auth) ? item.Auth : '-' }} {{ (item.HTTPS) ? '✔' : '✖' }} - {{ item.Section }} + {{ item.Category }} diff --git a/src/scripts.js b/src/scripts.js index d971da1..91d71bc 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -1,73 +1,18 @@ - 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); - 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); + loadJSON(function(response) { + var items = JSON.parse(response); new Vue({ data: { filter: '' }, computed: { data() { - let output = []; - for (var category in items) { - for (var api in items[category]) { - items[category][api].Category = category; - output.push(items[category][api]); - } - } - return output; + return items.entries; } }, methods: { filtered(item) { let show = true; - + if(this.filter.length) { show = false; @@ -91,3 +36,37 @@ loadJSON(function(response) { } }).$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); + 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++) { + td = tr[i].getElementsByTagName("td")[0]; + if (td) { + if (td.innerHTML.toUpperCase().indexOf(filter) > -1) { + tr[i].style.display = ""; + } else { + tr[i].style.display = "none"; + } + } + } +} \ No newline at end of file