-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Remove jQuery .attr
from the commit graph
#30006
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
Changes from 2 commits
d4af6c0
5d11f86
cca306b
258df41
80c4555
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,27 +18,27 @@ export function initRepoGraphGit() { | |
window.history.replaceState({}, '', window.location.pathname); | ||
} | ||
$('.pagination a').each((_, that) => { | ||
const href = $(that).attr('href'); | ||
const href = that.href; | ||
if (!href) return; | ||
const url = new URL(href, window.location); | ||
const params = url.searchParams; | ||
params.set('mode', 'monochrome'); | ||
url.search = `?${params.toString()}`; | ||
$(that).attr('href', url.href); | ||
that.href = url.href; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see @wxiaoguang suggests the opposite. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you elaborate, what's the difference? https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/href There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wxiaoguang see #29931 (comment). There I came to the conclusion it's better to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the difference: console.log(a.href);
// https://fiddle.jshell.net/_display/?editor_console=true#%E6%B0%94%E5%80%99%E5%AE%9C%E4%BA%BA
console.log(a.getAttribute("href"));
// #气候宜人
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The method to choose depends on use case whether absolute escaped or relative unicode URL is needed. We should just do what jQuery did before. @yardenshoham could you debug it out what jQuery did please? I assume it was equivalent to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah so let's change it back so it's a more accurate refactor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
URL also generates the normalized and fully escaped URL: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both will work I assume. That said, this code looks ripe for refactor, these two functions are almost completely the same. |
||
}); | ||
}); | ||
$('#flow-color-colored').on('click', () => { | ||
$('#flow-color-colored').addClass('active'); | ||
$('#flow-color-monochrome').removeClass('active'); | ||
$('#git-graph-container').addClass('colored').removeClass('monochrome'); | ||
$('.pagination a').each((_, that) => { | ||
const href = $(that).attr('href'); | ||
const href = that.href; | ||
if (!href) return; | ||
const url = new URL(href, window.location); | ||
const params = url.searchParams; | ||
params.delete('mode'); | ||
url.search = `?${params.toString()}`; | ||
$(that).attr('href', url.href); | ||
that.href = url.href; | ||
}); | ||
const params = new URLSearchParams(window.location.search); | ||
params.delete('mode'); | ||
|
Uh oh!
There was an error while loading. Please reload this page.