diff options
Diffstat (limited to 'app/assets/javascripts/blob_edit')
-rw-r--r-- | app/assets/javascripts/blob_edit/blob_bundle.js | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/app/assets/javascripts/blob_edit/blob_bundle.js b/app/assets/javascripts/blob_edit/blob_bundle.js index 2d426ee663a..f84e39baa53 100644 --- a/app/assets/javascripts/blob_edit/blob_bundle.js +++ b/app/assets/javascripts/blob_edit/blob_bundle.js @@ -8,11 +8,40 @@ import initPopover from '~/blob/suggest_gitlab_ci_yml'; import { disableButtonIfEmptyField, setCookie } from '~/lib/utils/common_utils'; import Tracking from '~/tracking'; +const initPopovers = () => { + const suggestEl = document.querySelector('.js-suggest-gitlab-ci-yml'); + + if (suggestEl) { + const commitButton = document.querySelector('#commit-changes'); + + initPopover(suggestEl); + + if (commitButton) { + const { dismissKey, humanAccess } = suggestEl.dataset; + const urlParams = new URLSearchParams(window.location.search); + const mergeRequestPath = urlParams.get('mr_path') || true; + + const commitCookieName = `suggest_gitlab_ci_yml_commit_${dismissKey}`; + const commitTrackLabel = 'suggest_gitlab_ci_yml_commit_changes'; + const commitTrackValue = '20'; + + commitButton.addEventListener('click', () => { + setCookie(commitCookieName, mergeRequestPath); + + Tracking.event(undefined, 'click_button', { + label: commitTrackLabel, + property: humanAccess, + value: commitTrackValue, + }); + }); + } + } +}; + export default () => { const editBlobForm = $('.js-edit-blob-form'); const uploadBlobForm = $('.js-upload-blob-form'); const deleteBlobForm = $('.js-delete-blob-form'); - const suggestEl = document.querySelector('.js-suggest-gitlab-ci-yml'); if (editBlobForm.length) { const urlRoot = editBlobForm.data('relativeUrlRoot'); @@ -33,6 +62,7 @@ export default () => { projectId, isMarkdown, }); + initPopovers(); }) .catch(e => createFlash(e)); @@ -62,30 +92,4 @@ export default () => { if (deleteBlobForm.length) { new NewCommitForm(deleteBlobForm); } - - if (suggestEl) { - const commitButton = document.querySelector('#commit-changes'); - - initPopover(suggestEl); - - if (commitButton) { - const { dismissKey, humanAccess } = suggestEl.dataset; - const urlParams = new URLSearchParams(window.location.search); - const mergeRequestPath = urlParams.get('mr_path') || true; - - const commitCookieName = `suggest_gitlab_ci_yml_commit_${dismissKey}`; - const commitTrackLabel = 'suggest_gitlab_ci_yml_commit_changes'; - const commitTrackValue = '20'; - - commitButton.addEventListener('click', () => { - setCookie(commitCookieName, mergeRequestPath); - - Tracking.event(undefined, 'click_button', { - label: commitTrackLabel, - property: humanAccess, - value: commitTrackValue, - }); - }); - } - } }; |