diff --git a/static/js/gear_menu.js b/static/js/gear_menu.js new file mode 100644 index 0000000000..a4b0f3eb95 --- /dev/null +++ b/static/js/gear_menu.js @@ -0,0 +1,73 @@ +var gear_menu = (function () { + +var exports = {}; + +// We want to remember how far we were scrolled on each 'tab'. +// To do so, we need to save away the old position of the +// scrollbar when we switch to a new tab (and restore it +// when we switch back.) +var scroll_positions = {}; + +$(function () { + admin.show_or_hide_menu_item(); + + $('#gear-menu a[data-toggle="tab"]').on('show', function (e) { + // Save the position of our old tab away, before we switch + var old_tab = $(e.relatedTarget).attr('href'); + scroll_positions[old_tab] = viewport.scrollTop(); + }); + $('#gear-menu a[data-toggle="tab"]').on('shown', function (e) { + var target_tab = $(e.target).attr('href'); + resize.resize_bottom_whitespace(); + // Hide all our error messages when switching tabs + $('.alert-error').hide(); + $('.alert-success').hide(); + $('.alert-info').hide(); + $('.alert').hide(); + + // Set the URL bar title to show the sub-page you're currently on. + var browser_url = target_tab; + if (browser_url === "#home") { + browser_url = ""; + } + hashchange.changehash(browser_url); + + // After we show the new tab, restore its old scroll position + // (we apparently have to do this after setting the hash, + // because otherwise that action may scroll us somewhere.) + if (scroll_positions.hasOwnProperty(target_tab)) { + viewport.scrollTop(scroll_positions[target_tab]); + } else { + if (target_tab === '#home') { + scroll_to_selected(); + } else { + viewport.scrollTop(0); + } + } + }); + + var subs_link = $('#gear-menu a[href="#subscriptions"]'); + + // If the streams page is shown by clicking directly on the "Streams" + // link (in the gear menu), then focus the new stream textbox. + subs_link.on('click', function (e) { + $(document).one('subs_page_loaded.zulip', function (e) { + $('#create_stream_name').focus().select(); + }); + }); + + // Whenever the streams page comes up (from anywhere), populate it. + subs_link.on('shown', subs.setup_page); + + // The admin and settings pages are generated client-side through + // templates. + + var admin_link = $('#gear-menu a[href="#administration"]'); + admin_link.on('shown', admin.setup_page); + + var settings_link = $('#gear-menu a[href="#settings"]'); + settings_link.on('shown', settings.setup_page); +}); + +return exports; +}()); diff --git a/static/js/ui.js b/static/js/ui.js index fded9e87b6..f1e651ed37 100644 --- a/static/js/ui.js +++ b/static/js/ui.js @@ -19,12 +19,6 @@ exports.home_tab_obscured = function () { return false; }; -// We want to remember how far we were scrolled on each 'tab'. -// To do so, we need to save away the old position of the -// scrollbar when we switch to a new tab (and restore it -// when we switch back.) -var scroll_positions = {}; - exports.change_tab_to = function (tabname) { $('#gear-menu a[href="' + tabname + '"]').tab('show'); }; @@ -528,65 +522,6 @@ $(function () { e.preventDefault(); }); - admin.show_or_hide_menu_item(); - - $('#gear-menu a[data-toggle="tab"]').on('show', function (e) { - // Save the position of our old tab away, before we switch - var old_tab = $(e.relatedTarget).attr('href'); - scroll_positions[old_tab] = viewport.scrollTop(); - }); - $('#gear-menu a[data-toggle="tab"]').on('shown', function (e) { - var target_tab = $(e.target).attr('href'); - resize.resize_bottom_whitespace(); - // Hide all our error messages when switching tabs - $('.alert-error').hide(); - $('.alert-success').hide(); - $('.alert-info').hide(); - $('.alert').hide(); - - // Set the URL bar title to show the sub-page you're currently on. - var browser_url = target_tab; - if (browser_url === "#home") { - browser_url = ""; - } - hashchange.changehash(browser_url); - - // After we show the new tab, restore its old scroll position - // (we apparently have to do this after setting the hash, - // because otherwise that action may scroll us somewhere.) - if (scroll_positions.hasOwnProperty(target_tab)) { - viewport.scrollTop(scroll_positions[target_tab]); - } else { - if (target_tab === '#home') { - scroll_to_selected(); - } else { - viewport.scrollTop(0); - } - } - }); - - var subs_link = $('#gear-menu a[href="#subscriptions"]'); - - // If the streams page is shown by clicking directly on the "Streams" - // link (in the gear menu), then focus the new stream textbox. - subs_link.on('click', function (e) { - $(document).one('subs_page_loaded.zulip', function (e) { - $('#create_stream_name').focus().select(); - }); - }); - - // Whenever the streams page comes up (from anywhere), populate it. - subs_link.on('shown', subs.setup_page); - - // The admin and settings pages are generated client-side through - // templates. - - var admin_link = $('#gear-menu a[href="#administration"]'); - admin_link.on('shown', admin.setup_page); - - var settings_link = $('#gear-menu a[href="#settings"]'); - settings_link.on('shown', settings.setup_page); - // A little hackish, because it doesn't seem to totally get us the // exact right width for the floating_recipient_bar and compose // box, but, close enough for now. diff --git a/tools/jslint/check-all.js b/tools/jslint/check-all.js index 91c265f5fb..7cdebc8cbe 100644 --- a/tools/jslint/check-all.js +++ b/tools/jslint/check-all.js @@ -27,7 +27,7 @@ var globals = + ' invite ui util activity timerender MessageList MessageListView blueslip unread stream_list' + ' message_edit tab_bar emoji popovers navigate people settings alert_words_ui message_store' + ' avatar feature_flags search_suggestion referral stream_color Dict' - + ' Filter summary admin stream_data muting WinChan muting_ui Socket channel' + + ' Filter summary admin stream_data muting WinChan muting_ui Socket channel gear_menu' + ' message_flags bot_data loading favicon resize scroll_bar condense floating_recipient_bar' // colorspace.js diff --git a/zproject/settings.py b/zproject/settings.py index 710bd2061d..34a6a948b6 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -547,6 +547,7 @@ JS_SPECS = { 'js/floating_recipient_bar.js', 'js/ui.js', 'js/scroll_bar.js', + 'js/gear_menu.js', 'js/popovers.js', 'js/typeahead_helper.js', 'js/search_suggestion.js',