Skip to content

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

@derekhu

Description

@derekhu

$(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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions