瀏覽代碼

Upgrade jQuery to 3.5.0, remove jQuery-Migrate, fix deprecations (#11055)

- Removed jQuery-Migrate as it seems to no longer be needed.
- Removed a dead code section.
- Fixed some deprecations detected by jQuery-Migrate.

Ref: https://jquery.com/upgrade-guide/3.5/
Ref: https://github.com/gogs/gogs/search?q=repo-name-change-prompt
Ref: https://github.com/go-gitea/gitea/search?q=repo-name-change-prompt
Fixes: https://github.com/go-gitea/gitea/issues/9372

Co-authored-by: zeripath <art27@cantab.net>
tags/v1.13.0-dev
silverwind 4 年之前
父節點
當前提交
b57a735e77
No account linked to committer's email address
共有 5 個文件被更改,包括 115 次插入137 次删除
  1. 3
    8
      package-lock.json
  2. 1
    2
      package.json
  3. 1
    6
      public/vendor/librejs.html
  4. 110
    119
      web_src/js/index.js
  5. 0
    2
      web_src/js/jquery.js

+ 3
- 8
package-lock.json 查看文件

} }
}, },
"jquery": { "jquery": {
"version": "3.4.1",
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.1.tgz",
"integrity": "sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw=="
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.0.tgz",
"integrity": "sha512-Xb7SVYMvygPxbFMpTFQiHh1J7HClEaThguL15N/Gg37Lri/qKyhRGZYzHRyLH8Stq3Aow0LsHO2O2ci86fCrNQ=="
}, },
"jquery-datetimepicker": { "jquery-datetimepicker": {
"version": "2.5.21", "version": "2.5.21",
"php-date-formatter": "^1.3.4" "php-date-formatter": "^1.3.4"
} }
}, },
"jquery-migrate": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/jquery-migrate/-/jquery-migrate-3.1.0.tgz",
"integrity": "sha512-u/MtE1ST2pCr3rCyouJG2xMiw/k3OzLNeRKprjKTeHUezCGr0DyEgeXFdqFLmQfxfR5EsVu+mGo/sCcYdiYcIQ=="
},
"jquery-mousewheel": { "jquery-mousewheel": {
"version": "3.1.13", "version": "3.1.13",
"resolved": "https://registry.npmjs.org/jquery-mousewheel/-/jquery-mousewheel-3.1.13.tgz", "resolved": "https://registry.npmjs.org/jquery-mousewheel/-/jquery-mousewheel-3.1.13.tgz",

+ 1
- 2
package.json 查看文件

"fomantic-ui": "2.8.4", "fomantic-ui": "2.8.4",
"highlight.js": "9.18.1", "highlight.js": "9.18.1",
"imports-loader": "0.8.0", "imports-loader": "0.8.0",
"jquery": "3.4.1",
"jquery": "3.5.0",
"jquery-datetimepicker": "2.5.21", "jquery-datetimepicker": "2.5.21",
"jquery-migrate": "3.1.0",
"jquery.are-you-sure": "1.9.0", "jquery.are-you-sure": "1.9.0",
"less-loader": "5.0.0", "less-loader": "5.0.0",
"mini-css-extract-plugin": "0.9.0", "mini-css-extract-plugin": "0.9.0",

+ 1
- 6
public/vendor/librejs.html 查看文件

<tr> <tr>
<td><a href="../js/jquery.js">jQuery</a></td> <td><a href="../js/jquery.js">jQuery</a></td>
<td><a href="https://jquery.org/license/">MIT</a></td> <td><a href="https://jquery.org/license/">MIT</a></td>
<td><a href="https://code.jquery.com/jquery-3.4.1.min.js">jquery-3.4.1.min.js</a></td>
</tr>
<tr>
<td><a href="../js/jquery.js">jQuery Migrate</a></td>
<td><a href="https://jquery.org/license/">MIT</a></td>
<td><a href="https://code.jquery.com/jquery-migrate-3.1.0.min.js">jquery-migrate-3.1.0.min.js</a></td>
<td><a href="https://code.jquery.com/jquery-3.5.0.min.js">jquery-3.5.0.min.js</a></td>
</tr> </tr>
<tr> <tr>
<td><a href="../fomantic/semantic.min.js">semantic.min.js</a></td> <td><a href="../fomantic/semantic.min.js">semantic.min.js</a></td>

+ 110
- 119
web_src/js/index.js 查看文件

function initCommentPreviewTab($form) { function initCommentPreviewTab($form) {
const $tabMenu = $form.find('.tabular.menu'); const $tabMenu = $form.find('.tabular.menu');
$tabMenu.find('.item').tab(); $tabMenu.find('.item').tab();
$tabMenu.find(`.item[data-tab="${$tabMenu.data('preview')}"]`).click(function () {
$tabMenu.find(`.item[data-tab="${$tabMenu.data('preview')}"]`).on('click', function () {
const $this = $(this); const $this = $(this);
$.post($this.data('url'), { $.post($this.data('url'), {
_csrf: csrf, _csrf: csrf,
const $previewTab = $tabMenu.find(`.item[data-tab="${$tabMenu.data('preview')}"]`); const $previewTab = $tabMenu.find(`.item[data-tab="${$tabMenu.data('preview')}"]`);
if ($previewTab.length) { if ($previewTab.length) {
previewFileModes = $previewTab.data('preview-file-modes').split(','); previewFileModes = $previewTab.data('preview-file-modes').split(',');
$previewTab.click(function () {
$previewTab.on('click', function () {
const $this = $(this); const $this = $(this);
$.post($this.data('url'), { $.post($this.data('url'), {
_csrf: csrf, _csrf: csrf,
function initEditDiffTab($form) { function initEditDiffTab($form) {
const $tabMenu = $form.find('.tabular.menu'); const $tabMenu = $form.find('.tabular.menu');
$tabMenu.find('.item').tab(); $tabMenu.find('.item').tab();
$tabMenu.find(`.item[data-tab="${$tabMenu.data('diff')}"]`).click(function () {
$tabMenu.find(`.item[data-tab="${$tabMenu.data('diff')}"]`).on('click', function () {
const $this = $(this); const $this = $(this);
$.post($this.data('url'), { $.post($this.data('url'), {
_csrf: csrf, _csrf: csrf,
function initBranchSelector() { function initBranchSelector() {
const $selectBranch = $('.ui.select-branch'); const $selectBranch = $('.ui.select-branch');
const $branchMenu = $selectBranch.find('.reference-list-menu'); const $branchMenu = $selectBranch.find('.reference-list-menu');
$branchMenu.find('.item:not(.no-select)').click(function () {
$branchMenu.find('.item:not(.no-select)').on('click', function () {
const selectedValue = $(this).data('id'); const selectedValue = $(this).data('id');
$($(this).data('id-selector')).val(selectedValue); $($(this).data('id-selector')).val(selectedValue);
$selectBranch.find('.ui .branch-name').text(selectedValue); $selectBranch.find('.ui .branch-name').text(selectedValue);
}); });
$selectBranch.find('.reference.column').click(function () {
$selectBranch.find('.reference.column').on('click', function () {
$selectBranch.find('.scrolling.reference-list-menu').css('display', 'none'); $selectBranch.find('.scrolling.reference-list-menu').css('display', 'none');
$selectBranch.find('.reference .text').removeClass('black'); $selectBranch.find('.reference .text').removeClass('black');
$($(this).data('target')).css('display', 'block'); $($(this).data('target')).css('display', 'block');
function initLabelEdit() { function initLabelEdit() {
// Create label // Create label
const $newLabelPanel = $('.new-label.segment'); const $newLabelPanel = $('.new-label.segment');
$('.new-label.button').click(() => {
$('.new-label.button').on('click', () => {
$newLabelPanel.show(); $newLabelPanel.show();
}); });
$('.new-label.segment .cancel').click(() => {
$('.new-label.segment .cancel').on('click', () => {
$newLabelPanel.hide(); $newLabelPanel.hide();
}); });


$('.color-picker').each(function () { $('.color-picker').each(function () {
$(this).minicolors(); $(this).minicolors();
}); });
$('.precolors .color').click(function () {
$('.precolors .color').on('click', function () {
const color_hex = $(this).data('color-hex'); const color_hex = $(this).data('color-hex');
$('.color-picker').val(color_hex); $('.color-picker').val(color_hex);
$('.minicolors-swatch-color').css('background-color', color_hex); $('.minicolors-swatch-color').css('background-color', color_hex);
}); });
$('.edit-label-button').click(function () {
$('.edit-label-button').on('click', function () {
$('#label-modal-id').val($(this).data('id')); $('#label-modal-id').val($(this).data('id'));
$('.edit-label .new-label-input').val($(this).data('title')); $('.edit-label .new-label-input').val($(this).data('title'));
$('.edit-label .new-label-desc-input').val($(this).data('description')); $('.edit-label .new-label-desc-input').val($(this).data('description'));
$('.minicolors-swatch-color').css('background-color', $(this).data('color')); $('.minicolors-swatch-color').css('background-color', $(this).data('color'));
$('.edit-label.modal').modal({ $('.edit-label.modal').modal({
onApprove() { onApprove() {
$('.edit-label.form').submit();
$('.edit-label.form').trigger('submit');
} }
}).modal('show'); }).modal('show');
return false; return false;
} }
}); });


$listMenu.find('.item:not(.no-select)').click(function () {
$listMenu.find('.item:not(.no-select)').on('click', function () {
// we don't need the action attribute when updating assignees // we don't need the action attribute when updating assignees
if (selector === 'select-assignees-modify' || selector === 'select-reviewers-modify') { if (selector === 'select-assignees-modify' || selector === 'select-reviewers-modify') {
// UI magic. We need to do this here, otherwise it would destroy the functionality of // UI magic. We need to do this here, otherwise it would destroy the functionality of
$($(this).parent().data('id')).val(listIds.join(',')); $($(this).parent().data('id')).val(listIds.join(','));
return false; return false;
}); });
$listMenu.find('.no-select.item').click(function () {
$listMenu.find('.no-select.item').on('click', function () {
if (hasLabelUpdateAction || selector === 'select-assignees-modify') { if (hasLabelUpdateAction || selector === 'select-assignees-modify') {
updateIssuesMeta( updateIssuesMeta(
$listMenu.data('update-url'), $listMenu.data('update-url'),
const $list = $(`.ui${select_id}.list`); const $list = $(`.ui${select_id}.list`);
const hasUpdateAction = $menu.data('action') === 'update'; const hasUpdateAction = $menu.data('action') === 'update';


$menu.find('.item:not(.no-select)').click(function () {
$menu.find('.item:not(.no-select)').on('click', function () {
$(this).parent().find('.item').each(function () { $(this).parent().find('.item').each(function () {
$(this).removeClass('selected active'); $(this).removeClass('selected active');
}); });
$(`.ui${select_id}.list .no-select`).addClass('hide'); $(`.ui${select_id}.list .no-select`).addClass('hide');
$(input_id).val($(this).data('id')); $(input_id).val($(this).data('id'));
}); });
$menu.find('.no-select.item').click(function () {
$menu.find('.no-select.item').on('click', function () {
$(this).parent().find('.item:not(.no-select)').each(function () { $(this).parent().find('.item:not(.no-select)').each(function () {
$(this).removeClass('selected active'); $(this).removeClass('selected active');
}); });
} }


// Database type change detection. // Database type change detection.
$('#db_type').change(function () {
$('#db_type').on('change', function () {
const sqliteDefault = 'data/gitea.db'; const sqliteDefault = 'data/gitea.db';
const tidbDefault = 'data/gitea_tidb'; const tidbDefault = 'data/gitea_tidb';


}); });


// TODO: better handling of exclusive relations. // TODO: better handling of exclusive relations.
$('#offline-mode input').change(function () {
$('#offline-mode input').on('change', function () {
if ($(this).is(':checked')) { if ($(this).is(':checked')) {
$('#disable-gravatar').checkbox('check'); $('#disable-gravatar').checkbox('check');
$('#federated-avatar-lookup').checkbox('uncheck'); $('#federated-avatar-lookup').checkbox('uncheck');
} }
}); });
$('#disable-gravatar input').change(function () {
$('#disable-gravatar input').on('change', function () {
if ($(this).is(':checked')) { if ($(this).is(':checked')) {
$('#federated-avatar-lookup').checkbox('uncheck'); $('#federated-avatar-lookup').checkbox('uncheck');
} else { } else {
$('#offline-mode').checkbox('uncheck'); $('#offline-mode').checkbox('uncheck');
} }
}); });
$('#federated-avatar-lookup input').change(function () {
$('#federated-avatar-lookup input').on('change', function () {
if ($(this).is(':checked')) { if ($(this).is(':checked')) {
$('#disable-gravatar').checkbox('uncheck'); $('#disable-gravatar').checkbox('uncheck');
$('#offline-mode').checkbox('uncheck'); $('#offline-mode').checkbox('uncheck');
} }
}); });
$('#enable-openid-signin input').change(function () {
$('#enable-openid-signin input').on('change', function () {
if ($(this).is(':checked')) { if ($(this).is(':checked')) {
if (!$('#disable-registration input').is(':checked')) { if (!$('#disable-registration input').is(':checked')) {
$('#enable-openid-signup').checkbox('check'); $('#enable-openid-signup').checkbox('check');
$('#enable-openid-signup').checkbox('uncheck'); $('#enable-openid-signup').checkbox('uncheck');
} }
}); });
$('#disable-registration input').change(function () {
$('#disable-registration input').on('change', function () {
if ($(this).is(':checked')) { if ($(this).is(':checked')) {
$('#enable-captcha').checkbox('uncheck'); $('#enable-captcha').checkbox('uncheck');
$('#enable-openid-signup').checkbox('uncheck'); $('#enable-openid-signup').checkbox('uncheck');
$('#enable-openid-signup').checkbox('check'); $('#enable-openid-signup').checkbox('check');
} }
}); });
$('#enable-captcha input').change(function () {
$('#enable-captcha input').on('change', function () {
if ($(this).is(':checked')) { if ($(this).is(':checked')) {
$('#disable-registration').checkbox('uncheck'); $('#disable-registration').checkbox('uncheck');
} }
).then(reload); ).then(reload);
}); });


$(document).click((event) => {
$(document).on('click', (event) => {
const urlTarget = $(':target'); const urlTarget = $(':target');
if (urlTarget.length === 0) return; if (urlTarget.length === 0) return;




// Options // Options
if ($('.repository.settings.options').length > 0) { if ($('.repository.settings.options').length > 0) {
$('#repo_name').keyup(function () {
const $prompt = $('#repo-name-change-prompt');
if ($(this).val().toString().toLowerCase() !== $(this).data('name').toString().toLowerCase()) {
$prompt.show();
} else {
$prompt.hide();
}
});

// Enable or select internal/external wiki system and issue tracker. // Enable or select internal/external wiki system and issue tracker.
$('.enable-system').change(function () {
$('.enable-system').on('change', function () {
if (this.checked) { if (this.checked) {
$($(this).data('target')).removeClass('disabled'); $($(this).data('target')).removeClass('disabled');
if (!$(this).data('context')) $($(this).data('context')).addClass('disabled'); if (!$(this).data('context')) $($(this).data('context')).addClass('disabled');
if (!$(this).data('context')) $($(this).data('context')).removeClass('disabled'); if (!$(this).data('context')) $($(this).data('context')).removeClass('disabled');
} }
}); });
$('.enable-system-radio').change(function () {
$('.enable-system-radio').on('change', function () {
if (this.value === 'false') { if (this.value === 'false') {
$($(this).data('target')).addClass('disabled'); $($(this).data('target')).addClass('disabled');
if (typeof $(this).data('context') !== 'undefined') $($(this).data('context')).removeClass('disabled'); if (typeof $(this).data('context') !== 'undefined') $($(this).data('context')).removeClass('disabled');
$('#deadline').val(date.toISOString().substring(0, 10)); $('#deadline').val(date.toISOString().substring(0, 10));
}, },
}); });
$('#clear-date').click(() => {
$('#clear-date').on('click', () => {
$('#deadline').val(''); $('#deadline').val('');
return false; return false;
}); });
)); ));
selectionTextField.data('branch', branchNameNew); // update branch name in setting selectionTextField.data('branch', branchNameNew); // update branch name in setting
}; };
$('#branch-select > .item').click(changeBranchSelect);
$('#branch-select > .item').on('click', changeBranchSelect);


$('#edit-title').click(editTitleToggle);
$('#cancel-edit-title').click(editTitleToggle);
$('#save-edit-title').click(editTitleToggle).click(function () {
$('#edit-title').on('click', editTitleToggle);
$('#cancel-edit-title').on('click', editTitleToggle);
$('#save-edit-title').on('click', editTitleToggle).on('click', function () {
const pullrequest_targetbranch_change = function (update_url) { const pullrequest_targetbranch_change = function (update_url) {
const targetBranch = $('#pull-target-branch').data('branch'); const targetBranch = $('#pull-target-branch').data('branch');
const $branchTarget = $('#branch_target'); const $branchTarget = $('#branch_target');
}); });


// Quote reply // Quote reply
$('.quote-reply').click(function (event) {
$('.quote-reply').on('click', function (event) {
$(this).closest('.dropdown').find('.menu').toggle('visible'); $(this).closest('.dropdown').find('.menu').toggle('visible');
const target = $(this).data('target'); const target = $(this).data('target');
const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> '); const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> ');
let $content; let $content;
if ($(this).hasClass('quote-reply-diff')) { if ($(this).hasClass('quote-reply-diff')) {
const $parent = $(this).closest('.comment-code-cloud'); const $parent = $(this).closest('.comment-code-cloud');
$parent.find('button.comment-form-reply').click();
$parent.find('button.comment-form-reply').trigger('click');
$content = $parent.find('[name="content"]'); $content = $parent.find('[name="content"]');
if ($content.val() !== '') { if ($content.val() !== '') {
$content.val(`${$content.val()}\n\n${content}`); $content.val(`${$content.val()}\n\n${content}`);
}); });


// Edit issue or comment content // Edit issue or comment content
$('.edit-content').click(async function (event) {
$('.edit-content').on('click', async function (event) {
$(this).closest('.dropdown').find('.menu').toggle('visible'); $(this).closest('.dropdown').find('.menu').toggle('visible');
const $segment = $(this).closest('.header').next(); const $segment = $(this).closest('.header').next();
const $editContentZone = $segment.find('.edit-content-zone'); const $editContentZone = $segment.find('.edit-content-zone');
initCommentPreviewTab($editContentForm); initCommentPreviewTab($editContentForm);
initSimpleMDEImagePaste($simplemde, $files); initSimpleMDEImagePaste($simplemde, $files);


$editContentZone.find('.cancel.button').click(() => {
$editContentZone.find('.cancel.button').on('click', () => {
$renderContent.show(); $renderContent.show();
$editContentZone.hide(); $editContentZone.hide();
dz.emit('reload'); dz.emit('reload');
}); });
$editContentZone.find('.save.button').click(() => {
$editContentZone.find('.save.button').on('click', () => {
$renderContent.show(); $renderContent.show();
$editContentZone.hide(); $editContentZone.hide();
const $attachments = $files.find('[name=files]').map(function () { const $attachments = $files.find('[name=files]').map(function () {
}); });


// Delete comment // Delete comment
$('.delete-comment').click(function () {
$('.delete-comment').on('click', function () {
const $this = $(this); const $this = $(this);
if (window.confirm($this.data('locale'))) { if (window.confirm($this.data('locale'))) {
$.post($this.data('url'), { $.post($this.data('url'), {


// Change status // Change status
const $statusButton = $('#status-button'); const $statusButton = $('#status-button');
$('#comment-form .edit_area').keyup(function () {
$('#comment-form .edit_area').on('keyup', function () {
if ($(this).val().length === 0) { if ($(this).val().length === 0) {
$statusButton.text($statusButton.data('status')); $statusButton.text($statusButton.data('status'));
} else { } else {
$statusButton.text($statusButton.data('status-and-comment')); $statusButton.text($statusButton.data('status-and-comment'));
} }
}); });
$statusButton.click(() => {
$statusButton.on('click', () => {
$('#status').val($statusButton.data('status-val')); $('#status').val($statusButton.data('status-val'));
$('#comment-form').submit();
$('#comment-form').trigger('submit');
}); });


// Pull Request merge button // Pull Request merge button
} }


// Quick start and repository home // Quick start and repository home
$('#repo-clone-ssh').click(function () {
$('#repo-clone-ssh').on('click', function () {
$('.clone-url').text($(this).data('link')); $('.clone-url').text($(this).data('link'));
$('#repo-clone-url').val($(this).data('link')); $('#repo-clone-url').val($(this).data('link'));
$(this).addClass('blue'); $(this).addClass('blue');
$('#repo-clone-https').removeClass('blue'); $('#repo-clone-https').removeClass('blue');
localStorage.setItem('repo-clone-protocol', 'ssh'); localStorage.setItem('repo-clone-protocol', 'ssh');
}); });
$('#repo-clone-https').click(function () {
$('#repo-clone-https').on('click', function () {
$('.clone-url').text($(this).data('link')); $('.clone-url').text($(this).data('link'));
$('#repo-clone-url').val($(this).data('link')); $('#repo-clone-url').val($(this).data('link'));
$(this).addClass('blue'); $(this).addClass('blue');
$('#repo-clone-ssh').removeClass('blue'); $('#repo-clone-ssh').removeClass('blue');
localStorage.setItem('repo-clone-protocol', 'https'); localStorage.setItem('repo-clone-protocol', 'https');
}); });
$('#repo-clone-url').click(function () {
$('#repo-clone-url').on('click', function () {
$(this).select(); $(this).select();
}); });


// Branches // Branches
if ($('.repository.settings.branches').length > 0) { if ($('.repository.settings.branches').length > 0) {
initFilterSearchDropdown('.protected-branches .dropdown'); initFilterSearchDropdown('.protected-branches .dropdown');
$('.enable-protection, .enable-whitelist, .enable-statuscheck').change(function () {
$('.enable-protection, .enable-whitelist, .enable-statuscheck').on('change', function () {
if (this.checked) { if (this.checked) {
$($(this).data('target')).removeClass('disabled'); $($(this).data('target')).removeClass('disabled');
} else { } else {
$($(this).data('target')).addClass('disabled'); $($(this).data('target')).addClass('disabled');
} }
}); });
$('.disable-whitelist').change(function () {
$('.disable-whitelist').on('change', function () {
if (this.checked) { if (this.checked) {
$($(this).data('target')).addClass('disabled'); $($(this).data('target')).addClass('disabled');
} }


function initRepositoryCollaboration() { function initRepositoryCollaboration() {
// Change collaborator access mode // Change collaborator access mode
$('.access-mode.menu .item').click(function () {
$('.access-mode.menu .item').on('click', function () {
const $menu = $(this).parent(); const $menu = $(this).parent();
$.post($menu.data('url'), { $.post($menu.data('url'), {
_csrf: csrf, _csrf: csrf,


function initTeamSettings() { function initTeamSettings() {
// Change team access mode // Change team access mode
$('.organization.new.team input[name=permission]').change(() => {
$('.organization.new.team input[name=permission]').on('change', () => {
const val = $('input[name=permission]:checked', '.organization.new.team').val(); const val = $('input[name=permission]:checked', '.organization.new.team').val();
if (val === 'admin') { if (val === 'admin') {
$('.organization.new.team .team-units').hide(); $('.organization.new.team .team-units').hide();
const $bSideBySide = $('.editor-toolbar a.fa-columns'); const $bSideBySide = $('.editor-toolbar a.fa-columns');
$bEdit.on('click', () => { $bEdit.on('click', () => {
if ($toolbar.hasClass('disabled-for-preview')) { if ($toolbar.hasClass('disabled-for-preview')) {
$bPreview.click();
$bPreview.trigger('click');
} }
}); });
$bPrev.on('click', () => { $bPrev.on('click', () => {
if (!$toolbar.hasClass('disabled-for-preview')) { if (!$toolbar.hasClass('disabled-for-preview')) {
$bPreview.click();
$bPreview.trigger('click');
} }
}); });
$bPreview.on('click', () => { $bPreview.on('click', () => {
} }


function initEditor() { function initEditor() {
$('.js-quick-pull-choice-option').change(function () {
$('.js-quick-pull-choice-option').on('change', function () {
if ($(this).val() === 'commit-to-new-branch') { if ($(this).val() === 'commit-to-new-branch') {
$('.quick-pull-branch-name').show(); $('.quick-pull-branch-name').show();
$('.quick-pull-branch-name input').prop('required', true); $('.quick-pull-branch-name input').prop('required', true);
}); });


const $editFilename = $('#file-name'); const $editFilename = $('#file-name');
$editFilename.keyup(function (e) {
$editFilename.on('keyup', function (e) {
const $section = $('.breadcrumb span.section'); const $section = $('.breadcrumb span.section');
const $divider = $('.breadcrumb div.divider'); const $divider = $('.breadcrumb div.divider');
let value; let value;
} }
}); });


$commitButton.click((event) => {
$commitButton.on('click', (event) => {
// A modal which asks if an empty file should be committed // A modal which asks if an empty file should be committed
if ($editArea.val().length === 0) { if ($editArea.val().length === 0) {
$('#edit-empty-content-modal').modal({ $('#edit-empty-content-modal').modal({
onApprove() { onApprove() {
$('.edit.form').submit();
$('.edit.form').trigger('submit');
} }
}).modal('show'); }).modal('show');
event.preventDefault(); event.preventDefault();


// Options // Options
if ($('.organization.settings.options').length > 0) { if ($('.organization.settings.options').length > 0) {
$('#org_name').keyup(function () {
$('#org_name').on('keyup', function () {
const $prompt = $('#org-name-change-prompt'); const $prompt = $('#org-name-change-prompt');
if ($(this).val().toString().toLowerCase() !== $(this).data('org-name').toString().toLowerCase()) { if ($(this).val().toString().toLowerCase() !== $(this).data('org-name').toString().toLowerCase()) {
$prompt.show(); $prompt.show();
function initUserSettings() { function initUserSettings() {
// Options // Options
if ($('.user.settings.profile').length > 0) { if ($('.user.settings.profile').length > 0) {
$('#username').keyup(function () {
$('#username').on('keyup', function () {
const $prompt = $('#name-change-prompt'); const $prompt = $('#name-change-prompt');
if ($(this).val().toString().toLowerCase() !== $(this).data('name').toString().toLowerCase()) { if ($(this).val().toString().toLowerCase() !== $(this).data('name').toString().toLowerCase()) {
$prompt.show(); $prompt.show();
return; return;
} }


$('.events.checkbox input').change(function () {
$('.events.checkbox input').on('change', function () {
if ($(this).is(':checked')) { if ($(this).is(':checked')) {
$('.events.fields').show(); $('.events.fields').show();
} }
}); });
$('.non-events.checkbox input').change(function () {
$('.non-events.checkbox input').on('change', function () {
if ($(this).is(':checked')) { if ($(this).is(':checked')) {
$('.events.fields').hide(); $('.events.fields').hide();
} }
$('#content_type').parent().parent()[visible ? 'show' : 'hide'](); $('#content_type').parent().parent()[visible ? 'show' : 'hide']();
}; };
updateContentType(); updateContentType();
$('#http_method').change(() => {
$('#http_method').on('change', () => {
updateContentType(); updateContentType();
}); });


// Test delivery // Test delivery
$('#test-delivery').click(function () {
$('#test-delivery').on('click', function () {
const $this = $(this); const $this = $(this);
$this.addClass('loading disabled'); $this.addClass('loading disabled');
$.post($this.data('link'), { $.post($this.data('link'), {


// New user // New user
if ($('.admin.new.user').length > 0 || $('.admin.edit.user').length > 0) { if ($('.admin.new.user').length > 0 || $('.admin.edit.user').length > 0) {
$('#login_type').change(function () {
$('#login_type').on('change', function () {
if ($(this).val().substring(0, 1) === '0') { if ($(this).val().substring(0, 1) === '0') {
$('#login_name').removeAttr('required'); $('#login_name').removeAttr('required');
$('.non-local').hide(); $('.non-local').hide();


// New authentication // New authentication
if ($('.admin.new.authentication').length > 0) { if ($('.admin.new.authentication').length > 0) {
$('#auth_type').change(function () {
$('#auth_type').on('change', function () {
$('.ldap, .dldap, .smtp, .pam, .oauth2, .has-tls, .search-page-size, .sspi').hide(); $('.ldap, .dldap, .smtp, .pam, .oauth2, .has-tls, .search-page-size, .sspi').hide();


$('.ldap input[required], .binddnrequired input[required], .dldap input[required], .smtp input[required], .pam input[required], .oauth2 input[required], .has-tls input[required], .sspi input[required]').removeAttr('required'); $('.ldap input[required], .binddnrequired input[required], .dldap input[required], .smtp input[required], .pam input[required], .oauth2 input[required], .has-tls input[required], .sspi input[required]').removeAttr('required');
onUsePagedSearchChange(); onUsePagedSearchChange();
} }
}); });
$('#auth_type').change();
$('#security_protocol').change(onSecurityProtocolChange);
$('#use_paged_search').change(onUsePagedSearchChange);
$('#oauth2_provider').change(onOAuth2Change);
$('#oauth2_use_custom_url').change(onOAuth2UseCustomURLChange);
$('#auth_type').trigger('change');
$('#security_protocol').on('change', onSecurityProtocolChange);
$('#use_paged_search').on('change', onUsePagedSearchChange);
$('#oauth2_provider').on('change', onOAuth2Change);
$('#oauth2_use_custom_url').on('change', onOAuth2UseCustomURLChange);
} }
// Edit authentication // Edit authentication
if ($('.admin.edit.authentication').length > 0) { if ($('.admin.edit.authentication').length > 0) {
const authType = $('#auth_type').val(); const authType = $('#auth_type').val();
if (authType === '2' || authType === '5') { if (authType === '2' || authType === '5') {
$('#security_protocol').change(onSecurityProtocolChange);
$('#security_protocol').on('change', onSecurityProtocolChange);
if (authType === '2') { if (authType === '2') {
$('#use_paged_search').change(onUsePagedSearchChange);
$('#use_paged_search').on('change', onUsePagedSearchChange);
} }
} else if (authType === '6') { } else if (authType === '6') {
$('#oauth2_provider').change(onOAuth2Change);
$('#oauth2_use_custom_url').change(onOAuth2UseCustomURLChange);
$('#oauth2_provider').on('change', onOAuth2Change);
$('#oauth2_use_custom_url').on('change', onOAuth2UseCustomURLChange);
onOAuth2Change(); onOAuth2Change();
} }
} }
const $detailModal = $('#detail-modal'); const $detailModal = $('#detail-modal');


// Attach view detail modals // Attach view detail modals
$('.view-detail').click(function () {
$('.view-detail').on('click', function () {
$detailModal.find('.content p').text($(this).data('content')); $detailModal.find('.content p').text($(this).data('content'));
$detailModal.modal('show'); $detailModal.modal('show');
return false; return false;


// Select actions // Select actions
const $checkboxes = $('.select.table .ui.checkbox'); const $checkboxes = $('.select.table .ui.checkbox');
$('.select.action').click(function () {
$('.select.action').on('click', function () {
switch ($(this).data('action')) { switch ($(this).data('action')) {
case 'select-all': case 'select-all':
$checkboxes.checkbox('check'); $checkboxes.checkbox('check');
break; break;
} }
}); });
$('#delete-selection').click(function () {
$('#delete-selection').on('click', function () {
const $this = $(this); const $this = $(this);
$this.addClass('loading disabled'); $this.addClass('loading disabled');
const ids = []; const ids = [];
} }


function buttonsClickOnEnter() { function buttonsClickOnEnter() {
$('.ui.button').keypress(function (e) {
$('.ui.button').on('keypress', function (e) {
if (e.keyCode === 13 || e.keyCode === 32) { // enter key or space bar if (e.keyCode === 13 || e.keyCode === 32) { // enter key or space bar
$(this).click();
$(this).trigger('click');
} }
}); });
} }
} }


function initWipTitle() { function initWipTitle() {
$('.title_wip_desc > a').click((e) => {
$('.title_wip_desc > a').on('click', (e) => {
e.preventDefault(); e.preventDefault();


const $issueTitle = $('#issue_title'); const $issueTitle = $('#issue_title');
$nonTemplate.show(); $nonTemplate.show();
} }
}; };
$repoTemplate.change(checkTemplate);
$repoTemplate.on('change', checkTemplate);
checkTemplate(); checkTemplate();


const changeOwner = function () { const changeOwner = function () {
fullTextSearch: true fullTextSearch: true
}); });
}; };
$('#uid').change(changeOwner);
$('#uid').on('change', changeOwner);
changeOwner(); changeOwner();
} }


$('.tabular.menu .item').tab(); $('.tabular.menu .item').tab();
$('.tabable.menu .item').tab(); $('.tabable.menu .item').tab();


$('.toggle.button').click(function () {
$('.toggle.button').on('click', function () {
$($(this).data('target')).slideToggle(100); $($(this).data('target')).slideToggle(100);
}); });


// make table <tr> element clickable like a link // make table <tr> element clickable like a link
$('tr[data-href]').click(function () {
$('tr[data-href]').on('click', function () {
window.location = $(this).data('href'); window.location = $(this).data('href');
}); });


} }


// Helpers. // Helpers.
$('.delete-button').click(showDeletePopup);
$('.add-all-button').click(showAddAllPopup);
$('.link-action').click(linkAction);
$('.link-email-action').click(linkEmailAction);
$('.delete-button').on('click', showDeletePopup);
$('.add-all-button').on('click', showAddAllPopup);
$('.link-action').on('click', linkAction);
$('.link-email-action').on('click', linkEmailAction);


$('.delete-branch-button').click(showDeletePopup);
$('.delete-branch-button').on('click', showDeletePopup);


$('.undo-button').click(function () {
$('.undo-button').on('click', function () {
const $this = $(this); const $this = $(this);
$.post($this.data('url'), { $.post($this.data('url'), {
_csrf: csrf, _csrf: csrf,
window.location.href = data.redirect; window.location.href = data.redirect;
}); });
}); });
$('.show-panel.button').click(function () {
$('.show-panel.button').on('click', function () {
$($(this).data('panel')).show(); $($(this).data('panel')).show();
}); });
$('.show-modal.button').click(function () {
$('.show-modal.button').on('click', function () {
$($(this).data('modal')).modal('show'); $($(this).data('modal')).modal('show');
}); });
$('.delete-post.button').click(function () {
$('.delete-post.button').on('click', function () {
const $this = $(this); const $this = $(this);
$.post($this.data('request-url'), { $.post($this.data('request-url'), {
_csrf: csrf _csrf: csrf
}); });
}); });


$('.issue-checkbox').click(() => {
$('.issue-checkbox').on('click', () => {
const numChecked = $('.issue-checkbox').children('input:checked').length; const numChecked = $('.issue-checkbox').children('input:checked').length;
if (numChecked > 0) { if (numChecked > 0) {
$('#issue-filters').addClass('hide'); $('#issue-filters').addClass('hide');
} }
}); });


$('.issue-action').click(function () {
$('.issue-action').on('click', function () {
let {action} = this.dataset; let {action} = this.dataset;
let {elementId} = this.dataset; let {elementId} = this.dataset;
const issueIDs = $('.issue-checkbox').children('input:checked').map(function () { const issueIDs = $('.issue-checkbox').children('input:checked').map(function () {
// trigger ckecked event, if checkboxes are checked on load // trigger ckecked event, if checkboxes are checked on load
$('.issue-checkbox input[type="checkbox"]:checked').first().each((_, e) => { $('.issue-checkbox input[type="checkbox"]:checked').first().each((_, e) => {
e.checked = false; e.checked = false;
$(e).click();
$(e).trigger('click');
}); });


$('.resolve-conversation').on('click', function (e) { $('.resolve-conversation').on('click', function (e) {
if ($('#repo-clone-url').length > 0) { if ($('#repo-clone-url').length > 0) {
switch (localStorage.getItem('repo-clone-protocol')) { switch (localStorage.getItem('repo-clone-protocol')) {
case 'ssh': case 'ssh':
if ($('#repo-clone-ssh').click().length === 0) {
$('#repo-clone-https').click();
if ($('#repo-clone-ssh').length === 0) {
$('#repo-clone-https').trigger('click');
} }
break; break;
default: default:
$('#repo-clone-https').click();
$('#repo-clone-https').trigger('click');
break; break;
} }
} }
} }


const $cloneAddr = $('#clone_addr'); const $cloneAddr = $('#clone_addr');
$cloneAddr.change(() => {
$cloneAddr.on('change', () => {
const $repoName = $('#repo_name'); const $repoName = $('#repo_name');
if ($cloneAddr.val().length > 0 && $repoName.val().length === 0) { // Only modify if repo_name input is blank if ($cloneAddr.val().length > 0 && $repoName.val().length === 0) { // Only modify if repo_name input is blank
$repoName.val($cloneAddr.val().match(/^(.*\/)?((.+?)(\.git)?)$/)[3]); $repoName.val($cloneAddr.val().match(/^(.*\/)?((.+?)(\.git)?)$/)[3]);
closable: false, closable: false,
onApprove() { onApprove() {
if ($this.data('type') === 'form') { if ($this.data('type') === 'form') {
$($this.data('form')).submit();
$($this.data('form')).trigger('submit');
return; return;
} }


closable: false, closable: false,
onApprove() { onApprove() {
if ($this.data('type') === 'form') { if ($this.data('type') === 'form') {
$($this.data('form')).submit();
$($this.data('form')).trigger('submit');
return; return;
} }


} }


function initCtrlEnterSubmit() { function initCtrlEnterSubmit() {
$('.js-quick-submit').keydown(function (e) {
$('.js-quick-submit').on('keydown', function (e) {
if (((e.ctrlKey && !e.altKey) || e.metaKey) && (e.keyCode === 13 || e.keyCode === 10)) { if (((e.ctrlKey && !e.altKey) || e.metaKey) && (e.keyCode === 13 || e.keyCode === 10)) {
$(this).closest('form').submit();
$(this).closest('form').trigger('submit');
} }
}); });
} }
.modal({ .modal({
duration: 200, duration: 200,
onApprove() { onApprove() {
$('#add_time_manual_form').submit();
$('#add_time_manual_form').trigger('submit');
} }
}).modal('show'); }).modal('show');
}; };


window.toggleStopwatch = function () { window.toggleStopwatch = function () {
$('#toggle_stopwatch_form').submit();
$('#toggle_stopwatch_form').trigger('submit');
}; };
window.cancelStopwatch = function () { window.cancelStopwatch = function () {
$('#cancel_stopwatch_form').submit();
$('#cancel_stopwatch_form').trigger('submit');
}; };


function initFilterBranchTagDropdown(selector) { function initFilterBranchTagDropdown(selector) {
if (!this.showCreateNewBranch) { if (!this.showCreateNewBranch) {
return; return;
} }
this.$refs.newBranchForm.submit();
this.$refs.newBranchForm.trigger('submit');
}, },
focusSearchField() { focusSearchField() {
const vm = this; const vm = this;
}); });
} }


$('.commit-button').click(function (e) {
$('.commit-button').on('click', function (e) {
e.preventDefault(); e.preventDefault();
$(this).parent().find('.commit-body').toggle(); $(this).parent().find('.commit-body').toggle();
}); });
const content = $('#navbar'); const content = $('#navbar');
const toggle = $('#navbar-expand-toggle'); const toggle = $('#navbar-expand-toggle');
let isExpanded = false; let isExpanded = false;
toggle.click(() => {
toggle.on('click', () => {
isExpanded = !isExpanded; isExpanded = !isExpanded;
if (isExpanded) { if (isExpanded) {
content.addClass('shown'); content.addClass('shown');
const topicForm = $('#topic_edit.ui.form'); const topicForm = $('#topic_edit.ui.form');
const topicPrompts = getPrompts(); const topicPrompts = getPrompts();


mgrBtn.click(() => {
mgrBtn.on('click', () => {
viewDiv.hide(); viewDiv.hide();
editDiv.css('display', ''); // show Semantic UI Grid editDiv.css('display', ''); // show Semantic UI Grid
}); });
return prompts; return prompts;
} }


saveBtn.click(() => {
saveBtn.on('click', () => {
const topics = $('input[name=topics]').val(); const topics = $('input[name=topics]').val();


$.post(saveBtn.data('link'), { $.post(saveBtn.data('link'), {
onApprove() { onApprove() {
$('#removeDependencyID').val(id); $('#removeDependencyID').val(id);
$('#dependencyType').val(type); $('#dependencyType').val(type);
$('#removeDependencyForm').submit();
$('#removeDependencyForm').trigger('submit');
} }
}).modal('show'); }).modal('show');
}; };
}); });


$('.menu a.label-filter-item').each(function () { $('.menu a.label-filter-item').each(function () {
$(this).click(function (e) {
$(this).on('click', function (e) {
if (e.altKey) { if (e.altKey) {
e.preventDefault(); e.preventDefault();


}); });
}); });


$('.menu .ui.dropdown.label-filter').keydown((e) => {
$('.menu .ui.dropdown.label-filter').on('keydown', (e) => {
if (e.altKey && e.keyCode === 13) { if (e.altKey && e.keyCode === 13) {
const selectedItems = $('.menu .ui.dropdown.label-filter .menu .item.selected'); const selectedItems = $('.menu .ui.dropdown.label-filter .menu .item.selected');


window.submitReply = function (btn) { window.submitReply = function (btn) {
const form = $(btn).closest('form'); const form = $(btn).closest('form');
if (form.length > 0 && form.hasClass('comment-form')) { if (form.length > 0 && form.hasClass('comment-form')) {
form.submit();
form.trigger('submit');
} }
}; };



+ 0
- 2
web_src/js/jquery.js 查看文件

import $ from 'jquery'; import $ from 'jquery';
import 'jquery-migrate';


$.migrateMute = true;
window.$ = window.jQuery = $; window.$ = window.jQuery = $;

Loading…
取消
儲存