Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
Added emphasis to matching item(s) in picklist
Browse files Browse the repository at this point in the history
  • Loading branch information
jbate committed Sep 15, 2015
1 parent d29efe8 commit a588c5e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/js/contact-data-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,23 @@ var contactDataServices = {
// Create a new picklist item/row
createListItem: function(item){
var row = document.createElement("div");
row.innerHTML = item.suggestion;
row.innerHTML = contactDataServices.address.picklist.addMatchingEmphasis(item);
// Store the Format URL
row.setAttribute("format", item.format);
return row;
},
// Add emphasis to the picklist items highlighting the match
addMatchingEmphasis: function(item){
var highlights = item.emphasis || [],
label = item.suggestion;

for (i = 0; i < highlights.length; i++) {
var replacement = '<b>' + label.substring(highlights[i][0], highlights[i][1]) + '</b>';
label = label.substring(0, highlights[i][0]) + replacement + label.substring(highlights[i][1]);
}

return label;
},
listen: function(row){
row.addEventListener("click", contactDataServices.address.picklist.pick);
},
Expand Down

0 comments on commit a588c5e

Please sign in to comment.