summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/blob
diff options
context:
space:
mode:
authorJacob Schatz <jschatz@gitlab.com>2017-04-24 19:59:35 +0000
committerJacob Schatz <jschatz@gitlab.com>2017-04-24 19:59:35 +0000
commit60fe0c2743d8fb5c0f8a3b7de5e8c9b37b3f1bef (patch)
tree5092fe063306982bffcb637cf407baecc8c73dbd /app/assets/javascripts/blob
parent22c88c675df13d918be1f4f681dbca47cb263bcb (diff)
parent5f7b4cb5d8061f83f07ce079157d7d98e4257926 (diff)
downloadgitlab-ce-60fe0c2743d8fb5c0f8a3b7de5e8c9b37b3f1bef.tar.gz
Merge branch 'use-jquery-on-blob-fork-suggestion' into 'master'
Use jQuery niceness on blob_fork_suggestion See merge request !10858
Diffstat (limited to 'app/assets/javascripts/blob')
-rw-r--r--app/assets/javascripts/blob/blob_fork_suggestion.js53
1 files changed, 25 insertions, 28 deletions
diff --git a/app/assets/javascripts/blob/blob_fork_suggestion.js b/app/assets/javascripts/blob/blob_fork_suggestion.js
index 3baf81905fe..47c431fb809 100644
--- a/app/assets/javascripts/blob/blob_fork_suggestion.js
+++ b/app/assets/javascripts/blob/blob_fork_suggestion.js
@@ -16,47 +16,44 @@ const defaults = {
class BlobForkSuggestion {
constructor(options) {
this.elementMap = Object.assign({}, defaults, options);
- this.onClickWrapper = this.onClick.bind(this);
-
- document.addEventListener('click', this.onClickWrapper);
+ this.onOpenButtonClick = this.onOpenButtonClick.bind(this);
+ this.onCancelButtonClick = this.onCancelButtonClick.bind(this);
}
- showSuggestionSection(forkPath, action = 'edit') {
- [].forEach.call(this.elementMap.suggestionSections, (suggestionSection) => {
- suggestionSection.classList.remove('hidden');
- });
+ init() {
+ this.bindEvents();
- [].forEach.call(this.elementMap.forkButtons, (forkButton) => {
- forkButton.setAttribute('href', forkPath);
- });
+ return this;
+ }
- [].forEach.call(this.elementMap.actionTextPieces, (actionTextPiece) => {
- // eslint-disable-next-line no-param-reassign
- actionTextPiece.textContent = action;
- });
+ bindEvents() {
+ $(this.elementMap.openButtons).on('click', this.onOpenButtonClick);
+ $(this.elementMap.cancelButtons).on('click', this.onCancelButtonClick);
}
- hideSuggestionSection() {
- [].forEach.call(this.elementMap.suggestionSections, (suggestionSection) => {
- suggestionSection.classList.add('hidden');
- });
+ showSuggestionSection(forkPath, action = 'edit') {
+ $(this.elementMap.suggestionSections).removeClass('hidden');
+ $(this.elementMap.forkButtons).attr('href', forkPath);
+ $(this.elementMap.actionTextPieces).text(action);
}
- onClick(e) {
- const el = e.target;
+ hideSuggestionSection() {
+ $(this.elementMap.suggestionSections).addClass('hidden');
+ }
- if ([].includes.call(this.elementMap.openButtons, el)) {
- const { forkPath, action } = el.dataset;
- this.showSuggestionSection(forkPath, action);
- }
+ onOpenButtonClick(e) {
+ const forkPath = $(e.currentTarget).attr('data-fork-path');
+ const action = $(e.currentTarget).attr('data-action');
+ this.showSuggestionSection(forkPath, action);
+ }
- if ([].includes.call(this.elementMap.cancelButtons, el)) {
- this.hideSuggestionSection();
- }
+ onCancelButtonClick() {
+ this.hideSuggestionSection();
}
destroy() {
- document.removeEventListener('click', this.onClickWrapper);
+ $(this.elementMap.openButtons).off('click', this.onOpenButtonClick);
+ $(this.elementMap.cancelButtons).off('click', this.onCancelButtonClick);
}
}