Skip to content

Commit 2169762

Browse files
Remove usage of JS globals (#15378)
Refactor the exported globals in index.js to JS-initialized event handlers. Co-authored-by: techknowlogick <[email protected]>
1 parent b9ed3cb commit 2169762

File tree

4 files changed

+34
-35
lines changed

4 files changed

+34
-35
lines changed

templates/repo/diff/comment_form.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
{{end}}
4545
{{end}}
4646
{{if or (not $.HasComments) $.hidden}}
47-
<button type="button" class="ui submit tiny basic button btn-cancel" onclick="window.cancelCodeComment(this);">{{$.root.i18n.Tr "cancel"}}</button>
47+
<button type="button" class="ui submit tiny basic button btn-cancel cancel-code-comment">{{$.root.i18n.Tr "cancel"}}</button>
4848
{{end}}
4949
</div>
5050
</div>

templates/repo/issue/view_content/sidebar.tmpl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,7 @@
467467
</div>
468468
<div class="item-right df ac">
469469
{{if and $.CanCreateIssueDependencies (not $.Repository.IsArchived)}}
470-
<a class="delete-dependency-button poping up ci" onclick="window.deleteDependencyModal({{.Issue.ID}}, 'blocking');"
471-
data-content="{{$.i18n.Tr "repo.issues.dependency.remove_info"}}" data-inverted="">
470+
<a class="delete-dependency-button poping up ci" data-id="{{.Issue.ID}}" data-type="blocking" data-content="{{$.i18n.Tr "repo.issues.dependency.remove_info"}}" data-inverted="">
472471
{{svg "octicon-trash" 16}}
473472
</a>
474473
{{end}}
@@ -495,8 +494,7 @@
495494
</div>
496495
<div class="item-right df ac">
497496
{{if and $.CanCreateIssueDependencies (not $.Repository.IsArchived)}}
498-
<a class="delete-dependency-button poping up ci" onclick="window.deleteDependencyModal({{.Issue.ID}}, 'blockedBy');"
499-
data-content="{{$.i18n.Tr "repo.issues.dependency.remove_info"}}" data-inverted="">
497+
<a class="delete-dependency-button poping up ci" data-id="{{.Issue.ID}}" data-type="blockedBy" data-content="{{$.i18n.Tr "repo.issues.dependency.remove_info"}}" data-inverted="">
500498
{{svg "octicon-trash" 16}}
501499
</a>
502500
{{end}}

templates/user/auth/signin_inner.tmpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
{{if and .OrderedOAuth2Names .OAuth2Providers}}
5454
<div class="ui attached segment">
5555
<div class="oauth2 center">
56-
<div id="oauth2-login-loader" class="ui disabled centered loader"></div>
56+
<div id="oauth2-login-loader" class="ui disabled centered loader"></div>
5757
<div>
5858
<div id="oauth2-login-navigator">
5959
<p>{{.i18n.Tr "sign_in_with"}}</p>
@@ -63,9 +63,8 @@
6363
<img
6464
alt="{{$provider.DisplayName}}{{if eq $provider.Name "openidConnect"}} ({{$key}}){{end}}"
6565
title="{{$provider.DisplayName}}{{if eq $provider.Name "openidConnect"}} ({{$key}}){{end}}"
66-
class="{{$provider.Name}}"
66+
class="{{$provider.Name}} oauth-login-image"
6767
src="{{AppSubUrl}}{{$provider.Image}}"
68-
onclick="window.onOAuthLoginClick()"
6968
></a>
7069
{{end}}
7170
</div>

web_src/js/index.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* exported deleteDependencyModal, cancelCodeComment, onOAuthLoginClick */
2-
31
import './publicpath.js';
42

53
import Vue from 'vue';
@@ -1156,6 +1154,32 @@ async function initRepository() {
11561154
return false;
11571155
});
11581156

1157+
// Delete Issue dependency
1158+
$(document).on('click', '.delete-dependency-button', (e) => {
1159+
const {id, type} = e.currentTarget.dataset;
1160+
1161+
$('.remove-dependency').modal({
1162+
closable: false,
1163+
duration: 200,
1164+
onApprove: () => {
1165+
$('#removeDependencyID').val(id);
1166+
$('#dependencyType').val(type);
1167+
$('#removeDependencyForm').trigger('submit');
1168+
}
1169+
}).modal('show');
1170+
});
1171+
1172+
// Cancel inline code comment
1173+
$(document).on('click', '.cancel-code-comment', (e) => {
1174+
const form = $(e.currentTarget).closest('form');
1175+
if (form.length > 0 && form.hasClass('comment-form')) {
1176+
form.addClass('hide');
1177+
form.parent().find('button.comment-form-reply').show();
1178+
} else {
1179+
form.closest('.comment-code-cloud').remove();
1180+
}
1181+
});
1182+
11591183
// Change status
11601184
const $statusButton = $('#status-button');
11611185
$('#comment-form textarea').on('keyup', function () {
@@ -1193,6 +1217,7 @@ async function initRepository() {
11931217
$mergeButton.parent().show();
11941218
$('.instruct-toggle').show();
11951219
});
1220+
11961221
initReactionSelector();
11971222
}
11981223

@@ -3812,19 +3837,6 @@ function initIssueDue() {
38123837
});
38133838
}
38143839

3815-
window.deleteDependencyModal = function (id, type) {
3816-
$('.remove-dependency')
3817-
.modal({
3818-
closable: false,
3819-
duration: 200,
3820-
onApprove() {
3821-
$('#removeDependencyID').val(id);
3822-
$('#dependencyType').val(type);
3823-
$('#removeDependencyForm').trigger('submit');
3824-
}
3825-
}).modal('show');
3826-
};
3827-
38283840
function initIssueList() {
38293841
const repolink = $('#repolink').val();
38303842
const repoId = $('#repoId').val();
@@ -3911,17 +3923,7 @@ $(document).on('submit', '.conversation-holder form', async (e) => {
39113923
initClipboard();
39123924
});
39133925

3914-
window.cancelCodeComment = function (btn) {
3915-
const form = $(btn).closest('form');
3916-
if (form.length > 0 && form.hasClass('comment-form')) {
3917-
form.addClass('hide');
3918-
form.parent().find('button.comment-form-reply').show();
3919-
} else {
3920-
form.closest('.comment-code-cloud').remove();
3921-
}
3922-
};
3923-
3924-
window.onOAuthLoginClick = function () {
3926+
$(document).on('click', '.oauth-login-image', () => {
39253927
const oauthLoader = $('#oauth2-login-loader');
39263928
const oauthNav = $('#oauth2-login-navigator');
39273929

@@ -3934,4 +3936,4 @@ window.onOAuthLoginClick = function () {
39343936
oauthLoader.addClass('disabled');
39353937
oauthNav.show();
39363938
}, 5000);
3937-
};
3939+
});

0 commit comments

Comments
 (0)