diff options
author | Nicolai Tellefsen <niccofyren@gmail.com> | 2016-03-20 23:53:39 +0100 |
---|---|---|
committer | Nicolai Tellefsen <niccofyren@gmail.com> | 2016-03-20 23:53:39 +0100 |
commit | e763a7874093d7c36b89424b116dd99fc2966312 (patch) | |
tree | 1b1ec8ebad82ff4486e57175ccd312673d364cbb /web/nms.gathering.org/js/nms-info-box.js | |
parent | 925af79d0cceb61755a0846f78fa46fbf0012406 (diff) |
NMS: Enable search GO-button
Diffstat (limited to 'web/nms.gathering.org/js/nms-info-box.js')
-rw-r--r-- | web/nms.gathering.org/js/nms-info-box.js | 15 |
1 files changed, 13 insertions, 2 deletions
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); + } } |