diff options
-rw-r--r-- | web/nms.gathering.org/index.html | 2 | ||||
-rw-r--r-- | web/nms.gathering.org/js/nms-info-box.js | 15 |
2 files changed, 14 insertions, 3 deletions
diff --git a/web/nms.gathering.org/index.html b/web/nms.gathering.org/index.html index bdb5912..db1acfa 100644 --- a/web/nms.gathering.org/index.html +++ b/web/nms.gathering.org/index.html @@ -92,7 +92,7 @@ <div class="input-group input-group-sm"> <input id="searchbox" type="text" class="form-control" placeholder="Filter" oninput="nmsInfoBox._search()" /> <span class="input-group-btn"> - <button class="btn btn-default" type="button" onclick="nmsInfoBox.show(document.getElementById('searchbox').value);">Go!</button> + <button id="searchbox-submit" class="btn btn-default" type="button" onclick="nmsInfoBox.showWindow('switchInfo',document.getElementById('searchbox').value);">Go!</button> </span> </div> </div> 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); + } } |