From 321c2df67e77395a36acd61d60e9fb3c7a2cdaa0 Mon Sep 17 00:00:00 2001 From: Jessica McKellar Date: Fri, 5 Oct 2012 17:39:13 -0400 Subject: [PATCH] Autocomplete on each recipient when composing a huddle. (imported from commit 0a95f431d960f8a39544d4598fd859a8090fbfa3) --- zephyr/static/js/ui.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/zephyr/static/js/ui.js b/zephyr/static/js/ui.js index 973a28e3b9..00a5b62539 100644 --- a/zephyr/static/js/ui.js +++ b/zephyr/static/js/ui.js @@ -91,7 +91,24 @@ function update_autocomplete() { }); $( "#recipient" ).typeahead({ source: people_list, - items: 4 + items: 4, + matcher: function (item) { + // Assumes we are matching on email addresses, not + // e.g. full names which would have spaces. + var current_recipient = $(this.query.split(" ")).last()[0]; + // Case-insensitive (from Bootstrap's default matcher). + return (item.toLowerCase().indexOf(current_recipient.toLowerCase()) !== -1); + }, + updater: function (item) { + var previous_recipients = this.query.split(" "); + previous_recipients.pop(); + previous_recipients = previous_recipients.join(" "); + if (previous_recipients.length !== 0) { + previous_recipients += " "; + } + return previous_recipients + item; + } + }); autocomplete_needs_update = false;