2013-05-03 00:29:52 +02:00
|
|
|
var settings = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
2013-06-14 20:03:54 +02:00
|
|
|
|
2017-03-01 01:31:33 +01:00
|
|
|
$("body").ready(function () {
|
|
|
|
var $sidebar = $(".form-sidebar");
|
|
|
|
var $targets = $sidebar.find("[data-target]");
|
|
|
|
var $title = $sidebar.find(".title h1");
|
|
|
|
var is_open = false;
|
|
|
|
|
|
|
|
var close_sidebar = function () {
|
|
|
|
$sidebar.removeClass("show");
|
|
|
|
is_open = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.trigger_sidebar = function (target) {
|
|
|
|
$targets.hide();
|
|
|
|
var $target = $(".form-sidebar").find("[data-target='" + target + "']");
|
|
|
|
|
|
|
|
$title.text($target.attr("data-title"));
|
|
|
|
$target.show();
|
|
|
|
|
|
|
|
$sidebar.addClass("show");
|
|
|
|
is_open = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
$(".form-sidebar .exit").click(function (e) {
|
|
|
|
close_sidebar();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("body").click(function (e) {
|
|
|
|
if (is_open && !$(e.target).within(".form-sidebar")) {
|
|
|
|
close_sidebar();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("body").on("click", "[data-sidebar-form]", function (e) {
|
|
|
|
exports.trigger_sidebar($(this).attr("data-sidebar-form"));
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("body").on("click", "[data-sidebar-form-close]", close_sidebar);
|
2017-03-18 22:47:13 +01:00
|
|
|
|
|
|
|
function settings_close_modal() {
|
|
|
|
hashchange.exit_modal();
|
|
|
|
}
|
|
|
|
modals.set_close_handler("settings", settings_close_modal);
|
2017-03-01 01:31:33 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-06-10 09:03:36 +02:00
|
|
|
function _setup_page() {
|
2016-12-03 01:12:52 +01:00
|
|
|
var tab = (function () {
|
|
|
|
var tab = false;
|
|
|
|
var hash_sequence = window.location.hash.split(/\//);
|
|
|
|
if (/#*(settings)/.test(hash_sequence[0])) {
|
|
|
|
tab = hash_sequence[1];
|
|
|
|
return tab || "your-account";
|
|
|
|
}
|
|
|
|
return tab;
|
|
|
|
}());
|
|
|
|
|
2016-12-07 18:38:59 +01:00
|
|
|
// Most browsers do not allow filenames to start with `.` without the user manually changing it.
|
2017-01-20 23:49:20 +01:00
|
|
|
// So we use zuliprc, not .zuliprc.
|
|
|
|
|
|
|
|
var settings_tab = templates.render('settings_tab', {
|
|
|
|
full_name: people.my_full_name(),
|
|
|
|
page_params: page_params,
|
|
|
|
zuliprc: 'zuliprc',
|
2017-04-02 20:59:22 +02:00
|
|
|
timezones: moment.tz.names(),
|
2017-01-20 23:49:20 +01:00
|
|
|
});
|
|
|
|
|
2016-12-03 01:12:52 +01:00
|
|
|
$(".settings-box").html(settings_tab);
|
2014-02-13 23:47:57 +01:00
|
|
|
|
2017-04-07 01:30:13 +02:00
|
|
|
// Since we just swapped in a whole new settings widget, we need to
|
|
|
|
// tell settings_sections nothing is loaded.
|
|
|
|
settings_sections.reset_sections();
|
2014-03-04 23:37:29 +01:00
|
|
|
|
2016-12-03 01:12:52 +01:00
|
|
|
if (tab) {
|
|
|
|
exports.launch_page(tab);
|
|
|
|
}
|
2016-06-10 09:03:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.setup_page = function () {
|
|
|
|
i18n.ensure_i18n(_setup_page);
|
2014-02-13 23:47:57 +01:00
|
|
|
};
|
2013-05-03 00:29:52 +02:00
|
|
|
|
2016-12-03 01:12:52 +01:00
|
|
|
exports.launch_page = function (tab) {
|
|
|
|
var $active_tab = $("#settings_overlay_container li[data-section='" + tab + "']");
|
|
|
|
|
|
|
|
if (!$active_tab.hasClass("admin")) {
|
2017-02-21 19:10:50 +01:00
|
|
|
$(".sidebar .ind-tab[data-tab-key='settings']").click();
|
2016-12-03 01:12:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$("#settings_overlay_container").addClass("show");
|
|
|
|
$active_tab.click();
|
|
|
|
};
|
|
|
|
|
2017-04-04 19:59:04 +02:00
|
|
|
exports.handle_up_arrow = function (e) {
|
|
|
|
var prev = e.target.previousElementSibling;
|
|
|
|
|
|
|
|
if ($(prev).css("display") !== "none") {
|
|
|
|
$(prev).focus().click();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.handle_down_arrow = function (e) {
|
|
|
|
var next = e.target.nextElementSibling;
|
|
|
|
|
|
|
|
if ($(next).css("display") !== "none") {
|
|
|
|
$(next).focus().click();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-19 17:15:48 +01:00
|
|
|
return exports;
|
2013-06-27 23:05:36 +02:00
|
|
|
}());
|
2016-12-04 08:59:56 +01:00
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = settings;
|
|
|
|
}
|