2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
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");
|
|
|
|
};
|
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
function two_column_mode() {
|
|
|
|
return $("#settings_overlay_container").css("--single-column") === undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
class SettingsPanelMenu {
|
|
|
|
constructor(opts) {
|
|
|
|
this.main_elem = opts.main_elem;
|
|
|
|
this.hash_prefix = opts.hash_prefix;
|
|
|
|
this.curr_li = this.main_elem.children("li").eq(0);
|
|
|
|
|
|
|
|
this.main_elem.on("click", "li[data-section]", (e) => {
|
|
|
|
const section = $(e.currentTarget).attr("data-section");
|
|
|
|
|
|
|
|
this.activate_section_or_default(section);
|
2018-06-03 17:29:11 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
// You generally want to add logic to activate_section,
|
|
|
|
// not to this click handler.
|
2018-06-03 17:29:11 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2020-06-25 00:51:20 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
show() {
|
|
|
|
this.main_elem.show();
|
|
|
|
const section = this.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.
|
2020-07-23 02:34:41 +02:00
|
|
|
this.activate_section_or_default(section);
|
2020-06-24 07:46:43 +02:00
|
|
|
}
|
2020-07-23 02:34:41 +02:00
|
|
|
this.curr_li.trigger("focus");
|
|
|
|
}
|
2018-06-03 17:29:11 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
hide() {
|
|
|
|
this.main_elem.hide();
|
|
|
|
}
|
2018-06-03 17:29:11 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
current_tab() {
|
|
|
|
return this.curr_li.data("section");
|
|
|
|
}
|
2018-06-03 19:12:11 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
li_for_section(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;
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
2018-12-02 21:00:53 +01:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
set_key_handlers(toggler) {
|
2018-06-03 12:42:43 +02:00
|
|
|
keydown_util.handle({
|
2020-07-23 02:34:41 +02:00
|
|
|
elem: this.main_elem,
|
2018-06-03 12:42:43 +02:00
|
|
|
handlers: {
|
|
|
|
left_arrow: toggler.maybe_go_left,
|
|
|
|
right_arrow: toggler.maybe_go_right,
|
2020-07-23 02:34:41 +02:00
|
|
|
enter_key: () => this.enter_panel(),
|
|
|
|
up_arrow: () => this.prev(),
|
|
|
|
down_arrow: () => this.next(),
|
2018-06-03 12:42:43 +02:00
|
|
|
},
|
|
|
|
});
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
2018-06-03 12:42:43 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
prev() {
|
|
|
|
this.curr_li.prevAll(":visible:first").trigger("focus").trigger("click");
|
2018-06-03 12:42:43 +02:00
|
|
|
return true;
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
2018-06-03 12:42:43 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
next() {
|
|
|
|
this.curr_li.nextAll(":visible:first").trigger("focus").trigger("click");
|
2018-06-03 12:42:43 +02:00
|
|
|
return true;
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
2018-06-03 12:42:43 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
enter_panel() {
|
|
|
|
const panel = this.get_panel();
|
2020-07-15 01:29:15 +02:00
|
|
|
const sel = "input:visible,button:visible,select:visible";
|
2019-11-02 00:06:25 +01:00
|
|
|
const panel_elem = panel.find(sel).first();
|
2018-06-04 12:52:42 +02:00
|
|
|
|
2020-07-20 21:24:26 +02:00
|
|
|
panel_elem.trigger("focus");
|
2018-06-04 12:52:42 +02:00
|
|
|
return true;
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
2018-06-04 12:52:42 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
activate_section_or_default(section) {
|
2020-06-25 00:51:20 +02:00
|
|
|
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.
|
2020-07-23 02:34:41 +02:00
|
|
|
section = this.current_tab();
|
2020-06-25 00:51:20 +02:00
|
|
|
} else {
|
|
|
|
// In single column mode we close the active section
|
|
|
|
// so that you always start at the settings list.
|
|
|
|
exports.mobile_deactivate_section();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
this.curr_li = this.li_for_section(section);
|
2018-06-03 19:12:11 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
this.main_elem.children("li").removeClass("active");
|
|
|
|
this.curr_li.addClass("active");
|
2018-12-02 17:34:48 +01:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
const settings_section_hash = "#" + this.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
|
|
|
|
2020-07-03 18:49:26 +02:00
|
|
|
$(".settings-section").removeClass("show");
|
2018-06-03 17:59:33 +02:00
|
|
|
|
2018-12-08 19:28:26 +01:00
|
|
|
settings_sections.load_settings_section(section);
|
2018-06-03 17:59:33 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
this.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);
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
2018-06-04 12:52:42 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
get_panel() {
|
|
|
|
const section = this.curr_li.data("section");
|
2019-11-02 00:06:25 +01:00
|
|
|
const sel = "[data-name='" + section + "']";
|
2020-07-03 18:49:26 +02:00
|
|
|
const panel = $(".settings-section" + sel);
|
2018-06-04 12:52:42 +02:00
|
|
|
return panel;
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.SettingsPanelMenu = SettingsPanelMenu;
|
2018-06-03 17:29:11 +02:00
|
|
|
|
|
|
|
exports.initialize = function () {
|
2020-07-23 02:34:41 +02:00
|
|
|
exports.normal_settings = new SettingsPanelMenu({
|
2020-07-15 01:29:15 +02:00
|
|
|
main_elem: $(".normal-settings-list"),
|
2018-06-03 17:59:33 +02:00
|
|
|
hash_prefix: "settings/",
|
2018-06-03 17:29:11 +02:00
|
|
|
});
|
2020-07-23 02:34:41 +02:00
|
|
|
exports.org_settings = new SettingsPanelMenu({
|
2020-07-15 01:29:15 +02:00
|
|
|
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;
|