summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Schatz <jschatz@gitlab.com>2016-08-25 14:49:36 +0000
committerJacob Schatz <jschatz@gitlab.com>2016-08-25 14:49:36 +0000
commit0b4fef6be48009404ac777034b0d61768b557673 (patch)
treefe011e23f53dbbe0c6a8fbfa6a0056a8af44fe51
parenta03da79fb2371ca0d866ce776bfb0bfe9f1be1df (diff)
parent96051549672084fabec9f67b1cf03c59e8ac3370 (diff)
downloadgitlab-ce-0b4fef6be48009404ac777034b0d61768b557673.tar.gz
Merge branch 'fix-hidden-discussion-permalinks' into 'master'
Automatically expand hidden discussions when accessed via a permalink hash (closes #19304) ## What does this MR do? Addresses "Auto-expand a discussion note when we arrive via anchor" (issue #19304) ## Are there points in the code the reviewer needs to double check? Let me know if the code is consistent with community standards (not 100% sure about indentation of chained jQuery actions) I don't think this MR warrants any unit tests or documentation, but let me know if you disagree. I'll add the requisite CHANGELOG entry upon approval. ## Why was this MR needed? Currently, if a discussion is accessed via a permalink to an "outdated" diff discussion, the anchor will not bring you to the expected part of the page. ## What are the relevant issue numbers? #19304 ## Does this MR meet the acceptance criteria? - [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - [ ] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md) - Tests - [ ] Added for this feature/bug - [ ] All builds are passing - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if you do - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) See merge request !5585
-rw-r--r--CHANGELOG1
-rw-r--r--app/assets/javascripts/behaviors/toggler_behavior.js30
-rw-r--r--app/assets/javascripts/lib/utils/url_utility.js12
3 files changed, 35 insertions, 8 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 104f37003c9..4e12f5d4f00 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,6 +7,7 @@ v 8.12.0 (unreleased)
- Optimistic locking for Issues and Merge Requests (title and description overriding prevention)
- Add `wiki_page_events` to project hook APIs (Ben Boeckel)
- Add Sentry logging to API calls
+ - Automatically expand hidden discussions when accessed by a permalink !5585 (Mike Greiling)
- Added tests for diff notes
- Added 'only_allow_merge_if_build_succeeds' project setting in the API. !5930 (Duck)
- Reduce number of database queries on builds tab
diff --git a/app/assets/javascripts/behaviors/toggler_behavior.js b/app/assets/javascripts/behaviors/toggler_behavior.js
index 1b7b63489ea..8ac1ba7665e 100644
--- a/app/assets/javascripts/behaviors/toggler_behavior.js
+++ b/app/assets/javascripts/behaviors/toggler_behavior.js
@@ -1,10 +1,26 @@
-(function() {
+(function(w) {
$(function() {
- return $("body").on("click", ".js-toggle-button", function(e) {
- $(this).find('i').toggleClass('fa fa-chevron-down').toggleClass('fa fa-chevron-up');
- $(this).closest(".js-toggle-container").find(".js-toggle-content").toggle();
- return e.preventDefault();
+ $('.js-toggle-button').on('click', function(e) {
+ e.preventDefault();
+ $(this)
+ .find('.fa')
+ .toggleClass('fa-chevron-down fa-chevron-up')
+ .end()
+ .closest('.js-toggle-container')
+ .find('.js-toggle-content')
+ .toggle()
+ ;
});
- });
-}).call(this);
+ // If we're accessing a permalink, ensure it is not inside a
+ // closed js-toggle-container!
+ var hash = w.gl.utils.getLocationHash();
+ 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');
+ anchor.scrollIntoView();
+ }
+ });
+})(window);
diff --git a/app/assets/javascripts/lib/utils/url_utility.js b/app/assets/javascripts/lib/utils/url_utility.js
index fffbfd19745..533310cc87c 100644
--- a/app/assets/javascripts/lib/utils/url_utility.js
+++ b/app/assets/javascripts/lib/utils/url_utility.js
@@ -43,7 +43,7 @@
}
return newUrl;
};
- return w.gl.utils.removeParamQueryString = function(url, param) {
+ w.gl.utils.removeParamQueryString = function(url, param) {
var urlVariables, variables;
url = decodeURIComponent(url);
urlVariables = url.split('&');
@@ -59,6 +59,16 @@
return results;
})()).join('&');
};
+ w.gl.utils.getLocationHash = function(url) {
+ var hashIndex;
+ if (typeof url === 'undefined') {
+ // Note: We can't use window.location.hash here because it's
+ // not consistent across browsers - Firefox will pre-decode it
+ url = window.location.href;
+ }
+ hashIndex = url.indexOf('#');
+ return hashIndex === -1 ? null : url.substring(hashIndex + 1);
+ };
})(window);
}).call(this);