diff options
| -rw-r--r-- | web/nms.gathering.org/index.html | 2 | ||||
| -rw-r--r-- | web/nms.gathering.org/js/nms-info-box.js | 21 | 
2 files changed, 20 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..88bc7d7 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,22 @@ nmsInfoBox._search = function() {  	} else {  		nmsMap.removeAllSwitchHighlights();  	} +	if(matches.length == 1) { +		document.getElementById("searchbox-submit").classList.add("btn-primary"); +		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").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); +	}  } | 
