diff --git a/zephyr/static/js/composebox_typeahead.js b/zephyr/static/js/composebox_typeahead.js index 56b33873e5..176a81251a 100644 --- a/zephyr/static/js/composebox_typeahead.js +++ b/zephyr/static/js/composebox_typeahead.js @@ -13,16 +13,6 @@ var composebox_typeahead = (function () { var exports = {}; -var autocomplete_needs_update = false; - -exports.autocomplete_needs_update = function (needs_update) { - if (needs_update === undefined) { - return autocomplete_needs_update; - } else { - autocomplete_needs_update = needs_update; - } -}; - var private_message_typeahead_list = []; var private_message_mapped = {}; @@ -30,14 +20,7 @@ function render_pm_object(person) { return person.full_name + " <" + person.email + ">"; } -exports.update_autocomplete = function () { - stream_list.sort(); - people_list.sort(function (x, y) { - if (x.email === y.email) return 0; - if (x.email < y.email) return -1; - return 1; - }); - +exports.update_typeahead = function() { private_message_mapped = {}; private_message_typeahead_list = []; $.each(people_list, function (i, obj) { @@ -45,8 +28,6 @@ exports.update_autocomplete = function () { private_message_mapped[label] = obj; private_message_typeahead_list.push(label); }); - - autocomplete_needs_update = false; }; function get_pm_recipients(query_string) { @@ -200,7 +181,7 @@ exports.initialize = function () { $(this).val(recipients.join(", ")); }); - composebox_typeahead.update_autocomplete(); + typeahead_helper.update_autocomplete(); }; return exports; diff --git a/zephyr/static/js/subs.js b/zephyr/static/js/subs.js index 19fc56629e..d47cf3b20b 100644 --- a/zephyr/static/js/subs.js +++ b/zephyr/static/js/subs.js @@ -142,7 +142,7 @@ exports.unsubscribe = function (stream) { ajaxSubscribe(name); }); remove_from_stream_list(name); - composebox_typeahead.update_autocomplete(); + typeahead_helper.update_autocomplete(); $("#streams").focus(); }, error: function (xhr) { diff --git a/zephyr/static/js/typeahead_helper.js b/zephyr/static/js/typeahead_helper.js index d71914623e..27301a79b1 100644 --- a/zephyr/static/js/typeahead_helper.js +++ b/zephyr/static/js/typeahead_helper.js @@ -2,6 +2,28 @@ var typeahead_helper = (function () { var exports = {}; +var autocomplete_needs_update = false; +exports.autocomplete_needs_update = function (needs_update) { + if (needs_update === undefined) { + return autocomplete_needs_update; + } else { + autocomplete_needs_update = needs_update; + } +}; + +exports.update_autocomplete = function () { + stream_list.sort(); + people_list.sort(function (x, y) { + if (x.email === y.email) return 0; + if (x.email < y.email) return -1; + return 1; + }); + + composebox_typeahead.update_typeahead(); + autocomplete_needs_update = false; +}; + + // Loosely based on Bootstrap's default highlighter, but with escaping added. exports.highlight_with_escaping = function (query, item) { // query: The text currently in the searchbox diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 95f45b48f2..774bf5a81b 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -434,7 +434,7 @@ function add_message_metadata(dummy, message) { if (! Object.prototype.hasOwnProperty.call(people_set, person.email)) { people_set[person.email] = true; people_list.push(person); - composebox_typeahead.autocomplete_needs_update(true); + typeahead_helper.autocomplete_needs_update(true); } }); @@ -496,8 +496,8 @@ function add_messages(messages, where, add_to_home) { {then_scroll: true, update_server: false}); } - if (composebox_typeahead.autocomplete_needs_update()) { - composebox_typeahead.update_autocomplete(); + if (typeahead_helper.autocomplete_needs_update()) { + typeahead_helper.update_autocomplete(); } }