diff options
author | Filipa Lacerda <lacerda.filipa@gmail.com> | 2017-02-01 22:31:38 +0000 |
---|---|---|
committer | Filipa Lacerda <lacerda.filipa@gmail.com> | 2017-02-01 22:31:38 +0000 |
commit | 4f5a77a4403e7305360e27681ced10e3ee7f797b (patch) | |
tree | d52558a0a7dec0693b29952df84c6bc67749e261 /app | |
parent | 797ca1b15d4a1c20b1cbab3060061d5b684048e3 (diff) | |
parent | 34a1e3dcdbb7fdfcc1bafdc9dbaeee3c79b94c1c (diff) | |
download | gitlab-ce-4f5a77a4403e7305360e27681ced10e3ee7f797b.tar.gz |
Merge branch '27089-26860-27151-fix-discussion-note-permalink-collapsed' into 'master'
Fix permalink discussion note being collapsed
Closes #26860, #27089, and #27151
See merge request !8773
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/behaviors/toggler_behavior.js | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/app/assets/javascripts/behaviors/toggler_behavior.js b/app/assets/javascripts/behaviors/toggler_behavior.js index 6a49715590c..a7181904ac9 100644 --- a/app/assets/javascripts/behaviors/toggler_behavior.js +++ b/app/assets/javascripts/behaviors/toggler_behavior.js @@ -1,6 +1,19 @@ /* eslint-disable wrap-iife, func-names, space-before-function-paren, prefer-arrow-callback, vars-on-top, no-var, max-len */ (function(w) { $(function() { + var toggleContainer = function(container, /* optional */toggleState) { + var $container = $(container); + + $container + .find('.js-toggle-button .fa') + .toggleClass('fa-chevron-up', toggleState) + .toggleClass('fa-chevron-down', toggleState !== undefined ? !toggleState : undefined); + + $container + .find('.js-toggle-content') + .toggle(toggleState); + }; + // Toggle button. Show/hide content inside parent container. // Button does not change visibility. If button has icon - it changes chevron style. // @@ -10,14 +23,7 @@ // $('body').on('click', '.js-toggle-button', function(e) { e.preventDefault(); - $(this) - .find('.fa') - .toggleClass('fa-chevron-down fa-chevron-up') - .end() - .closest('.js-toggle-container') - .find('.js-toggle-content') - .toggle() - ; + toggleContainer($(this).closest('.js-toggle-container')); }); // If we're accessing a permalink, ensure it is not inside a @@ -26,8 +32,8 @@ var anchor = hash && document.getElementById(hash); var container = anchor && $(anchor).closest('.js-toggle-container'); - if (container && container.find('.js-toggle-content').is(':hidden')) { - container.find('.js-toggle-button').trigger('click'); + if (container) { + toggleContainer(container, true); anchor.scrollIntoView(); } }); |