Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

settings: Fix settings launch on mobile.

Gittenburg35378d4660af
diff --git a/static/js/admin.js b/static/js/admin.js
index 485ffe8a643..f159f1fdc02 100644
--- a/static/js/admin.js
+++ b/static/js/admin.js
@@ -121,7 +121,7 @@ exports.launch = function (section) {
settings_sections.reset_sections();
overlays.open_settings();
- settings_panel_menu.org_settings.activate_section(section);
+ settings_panel_menu.org_settings.activate_section_or_default(section);
settings_toggle.highlight_toggle('organization');
};
diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js
index 7183383daf2..3a10eb155d8 100644
--- a/static/js/click_handlers.js
+++ b/static/js/click_handlers.js
@@ -1,4 +1,5 @@
const util = require("./util");
+const settings_panel_menu = require('./settings_panel_menu');
// You won't find every click handler here, but it's a good place to start!
const render_buddy_list_tooltip = require('../templates/buddy_list_tooltip.hbs');
@@ -903,8 +904,7 @@ exports.initialize = function () {
});
$(".settings-header.mobile .fa-chevron-left").on("click", function () {
- $("#settings_page").find(".right").removeClass("show");
- $(this).parent().removeClass("slide-left");
+ settings_panel_menu.mobile_deactivate_section();
});
};
diff --git a/static/js/hashchange.js b/static/js/hashchange.js
index 43477628a56..df8c2647435 100644
--- a/static/js/hashchange.js
+++ b/static/js/hashchange.js
@@ -132,7 +132,7 @@ function do_hashchange_normal(from_reload) {
function do_hashchange_overlay(old_hash) {
const base = hash_util.get_hash_category(window.location.hash);
const old_base = hash_util.get_hash_category(old_hash);
- let section = hash_util.get_hash_section(window.location.hash);
+ const section = hash_util.get_hash_section(window.location.hash);
const coming_from_overlay = is_overlay_hash(old_hash || '#');
@@ -153,9 +153,8 @@ function do_hashchange_overlay(old_hash) {
// We may be on a really old browser or somebody
// hand-typed a hash.
blueslip.warn('missing section for settings');
- section = 'your-account';
}
- settings_panel_menu.normal_settings.activate_section(section);
+ settings_panel_menu.normal_settings.activate_section_or_default(section);
return;
}
@@ -164,9 +163,8 @@ function do_hashchange_overlay(old_hash) {
// We may be on a really old browser or somebody
// hand-typed a hash.
blueslip.warn('missing section for organization');
- section = 'organization-profile';
}
- settings_panel_menu.org_settings.activate_section(section);
+ settings_panel_menu.org_settings.activate_section_or_default(section);
return;
}
@@ -201,23 +199,11 @@ function do_hashchange_overlay(old_hash) {
}
if (base === 'settings') {
- if (!section) {
- section = settings_panel_menu.normal_settings.current_tab();
- const settings_hash = '#settings/' + section;
- exports.replace_hash(settings_hash);
- }
-
settings.launch(section);
return;
}
if (base === 'organization') {
- if (!section) {
- section = settings_panel_menu.org_settings.current_tab();
- const org_hash = '#organization/' + section;
- exports.replace_hash(org_hash);
- }
-
admin.launch(section);
return;
}
diff --git a/static/js/settings.js b/static/js/settings.js
index 883f45ea047..7e27c30c058 100644
--- a/static/js/settings.js
+++ b/static/js/settings.js
@@ -78,7 +78,7 @@ exports.launch = function (section) {
settings_sections.reset_sections();
overlays.open_settings();
- settings_panel_menu.normal_settings.activate_section(section);
+ settings_panel_menu.normal_settings.activate_section_or_default(section);
settings_toggle.highlight_toggle('settings');
};
diff --git a/static/js/settings_panel_menu.js b/static/js/settings_panel_menu.js
index 0f1f6e2cec3..3efdf3b8fa4 100644
--- a/static/js/settings_panel_menu.js
+++ b/static/js/settings_panel_menu.js
@@ -1,3 +1,9 @@
+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");
+};
+
exports.make_menu = function (opts) {
const main_elem = opts.main_elem;
const hash_prefix = opts.hash_prefix;
@@ -5,11 +11,16 @@ exports.make_menu = function (opts) {
const self = {};
+ function two_column_mode() {
+ return $('#settings_overlay_container').css('--single-column') === undefined;
+ }
+
self.show = function () {
main_elem.show();
const section = self.current_tab();
- if ($('#settings_overlay_container').css('--single-column') === undefined) {
- self.activate_section(section);
+ 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);
}
curr_li.focus();
};
@@ -59,7 +70,21 @@ exports.make_menu = function (opts) {
return true;
};
- self.activate_section = function (section) {
+ 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;
+ }
+ }
+
curr_li = self.li_for_section(section);
main_elem.children("li").removeClass("active");
@@ -93,7 +118,7 @@ exports.make_menu = function (opts) {
main_elem.on("click", "li[data-section]", function (e) {
const section = $(this).attr('data-section');
- self.activate_section(section);
+ self.activate_section_or_default(section);
// You generally want to add logic to activate_section,
// not to this click handler.