Commits

stefano cudini  committed 0c9431f Draft

support node or string returning by callTip option

  • Participants
  • Parent commits 52f5652

Comments (0)

Files changed (3)

File demos/custom-tip.html

 	var markersLayer = new L.LayerGroup();	//layer contain searched elements
 	map.addLayer(markersLayer);
 	
-	function customTip(text,val)
-	{
-		var tip = L.DomUtil.create('a', 'colortip');
-
-		tip.href = "#"+text;
-		tip.innerHTML = text;
-
-		var colortip = L.DomUtil.create('em', 'subtip', tip);
-		colortip.style.display = 'inline-block';
-		colortip.style.float = 'right';
-		colortip.style.width = '14px';
-		colortip.style.height = '14px';
-		colortip.style.backgroundColor = text;
-		
-		return tip;
+	function customTip(text,val) {
+		return '<a href="#">'+text+'<em style="background:'+text+'; width:14px;height:14px;float:right"></em></a>';
 	}
 
 	map.addControl( new L.Control.Search({layer: markersLayer, callTip: customTip, autoType: false }) );  //inizialize search control

File demos/tests.html

 	var markersLayer = new L.LayerGroup();	//layer contain searched elements
 	map.addLayer(markersLayer);
 
-	function customTip(text,val)
-	{
-		var tip = L.DomUtil.create('a', 'colortip');
-
-		tip.href = "#"+text;
-		tip.innerHTML = text;
-
-		var colortip = L.DomUtil.create('em', 'subtip', tip);
-		colortip.style.display = 'inline-block';
-		colortip.style.float = 'right';
-		colortip.style.width = '14px';
-		colortip.style.height = '14px';
-		colortip.style.backgroundColor = text;
-				
-		return tip;
+	function customTip(text,val) {
+		return '<a href="#">'+text+'<em style="background:'+text+'; width:14px;height:14px;float:right"></em></a>';
 	}
 
 	map.addControl( new L.Control.Search({layer: markersLayer, callTip: customTip, autoType: false }) );  //inizialize search control

File leaflet-search.js

 		propertyName: 'title',		//property in marker.options(or feature.properties for vector layer) trough filter elements in layer
 		propertyLoc: 'loc',			//field name for remapping location, using array: ['latname','lonname'] for select double fields(ex. ['lat','lon'] )
 		//TODO implement sub property filter for propertyName,propertyLoc like this:  "prop.subprop.title"
-		callTip: null,				//function that return row tip html node, receive text tooltip in first param
+		callTip: null,				//function that return row tip html node(or html string), receive text tooltip in first param
 		filterJSON: null,			//callback for filtering data to _recordsCache
 		minLength: 1,				//minimal text length for autocomplete
 		initial: true,				//search elements only by initial text
 		var tip;
 		
 		if(this.options.callTip)
-			tip = this.options.callTip(text,val); //custom tip content
+		{
+			tip = this.options.callTip(text,val); //custom tip node or html string
+			if(typeof tip === 'string')
+			{
+				var tmpNode = L.DomUtil.create('div');
+				tmpNode.innerHTML = tip;
+				tip = tmpNode.firstChild;
+			}
+		}
 		else
 		{
 			tip = L.DomUtil.create('a', '');