-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Remove jQuery from the repo commit functions #29230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
169a9b5
Remove jQuery from repo commit functions
yardenshoham 629da54
Update web_src/js/features/repo-commit.js
yardenshoham 066bc43
Merge branch 'main' into repo-commit-jquery
yardenshoham 048159f
Use `outerHTML`
yardenshoham 09ea44d
Use replaceWith if it's a node
yardenshoham b0f02f3
Merge remote-tracking branch 'upstream/main' into repo-commit-jquery
yardenshoham 2b34062
Fix
yardenshoham 993afbb
Merge branch 'main' into repo-commit-jquery
yardenshoham 93c2935
Merge remote-tracking branch 'upstream/main' into repo-commit-jquery
yardenshoham 2998713
Update web_src/js/features/repo-commit.js
yardenshoham 3b51cd3
Merge branch 'main' into repo-commit-jquery
yardenshoham 6da52e0
Lint
yardenshoham c612070
Merge branch 'main' into repo-commit-jquery
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,70 @@ | ||
import $ from 'jquery'; | ||
import {createTippy} from '../modules/tippy.js'; | ||
import {toggleElem} from '../utils/dom.js'; | ||
|
||
const {csrfToken} = window.config; | ||
import {parseDom} from '../utils.js'; | ||
import {POST} from '../modules/fetch.js'; | ||
|
||
export function initRepoEllipsisButton() { | ||
$('.js-toggle-commit-body').on('click', function (e) { | ||
e.preventDefault(); | ||
const expanded = $(this).attr('aria-expanded') === 'true'; | ||
toggleElem($(this).parent().find('.commit-body')); | ||
$(this).attr('aria-expanded', String(!expanded)); | ||
}); | ||
for (const button of document.querySelectorAll('.js-toggle-commit-body')) { | ||
button.addEventListener('click', function (e) { | ||
e.preventDefault(); | ||
const expanded = this.getAttribute('aria-expanded') === 'true'; | ||
toggleElem(this.parentElement.querySelector('.commit-body')); | ||
this.setAttribute('aria-expanded', String(!expanded)); | ||
}); | ||
} | ||
} | ||
|
||
export function initRepoCommitLastCommitLoader() { | ||
const notReadyEls = document.querySelectorAll('table#repo-files-table tr.notready'); | ||
if (!notReadyEls.length) return; | ||
|
||
export async function initRepoCommitLastCommitLoader() { | ||
const entryMap = {}; | ||
const entries = []; | ||
for (const el of notReadyEls) { | ||
const entryname = el.getAttribute('data-entryname'); | ||
entryMap[entryname] = $(el); | ||
entries.push(entryname); | ||
|
||
const entries = Array.from(document.querySelectorAll('table#repo-files-table tr.notready'), (el) => { | ||
const entryName = el.getAttribute('data-entryname'); | ||
entryMap[entryName] = el; | ||
return entryName; | ||
}); | ||
|
||
if (entries.length === 0) { | ||
return; | ||
} | ||
|
||
const lastCommitLoaderURL = $('table#repo-files-table').data('lastCommitLoaderUrl'); | ||
const lastCommitLoaderURL = document.querySelector('table#repo-files-table').getAttribute('data-last-commit-loader-url'); | ||
|
||
if (entries.length > 200) { | ||
$.post(lastCommitLoaderURL, { | ||
_csrf: csrfToken, | ||
}, (data) => { | ||
$('table#repo-files-table').replaceWith(data); | ||
}); | ||
// For more than 200 entries, replace the entire table | ||
const response = await POST(lastCommitLoaderURL); | ||
const data = await response.text(); | ||
document.querySelector('table#repo-files-table').outerHTML = data; | ||
6543 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
} | ||
|
||
$.post(lastCommitLoaderURL, { | ||
_csrf: csrfToken, | ||
'f': entries, | ||
}, (data) => { | ||
$(data).find('tr').each((_, row) => { | ||
if (row.className === 'commit-list') { | ||
$('table#repo-files-table .commit-list').replaceWith(row); | ||
return; | ||
} | ||
// there are other <tr> rows in response (eg: <tr class="has-parent">) | ||
// at the moment only the "data-entryname" rows should be processed | ||
const entryName = $(row).attr('data-entryname'); | ||
if (entryName) { | ||
entryMap[entryName].replaceWith(row); | ||
} | ||
}); | ||
}); | ||
// For fewer entries, update individual rows | ||
const response = await POST(lastCommitLoaderURL, {data: {'f': entries}}); | ||
6543 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const data = await response.text(); | ||
const doc = parseDom(data, 'text/html'); | ||
for (const row of doc.querySelectorAll('tr')) { | ||
if (row.className === 'commit-list') { | ||
document.querySelector('table#repo-files-table .commit-list')?.replaceWith(row); | ||
continue; | ||
} | ||
// there are other <tr> rows in response (eg: <tr class="has-parent">) | ||
// at the moment only the "data-entryname" rows should be processed | ||
const entryName = row.getAttribute('data-entryname'); | ||
if (entryName) { | ||
entryMap[entryName]?.replaceWith(row); | ||
} | ||
} | ||
} | ||
|
||
export function initCommitStatuses() { | ||
$('[data-tippy="commit-statuses"]').each(function () { | ||
const top = $('.repository.file.list').length > 0 || $('.repository.diff').length > 0; | ||
for (const element of document.querySelectorAll('[data-tippy="commit-statuses"]')) { | ||
const top = document.querySelector('.repository.file.list') || document.querySelector('.repository.diff'); | ||
|
||
createTippy(this, { | ||
content: this.nextElementSibling, | ||
createTippy(element, { | ||
content: element.nextElementSibling, | ||
placement: top ? 'top-start' : 'bottom-start', | ||
interactive: true, | ||
role: 'dialog', | ||
theme: 'box-with-header', | ||
}); | ||
}); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.