diff options
author | Byron Jones <glob@mozilla.com> | 2015-10-12 06:56:46 +0200 |
---|---|---|
committer | Byron Jones <glob@mozilla.com> | 2015-10-12 06:56:46 +0200 |
commit | bb7cbda33555735d17c41d2b9bdd54359dad2d94 (patch) | |
tree | a26287c6e48f3b5c00fac515dd2f832bbd23d085 /extensions/BugModal/web | |
parent | c2364b357634e07c1b709c5cb120181ae3bc5e65 (diff) | |
download | bugzilla-bb7cbda33555735d17c41d2b9bdd54359dad2d94.tar.gz bugzilla-bb7cbda33555735d17c41d2b9bdd54359dad2d94.tar.xz |
Bug 1149899 - Remember expanded/collapsed sections
Diffstat (limited to 'extensions/BugModal/web')
-rw-r--r-- | extensions/BugModal/web/bug_modal.js | 64 |
1 files changed, 41 insertions, 23 deletions
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()) |