Commits

Andreas Wagner  committed cbc2e1a Draft

Minor simplifications to substring-search code.

  • Participants
  • Parent commits 15ab918

Comments (0)

Files changed (2)

File demos/ajax-bulk.html

 
 	map.addLayer(new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'));	//base layer
 
-	map.addControl( new L.Control.Search({ url: 'search.php?cities=1&q={s}', text:'City name...', markerLocation: true, initial: false }) );
+	map.addControl( new L.Control.Search({ url: 'search.php?cities=1&q={s}', text:'City name...', markerLocation: true }) );
 
 </script>
 

File leaflet-search.js

 		{
 			tip = L.DomUtil.create('a', '');
 			tip.href = '#';
-			var record_prefix = text.substring(0,text.toUpperCase().indexOf(this._input.value.toUpperCase()));
-			var record_suffix = text.substring(this._input.value.length + record_prefix.length, text.length);
-			var record_substring = text.substring(record_prefix.length, this._input.value.length + record_prefix.length);
+			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;
 		}
 		
 		
 		var start = this._input.value.length,
 			firstRecord = this._tooltip.firstChild._text,
-			end = firstRecord.length,
-			originalText = this._input.value;
+			end = firstRecord.length;
 
-		if (firstRecord.indexOf(originalText) === 0) { // If prefix match
+		if (firstRecord.indexOf(this._input.value) == 0) { // If prefix match
 			this._input.value = firstRecord;
 			this._handleAutoresize();