From 216976247c1bb958f01a0b33c5f457d7fed62a4d Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 10 Apr 2021 01:42:38 +0200 Subject: [PATCH] Remove usage of JS globals (#15378) Refactor the exported globals in index.js to JS-initialized event handlers. Co-authored-by: techknowlogick --- templates/repo/diff/comment_form.tmpl | 2 +- .../repo/issue/view_content/sidebar.tmpl | 6 +- templates/user/auth/signin_inner.tmpl | 5 +- web_src/js/index.js | 56 ++++++++++--------- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/templates/repo/diff/comment_form.tmpl b/templates/repo/diff/comment_form.tmpl index b12beeab82..c82d32c214 100644 --- a/templates/repo/diff/comment_form.tmpl +++ b/templates/repo/diff/comment_form.tmpl @@ -44,7 +44,7 @@ {{end}} {{end}} {{if or (not $.HasComments) $.hidden}} - + {{end}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 872a86e658..30acb839b5 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -467,8 +467,7 @@
{{if and $.CanCreateIssueDependencies (not $.Repository.IsArchived)}} - + {{svg "octicon-trash" 16}} {{end}} @@ -495,8 +494,7 @@
{{if and $.CanCreateIssueDependencies (not $.Repository.IsArchived)}} - + {{svg "octicon-trash" 16}} {{end}} diff --git a/templates/user/auth/signin_inner.tmpl b/templates/user/auth/signin_inner.tmpl index 4d99d378ad..20a286aacb 100644 --- a/templates/user/auth/signin_inner.tmpl +++ b/templates/user/auth/signin_inner.tmpl @@ -53,7 +53,7 @@ {{if and .OrderedOAuth2Names .OAuth2Providers}}
-
+

{{.i18n.Tr "sign_in_with"}}

@@ -63,9 +63,8 @@ {{$provider.DisplayName}}{{if eq $provider.Name {{end}}
diff --git a/web_src/js/index.js b/web_src/js/index.js index a191af6df1..f7a767d6a2 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -1,5 +1,3 @@ -/* exported deleteDependencyModal, cancelCodeComment, onOAuthLoginClick */ - import './publicpath.js'; import Vue from 'vue'; @@ -1156,6 +1154,32 @@ async function initRepository() { return false; }); + // Delete Issue dependency + $(document).on('click', '.delete-dependency-button', (e) => { + const {id, type} = e.currentTarget.dataset; + + $('.remove-dependency').modal({ + closable: false, + duration: 200, + onApprove: () => { + $('#removeDependencyID').val(id); + $('#dependencyType').val(type); + $('#removeDependencyForm').trigger('submit'); + } + }).modal('show'); + }); + + // Cancel inline code comment + $(document).on('click', '.cancel-code-comment', (e) => { + const form = $(e.currentTarget).closest('form'); + if (form.length > 0 && form.hasClass('comment-form')) { + form.addClass('hide'); + form.parent().find('button.comment-form-reply').show(); + } else { + form.closest('.comment-code-cloud').remove(); + } + }); + // Change status const $statusButton = $('#status-button'); $('#comment-form textarea').on('keyup', function () { @@ -1193,6 +1217,7 @@ async function initRepository() { $mergeButton.parent().show(); $('.instruct-toggle').show(); }); + initReactionSelector(); } @@ -3812,19 +3837,6 @@ function initIssueDue() { }); } -window.deleteDependencyModal = function (id, type) { - $('.remove-dependency') - .modal({ - closable: false, - duration: 200, - onApprove() { - $('#removeDependencyID').val(id); - $('#dependencyType').val(type); - $('#removeDependencyForm').trigger('submit'); - } - }).modal('show'); -}; - function initIssueList() { const repolink = $('#repolink').val(); const repoId = $('#repoId').val(); @@ -3911,17 +3923,7 @@ $(document).on('submit', '.conversation-holder form', async (e) => { initClipboard(); }); -window.cancelCodeComment = function (btn) { - const form = $(btn).closest('form'); - if (form.length > 0 && form.hasClass('comment-form')) { - form.addClass('hide'); - form.parent().find('button.comment-form-reply').show(); - } else { - form.closest('.comment-code-cloud').remove(); - } -}; - -window.onOAuthLoginClick = function () { +$(document).on('click', '.oauth-login-image', () => { const oauthLoader = $('#oauth2-login-loader'); const oauthNav = $('#oauth2-login-navigator'); @@ -3934,4 +3936,4 @@ window.onOAuthLoginClick = function () { oauthLoader.addClass('disabled'); oauthNav.show(); }, 5000); -}; +});