From 35be5a88ac39cc948df8fe2114aabfb9ccfa366a Mon Sep 17 00:00:00 2001 From: Shubham Dhama Date: Fri, 22 Jun 2018 15:29:47 +0530 Subject: [PATCH] search: Remove redundant re-declaration of variables for search box. This is just a minor refactor. --- static/js/search.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/static/js/search.js b/static/js/search.js index fcb3fa297a..7e94f213d4 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -42,6 +42,8 @@ exports.update_button_visibility = function () { }; exports.initialize = function () { + var search_query_box = $('#search_query'); + var searchbox_form = $('#searchbox_form'); // Data storage for the typeahead. // This maps a search string to an object with a "description" field. @@ -50,7 +52,7 @@ exports.initialize = function () { // just represents the key of the hash, so it's redundant.) var search_object = {}; - $("#search_query").typeahead({ + search_query_box.typeahead({ source: function (query) { var suggestions = search_suggestion.get_suggestions(query); // Update our global search_object hash @@ -74,7 +76,7 @@ exports.initialize = function () { }, }); - $('#searchbox_form').on('compositionend', function () { + searchbox_form.on('compositionend', function () { // Set `is_using_input_method` to true if enter is pressed to exit // the input tool popover and get the text in the search bar. Then // we suppress searching triggered by this enter key by checking @@ -83,10 +85,9 @@ exports.initialize = function () { is_using_input_method = true; }); - $("#searchbox_form").keydown(function (e) { + searchbox_form.keydown(function (e) { exports.update_button_visibility(); var code = e.which; - var search_query_box = $("#search_query"); if (code === 13 && search_query_box.is(":focus")) { // Don't submit the form so that the typeahead can instead // handle our Enter keypress. Any searching that needs @@ -100,7 +101,6 @@ exports.initialize = function () { return; } var code = e.which; - var search_query_box = $("#search_query"); if (code === 13 && search_query_box.is(":focus")) { // We just pressed enter and the box had focus, which // means we didn't use the typeahead at all. In that @@ -119,9 +119,8 @@ exports.initialize = function () { // more work to re-order everything and make them private. $('#search_exit').on('click', exports.clear_search); - var query = $('#search_query'); - query.on('focus', exports.focus_search); - query.on('blur' , function () { + search_query_box.on('focus', exports.focus_search); + search_query_box.on('blur' , function () { // The search query box is a visual cue as to // whether search or narrowing is active. If // the user blurs the search box, then we should @@ -139,7 +138,7 @@ exports.initialize = function () { setTimeout(function () { var search_string = narrow_state.search_string(); - query.val(search_string); + search_query_box.val(search_string); exports.update_button_visibility(); }, 100); });