From e763a7874093d7c36b89424b116dd99fc2966312 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Sun, 20 Mar 2016 23:53:39 +0100 Subject: NMS: Enable search GO-button --- web/nms.gathering.org/js/nms-info-box.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 49825bc..d484cc8 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -425,7 +425,7 @@ nmsInfoBox._searchSmart = function(id, sw) { nmsInfoBox._search = function() { var el = document.getElementById("searchbox"); var id = false; - var hits = 0; + var matches = []; if (el) { id = el.value; } @@ -433,13 +433,14 @@ nmsInfoBox._search = function() { for(var sw in nmsData.switches.switches) { if (id[0] == "/") { if (nmsInfoBox._searchSmart(id.slice(1),sw)) { + matches.push(sw); nmsMap.setSwitchHighlight(sw,true); } else { nmsMap.setSwitchHighlight(sw,false); } } else { if(sw.indexOf(id) > -1) { - hits++; + matches.push(sw); nmsMap.setSwitchHighlight(sw,true); } else { nmsMap.setSwitchHighlight(sw,false); @@ -449,6 +450,16 @@ nmsInfoBox._search = function() { } else { nmsMap.removeAllSwitchHighlights(); } + if(matches.length == 1) { + document.getElementById("searchbox-submit").classList.add("btn-primary"); + document.getElementById("searchbox").addEventListener("keydown",function(e) { + if(e.keyCode == 13) + nmsInfoBox.showWindow("switchInfo",matches[0]); + }); + } else { + document.getElementById("searchbox-submit").classList.remove("btn-primary"); + document.getElementById("searchbox").removeEventListener("keydown",false); + } } -- cgit v1.2.3 From 3d840d42ab7a05059b457fd5ffb22b6c3beea8a6 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Mon, 21 Mar 2016 00:26:14 +0100 Subject: NMS: Improve search GO-button event listener --- web/nms.gathering.org/js/nms-info-box.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index d484cc8..88bc7d7 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -452,13 +452,19 @@ nmsInfoBox._search = function() { } if(matches.length == 1) { document.getElementById("searchbox-submit").classList.add("btn-primary"); - document.getElementById("searchbox").addEventListener("keydown",function(e) { - if(e.keyCode == 13) - nmsInfoBox.showWindow("switchInfo",matches[0]); - }); + document.getElementById("searchbox").dataset.match = matches[0]; + document.getElementById("searchbox").addEventListener("keydown",nmsInfoBox._searchKeyListener,false); } else { document.getElementById("searchbox-submit").classList.remove("btn-primary"); - document.getElementById("searchbox").removeEventListener("keydown",false); + document.getElementById("searchbox").dataset.match = ''; + document.getElementById("searchbox").removeEventListener("keydown",nmsInfoBox._searchKeyListener,false); + } +} + +nmsInfoBox._searchKeyListener = function(e) { + if(e.keyCode == 13) { + var sw = document.getElementById("searchbox").dataset.match; + nmsInfoBox.showWindow("switchInfo",sw); } } -- cgit v1.2.3