Skip to content

[UI] Add namespace to global click event , index.js #15687

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

Closed
derekhu opened this issue May 1, 2021 · 3 comments
Closed

[UI] Add namespace to global click event , index.js #15687

derekhu opened this issue May 1, 2021 · 3 comments

Comments

@derekhu
Copy link

derekhu commented May 1, 2021

$(document).on('click', (event) => {

  $(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>
@zeripath
Copy link
Contributor

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:

  1. Go to https://try.gitea.io/owner/repo/issue/6#comment-id
  2. Click anywhere
  3. Note that the hash disappears from the URL bar
  4. I expected the hash to stay

@derekhu
Copy link
Author

derekhu commented 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:

  1. Go to https://try.gitea.io/owner/repo/issue/6#comment-id
  2. Click anywhere
  3. Note that the hash disappears from the URL bar
  4. I expected the hash to stay

yeah, exact

derekhu added a commit to derekhu/gitea that referenced this issue Aug 27, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@wxiaoguang
Copy link
Contributor

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.

@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants