diff options
5 files changed, 51 insertions, 24 deletions
diff --git a/extensions/BugModal/Extension.pm b/extensions/BugModal/Extension.pm index 54ef8f4ca..2c60ef35a 100644 --- a/extensions/BugModal/Extension.pm +++ b/extensions/BugModal/Extension.pm @@ -293,6 +293,7 @@ sub webservice { sub install_before_final_checks { my ($self, $args) = @_; add_setting('ui_experiments', ['on', 'off'], 'off'); + add_setting('ui_remember_collapsed', ['on', 'off'], 'off'); # ensure the correct skin is being used my $dbh = Bugzilla->dbh; diff --git a/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl index ddf37a26c..2663d5562 100644 --- a/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl @@ -1015,6 +1015,12 @@ [% END %] [% END %] +[%# === initialise module visibility === %] + +<script> + init_module_visibility(); +</script> + [%# === top (between modules and comments) actions === %] [% IF user.id %] diff --git a/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl index 7fdb2ed49..361b9ec9d 100644 --- a/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl @@ -99,7 +99,8 @@ can_tag: [% user.can_tag_comments ? "true" : "false" %], settings: { quote_replies: '[% user.settings.quote_replies.value FILTER js %]', - zoom_textareas: [% user.settings.zoom_textareas.value == "on" ? "true" : "false" %] + zoom_textareas: [% user.settings.zoom_textareas.value == "on" ? "true" : "false" %], + remember_collapsed: [% user.settings.ui_remember_collapsed.value == "on" ? "true" : "false" %] } }; [% IF user.id %] diff --git a/extensions/BugModal/template/en/default/hook/global/setting-descs-settings.none.tmpl b/extensions/BugModal/template/en/default/hook/global/setting-descs-settings.none.tmpl index 7214977bb..4ca9c3003 100644 --- a/extensions/BugModal/template/en/default/hook/global/setting-descs-settings.none.tmpl +++ b/extensions/BugModal/template/en/default/hook/global/setting-descs-settings.none.tmpl @@ -8,4 +8,5 @@ [% setting_descs.ui_experiments = "Use experimental user interface" + setting_descs.ui_remember_collapsed = "Remember visibility of header sections when viewing a bug" %] diff --git a/extensions/BugModal/web/bug_modal.js b/extensions/BugModal/web/bug_modal.js index 74ee83312..ac467aa0f 100644 --- a/extensions/BugModal/web/bug_modal.js +++ b/extensions/BugModal/web/bug_modal.js @@ -5,6 +5,47 @@ * This Source Code Form is "Incompatible With Secondary Licenses", as * defined by the Mozilla Public License, v. 2.0. */ +// expand/collapse module +function slide_module(module, action, fast) { + if (!module.attr('id')) + return; + var latch = module.find('.module-latch'); + var spinner = $(latch.children('.module-spinner')[0]); + var content = $(module.children('.module-content')[0]); + var duration = fast ? 0 : 200; + + function slide_done() { + var is_visible = content.is(':visible'); + spinner.html(is_visible ? '▾' : '▸'); + if (BUGZILLA.user.settings.remember_collapsed) + localStorage.setItem(module.attr('id') + '.visibility', is_visible ? 'show' : 'hide'); + } + + if (action == 'show') { + content.slideDown(duration, 'swing', slide_done); + } + else if (action == 'hide') { + content.slideUp(duration, 'swing', slide_done); + } + else { + content.slideToggle(duration, 'swing', slide_done); + } +} + +function init_module_visibility() { + if (!BUGZILLA.user.settings.remember_collapsed) + return; + $('.module').each(function() { + var that = $(this); + var id = that.attr('id'); + if (!id) return; + var stored = localStorage.getItem(id + '.visibility'); + if (stored) { + slide_module(that, stored, true); + } + }); +} + $(function() { 'use strict'; @@ -25,29 +66,6 @@ $(function() { // products with descriptions (also lazy-loaded) var products = []; - // expand/collapse module - function slide_module(module, action, fast) { - if (!module.attr('id')) - return; - var latch = module.find('.module-latch'); - var spinner = $(latch.children('.module-spinner')[0]); - var content = $(module.children('.module-content')[0]); - var duration = fast ? 0 : 200; - - function slide_done() { - spinner.html(content.is(':visible') ? '▾' : '▸'); - } - if (action == 'show') { - content.slideDown(duration, 'swing', slide_done); - } - else if (action == 'hide') { - content.slideUp(duration, 'swing', slide_done); - } - else { - content.slideToggle(duration, 'swing', slide_done); - } - } - // restore edit mode after navigating back function restoreEditMode() { if (!$('#editing').val()) |