-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Remove jQuery .attr
from the commit graph
#30006
Remove jQuery .attr
from the commit graph
#30006
Conversation
Switched from jQuery `.attr` to plain javascript `.getAttribute` and `.setAttribute` Signed-off-by: Yarden Shoham <[email protected]>
I didn't test this one as I couldn't find a way to render the pagination buttons because my browser always crashes on this page for big repositories |
web_src/js/features/repo-graph.js
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Use setAttribute
instead of href
. There are slight differences in those two methods in how the URL encodes as I recently noticed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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 comment
The 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 setAttribute
and getAttribute
when working with href
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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"));
// #气候宜人
href
can not deal with unicode and resolves to absolute URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think so. el.href is the normalized and correctly escaped full URL. It could just be used as-is.
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 getAttribute
and setAttribute
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
In your example,
a.setAttribute("href", "#气候宜人")
you are setting a invalid URL tohref
. So when you read theel.href
again, it gets correctly escaped.It's not a invalid URL as
URL
constructor accepts it:
URL also generates the normalized and fully escaped URL: href: 'https://example.com/#%E6%B0%94%E5%80%99%E5%AE%9C%E4%BA%BA'
. So I insist el.href
is the right thing to be directly used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
This reverts commit 5d11f86.
* giteaofficial/main: (28 commits) Enable a few stylelint rules (go-gitea#30038) Remove remaining jQuery .css code (go-gitea#30015) Respect DEFAULT_ORG_MEMBER_VISIBLE setting when adding creator to org (go-gitea#30013) Remove jQuery `.attr` from the common global functions (go-gitea#30023) Migrate font-size helpers to tailwind (go-gitea#30029) Replace all simple inline styles with tailwind (go-gitea#30032) Migrate font-weight helpers to tailwind (go-gitea#30027) Remove jQuery from the issue "go to" button (go-gitea#30028) Determine fuzziness of bleve indexer by keyword length (go-gitea#29706) Escape paths for find file correctly (go-gitea#30026) Remove jQuery `.attr` from the diff page (go-gitea#30021) Remove jQuery `.attr` from the repository settings (go-gitea#30018) Remove jQuery `.attr` from the image diff again (go-gitea#30022) Introduce `.secondary-nav` and handle `.page-content` spacing universally (go-gitea#29982) Remove jQuery `.attr` from the branch/tag selector (go-gitea#30010) Remove jQuery `.attr` from the commit graph (go-gitea#30006) Remove jQuery from the citation modal (except fomantic) (go-gitea#30008) Remove jQuery `.attr` from the project page (go-gitea#30004) Fix incorrect tailwind migration (go-gitea#30007) Enforce trailing comma in JS on multiline (go-gitea#30002) ...
Switched from jQuery
.attr
to plain javascript.getAttribute
and.setAttribute