Closed
Description
Line 688 in 5811e16
$(document).on('click', (event) => {
const urlTarget = $(':target');
if (urlTarget.length === 0) return;
const urlTargetId = urlTarget.attr('id');
if (!urlTargetId) return;
if (!/^(issue|pull)(comment)?-\d+$/.test(urlTargetId)) return;
const $target = $(event.target);
if ($target.closest(`#${urlTargetId}`).length === 0) {
const scrollPosition = $(window).scrollTop();
window.location.hash = '';
$(window).scrollTop(scrollPosition);
window.history.pushState(null, null, ' ');
}
});
This block of code performaces different UI experience with Gitlab issue comment.
When I got focus on certain comment, it gets highlight and hash changed ok.
And when click blank place in the page, the hash changes to empty.
However, I want to keep the same experience as Gitlab done: keep the #hash .
I can .off() the global document click event, if the code provides events namespace, and I only have to add custom code in foot.tmpl instead of replace and modify the whole index.js.
eg: index.js
$(document).on('click.syncemptyhash' , ... ) // or any namespace you like
...
eg:custom,foot.tmpl
<script>
$(document).off('click.syncemptyhash')
</script>
Activity
zeripath commentedon May 11, 2021
Pop up a PR if you can.
I haven't completely understood what the problem is from your issue report. It would be good if you could give us some clear steps to reproduce the issue using try.gitea.io telling us what you expected instead.
Is it something like:
derekhu commentedon May 11, 2021
yeah, exact
Add namespace to global click event
wxiaoguang commentedon Nov 19, 2021
I think the behavior can be fixed by a
capture
event listener.https://stackoverflow.com/questions/12462721/does-stoppropgation-stop-the-event-from-propagating-in-the-capture-phase
Then we do not need to add event namespaces one by one.
I will close this issue and PR, feel free to feedback.