2020-06-25 00:51:20 +02:00
|
|
|
exports.mobile_deactivate_section = function () {
|
|
|
|
const $settings_overlay_container = $("#settings_overlay_container");
|
|
|
|
$settings_overlay_container.find(".right").removeClass("show");
|
|
|
|
$settings_overlay_container.find(".settings-header.mobile").removeClass("slide-left");
|
|
|
|
};
|
|
|
|
|
2018-06-03 17:29:11 +02:00
|
|
|
exports.make_menu = function (opts) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const main_elem = opts.main_elem;
|
|
|
|
const hash_prefix = opts.hash_prefix;
|
|
|
|
let curr_li = main_elem.children('li').eq(0);
|
2018-06-03 17:29:11 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const self = {};
|
2018-06-03 17:29:11 +02:00
|
|
|
|
2020-06-25 00:51:20 +02:00
|
|
|
function two_column_mode() {
|
|
|
|
return $('#settings_overlay_container').css('--single-column') === undefined;
|
|
|
|
}
|
|
|
|
|
2018-06-03 17:29:11 +02:00
|
|
|
self.show = function () {
|
|
|
|
main_elem.show();
|
2019-11-02 00:06:25 +01:00
|
|
|
const section = self.current_tab();
|
2020-06-25 00:51:20 +02:00
|
|
|
if (two_column_mode()) {
|
|
|
|
// In one colum mode want to show the settings list, not the first settings section.
|
|
|
|
self.activate_section_or_default(section);
|
2020-06-24 07:46:43 +02:00
|
|
|
}
|
2018-06-03 12:42:43 +02:00
|
|
|
curr_li.focus();
|
2018-06-03 17:29:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
self.hide = function () {
|
|
|
|
main_elem.hide();
|
|
|
|
};
|
|
|
|
|
2018-06-03 19:12:11 +02:00
|
|
|
self.current_tab = function () {
|
|
|
|
return curr_li.data('section');
|
|
|
|
};
|
|
|
|
|
2018-12-02 21:00:53 +01:00
|
|
|
self.li_for_section = function (section) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const li = $("#settings_overlay_container li[data-section='" + section + "']");
|
2018-12-02 21:00:53 +01:00
|
|
|
return li;
|
|
|
|
};
|
|
|
|
|
2018-06-03 12:42:43 +02:00
|
|
|
self.set_key_handlers = function (toggler) {
|
|
|
|
keydown_util.handle({
|
|
|
|
elem: main_elem,
|
|
|
|
handlers: {
|
|
|
|
left_arrow: toggler.maybe_go_left,
|
|
|
|
right_arrow: toggler.maybe_go_right,
|
2018-06-04 12:52:42 +02:00
|
|
|
enter_key: self.enter_panel,
|
2018-06-03 12:42:43 +02:00
|
|
|
up_arrow: self.prev,
|
|
|
|
down_arrow: self.next,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
self.prev = function () {
|
2019-08-15 16:39:28 +02:00
|
|
|
curr_li.prevAll(":visible:first").focus().click();
|
2018-06-03 12:42:43 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
self.next = function () {
|
2019-08-15 16:39:28 +02:00
|
|
|
curr_li.nextAll(":visible:first").focus().click();
|
2018-06-03 12:42:43 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2018-06-04 12:52:42 +02:00
|
|
|
self.enter_panel = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const panel = self.get_panel();
|
|
|
|
const sel = 'input:visible,button:visible,select:visible';
|
|
|
|
const panel_elem = panel.find(sel).first();
|
2018-06-04 12:52:42 +02:00
|
|
|
|
|
|
|
panel_elem.focus();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2020-06-25 00:51:20 +02:00
|
|
|
self.activate_section_or_default = function (section) {
|
|
|
|
if (!section) {
|
|
|
|
// No section is given so we display the default.
|
|
|
|
|
|
|
|
if (two_column_mode()) {
|
|
|
|
// In two column mode we resume to the last active section.
|
|
|
|
section = self.current_tab();
|
|
|
|
} else {
|
|
|
|
// In single column mode we close the active section
|
|
|
|
// so that you always start at the settings list.
|
|
|
|
exports.mobile_deactivate_section();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-02 21:00:53 +01:00
|
|
|
curr_li = self.li_for_section(section);
|
2018-06-03 19:12:11 +02:00
|
|
|
|
2020-06-24 07:46:43 +02:00
|
|
|
main_elem.children("li").removeClass("active");
|
2018-12-02 21:00:53 +01:00
|
|
|
curr_li.addClass("active");
|
2018-12-02 17:34:48 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const settings_section_hash = '#' + hash_prefix + section;
|
2018-12-02 17:34:48 +01:00
|
|
|
hashchange.update_browser_history(settings_section_hash);
|
2018-06-03 17:59:33 +02:00
|
|
|
|
|
|
|
$(".settings-section, .settings-wrapper").removeClass("show");
|
|
|
|
|
2018-12-08 19:28:26 +01:00
|
|
|
settings_sections.load_settings_section(section);
|
2018-06-03 17:59:33 +02:00
|
|
|
|
2018-06-04 12:52:42 +02:00
|
|
|
self.get_panel().addClass('show');
|
2018-12-02 21:10:32 +01:00
|
|
|
|
2019-03-01 01:40:05 +01:00
|
|
|
ui.reset_scrollbar($("#settings_content"));
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const $settings_overlay_container = $("#settings_overlay_container");
|
2018-12-02 21:10:32 +01:00
|
|
|
$settings_overlay_container.find(".right").addClass("show");
|
|
|
|
$settings_overlay_container.find(".settings-header.mobile").addClass("slide-left");
|
|
|
|
|
|
|
|
settings.set_settings_header(section);
|
2018-06-04 12:52:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
self.get_panel = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const section = curr_li.data('section');
|
|
|
|
const sel = "[data-name='" + section + "']";
|
|
|
|
const panel = $(".settings-section" + sel + ", .settings-wrapper" + sel);
|
2018-06-04 12:52:42 +02:00
|
|
|
return panel;
|
2018-06-03 17:59:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
main_elem.on("click", "li[data-section]", function (e) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const section = $(this).attr('data-section');
|
2018-12-02 21:00:53 +01:00
|
|
|
|
2020-06-25 00:51:20 +02:00
|
|
|
self.activate_section_or_default(section);
|
2018-06-03 17:59:33 +02:00
|
|
|
|
2018-12-02 21:10:32 +01:00
|
|
|
// You generally want to add logic to activate_section,
|
|
|
|
// not to this click handler.
|
2018-06-26 13:26:06 +02:00
|
|
|
|
2018-06-03 17:59:33 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2018-06-03 17:29:11 +02:00
|
|
|
return self;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.initialize = function () {
|
|
|
|
exports.normal_settings = exports.make_menu({
|
|
|
|
main_elem: $('.normal-settings-list'),
|
2018-06-03 17:59:33 +02:00
|
|
|
hash_prefix: "settings/",
|
2018-06-03 17:29:11 +02:00
|
|
|
});
|
|
|
|
exports.org_settings = exports.make_menu({
|
|
|
|
main_elem: $('.org-settings-list'),
|
2018-06-03 17:59:33 +02:00
|
|
|
hash_prefix: "organization/",
|
2018-06-03 17:29:11 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.show_normal_settings = function () {
|
|
|
|
exports.org_settings.hide();
|
|
|
|
exports.normal_settings.show();
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.show_org_settings = function () {
|
|
|
|
exports.normal_settings.hide();
|
|
|
|
exports.org_settings.show();
|
|
|
|
};
|
|
|
|
|
2018-06-03 12:42:43 +02:00
|
|
|
exports.set_key_handlers = function (toggler) {
|
|
|
|
exports.normal_settings.set_key_handlers(toggler);
|
|
|
|
exports.org_settings.set_key_handlers(toggler);
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.settings_panel_menu = exports;
|