2014-03-13 21:55:47 +01:00
|
|
|
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 = {};
|
|
|
|
|
2015-09-20 07:47:43 +02:00
|
|
|
exports.initialize = function () {
|
2014-03-13 21:55:47 +01:00
|
|
|
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') {
|
2016-05-25 13:26:57 +02:00
|
|
|
navigate.scroll_to_selected();
|
2014-03-13 21:55:47 +01:00
|
|
|
} 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) {
|
2016-10-12 08:53:57 +02:00
|
|
|
$('#create_or_filter_stream_row input[type="text"]').focus().select();
|
2014-03-13 21:55:47 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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);
|
2015-09-20 07:47:43 +02:00
|
|
|
};
|
2014-03-13 21:55:47 +01:00
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|