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 () {
|
2017-06-02 23:00:17 +02:00
|
|
|
i18n.ensure_i18n(admin.show_or_hide_menu_item);
|
2014-03-13 21:55:47 +01:00
|
|
|
|
|
|
|
$('#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');
|
2017-03-10 23:48:51 +01:00
|
|
|
scroll_positions[old_tab] = message_viewport.scrollTop();
|
2014-03-13 21:55:47 +01:00
|
|
|
});
|
|
|
|
$('#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
|
2017-03-23 20:37:08 +01:00
|
|
|
$('.alert').removeClass("show");
|
2014-03-13 21:55:47 +01:00
|
|
|
|
|
|
|
// 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.)
|
2017-05-17 05:36:58 +02:00
|
|
|
if (target_tab === '#home') {
|
|
|
|
if (scroll_positions.hasOwnProperty(target_tab)) {
|
|
|
|
message_viewport.scrollTop(scroll_positions[target_tab]);
|
2014-03-13 21:55:47 +01:00
|
|
|
} else {
|
2017-05-17 05:36:58 +02:00
|
|
|
navigate.scroll_to_selected();
|
2014-03-13 21:55:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// The admin and settings pages are generated client-side through
|
|
|
|
// templates.
|
2015-09-20 07:47:43 +02:00
|
|
|
};
|
2014-03-13 21:55:47 +01:00
|
|
|
|
2017-03-18 20:30:20 +01:00
|
|
|
exports.open = function () {
|
|
|
|
$("#settings-dropdown").click();
|
2017-05-22 04:29:24 +02:00
|
|
|
// there are invisible li tabs, which should not be clicked.
|
2017-03-18 20:30:20 +01:00
|
|
|
$("#gear-menu").find("li:not(.invisible) a").eq(0).focus();
|
|
|
|
};
|
|
|
|
|
2017-05-22 04:28:52 +02:00
|
|
|
exports.is_open = function () {
|
|
|
|
return $(".dropdown").hasClass("open");
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.close = function () {
|
|
|
|
if (exports.is_open()) {
|
|
|
|
$(".dropdown").removeClass("open");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-13 21:55:47 +01:00
|
|
|
return exports;
|
|
|
|
}());
|
2016-12-04 08:59:56 +01:00
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = gear_menu;
|
|
|
|
}
|