diff --git a/base.css b/base.css index 7df658addcf4a79b55844596d62d596188f0ea18..5174b6824f9ad836ce6118dd1aaccb1c8f43fd4b 100644 --- a/base.css +++ b/base.css @@ -59,6 +59,11 @@ a:active { text-decoration: none; } -figure a{ +figure a { + display: block; +} + +#loadmore { + text-align: center; display: block; } \ No newline at end of file diff --git a/index.html b/index.html index efff4b4d826835c0d50c8858490780bdbb9e3abc..0f1f62795bed5a5a8eaea98db6ecb94aefa6afc3 100644 --- a/index.html +++ b/index.html @@ -35,8 +35,11 @@ -
+
+
+ +
+
+ 加载更多 +
diff --git a/index.js b/index.js index aaa24d31a357187e672dad2a40703a60b514ed66..941ad60d05c454a6b3979f87402ee4cbf4edad5c 100644 --- a/index.js +++ b/index.js @@ -13,16 +13,20 @@ function getUrlVars() { function processJson(data) { machineList = data; - machineList = splitArrayByTime(machineList); + reorderedList = splitArrayByTime(machineList); var i, j, temparray, chunk = 32; - for (i = 0, j = machineList.length; i < j; i += chunk) { - temparray = machineList.slice(i, i + chunk); + for (i = 0, j = reorderedList.length; i < j; i += chunk) { + temparray = reorderedList.slice(i, i + chunk); pages.push(temparray); } showMachines(pages[loadedPage]); } +function loadmore() { + showMachines(pages[loadedPage]); +} + function showMachines(machines) { var base = $("#base-cell"); var machineListContainer = $("#machine-list"); @@ -44,11 +48,37 @@ function showMachines(machines) { clone.show(); clone.attr("id", machine.id); clone.find("a").attr("href", playerlink); - clone.find("figcaption").text(title) - clone.find(".figure-img").attr("src", imageLink) + clone.find("figcaption").text(title); + clone.find(".figure-img").attr("src", imageLink); + clone.addClass("show-data"); machineListContainer.append(clone); } loadedPage++; + if (loadedPage >= pages.length) { + $("#loadmore").hide(); + } +} + +function search() { + + var keyword = $("#search-text").val(); + if (!keyword || keyword.length == 0) { + $(".show-data").remove(); + loadedPage = 0; + processJson(machineList); + return; + } + var searchResult = []; + for (i = 0; i < machineList.length; i++) { + var text = machineList[i].name + machineList[i].vendor; + if (text.includes(keyword)) { + searchResult.push(machineList[i]); + } + } + pages = []; + loadedPage = 0; + $(".show-data").remove(); + showMachines(searchResult); } function splitArrayByTime(someArray) {