Commits

Andreas Wagner committed b7dc0eb Draft Merge
  • Participants
  • Parent commits 2e42445, cbc2e1a

Comments (0)

Files changed (3)

demos/simple.html

 	var markersLayer = new L.LayerGroup();	//layer contain searched elements
 	map.addLayer(markersLayer);
 
-	map.addControl( new L.Control.Search({layer: markersLayer}) );  //inizialize search control
+	map.addControl( new L.Control.Search({layer: markersLayer, initial: false}) );  //inizialize search control
 
 	////////////populate map with markers from sample data
 	for(i in data) {

leaflet-search.css

 	font-size:.85em;
 	vertical-align:center;
 }
+.leaflet-control-search .search-tip .substring {
+	font-weight:900;
+}
 .leaflet-control-search .search-tip-select,
 .leaflet-control-search .search-tip:hover,
 .leaflet-control-search .search-button:hover {

leaflet-search.js

 		{
 			tip = L.DomUtil.create('a', '');
 			tip.href = '#';
-			tip.innerHTML = text;
+			var record_prefix = text.substring(0,text.toUpperCase().indexOf(this._input.value.toUpperCase())),
+				record_suffix = text.substring(this._input.value.length + record_prefix.length, text.length),
+				record_substring = text.substring(record_prefix.length, this._input.value.length + record_prefix.length);
+			tip.innerHTML = record_prefix + '<span class=substring>' + record_substring + '<\/span>' + record_suffix;
 		}
 		
 		L.DomUtil.addClass(tip, 'search-tip');
 		var start = this._input.value.length,
 			firstRecord = this._tooltip.firstChild._text,
 			end = firstRecord.length;
-			
-		this._input.value = firstRecord;
-		this._handleAutoresize();
-		
-		if (this._input.createTextRange) {
-			var selRange = this._input.createTextRange();
-			selRange.collapse(true);
-			selRange.moveStart('character', start);
-			selRange.moveEnd('character', end);
-			selRange.select();
-		}
-		else if(this._input.setSelectionRange) {
-			this._input.setSelectionRange(start, end);
-		}
-		else if(this._input.selectionStart) {
-			this._input.selectionStart = start;
-			this._input.selectionEnd = end;
+
+		if (firstRecord.indexOf(this._input.value) == 0) { // If prefix match
+			this._input.value = firstRecord;
+			this._handleAutoresize();
+
+			if (this._input.createTextRange) {
+				var selRange = this._input.createTextRange();
+				selRange.collapse(true);
+				selRange.moveStart('character', start);
+				selRange.moveEnd('character', end);
+				selRange.select();
+			}
+			else if(this._input.setSelectionRange) {
+				this._input.setSelectionRange(start, end);
+			}
+			else if(this._input.selectionStart) {
+				this._input.selectionStart = start;
+				this._input.selectionEnd = end;
+			}
 		}
 	},