code.gitea.io/gitea@v1.21.7/web_src/js/features/contextpopup.js (about)

     1  import $ from 'jquery';
     2  import {createApp} from 'vue';
     3  import ContextPopup from '../components/ContextPopup.vue';
     4  import {parseIssueHref} from '../utils.js';
     5  import {createTippy} from '../modules/tippy.js';
     6  
     7  export function initContextPopups() {
     8    const refIssues = $('.ref-issue');
     9    attachRefIssueContextPopup(refIssues);
    10  }
    11  
    12  export function attachRefIssueContextPopup(refIssues) {
    13    for (const refIssue of refIssues) {
    14      if (refIssue.classList.contains('ref-external-issue')) {
    15        return;
    16      }
    17  
    18      const {owner, repo, index} = parseIssueHref(refIssue.getAttribute('href'));
    19      if (!owner) return;
    20  
    21      const el = document.createElement('div');
    22      refIssue.parentNode.insertBefore(el, refIssue.nextSibling);
    23  
    24      const view = createApp(ContextPopup);
    25  
    26      try {
    27        view.mount(el);
    28      } catch (err) {
    29        console.error(err);
    30        el.textContent = 'ContextPopup failed to load';
    31      }
    32  
    33      createTippy(refIssue, {
    34        content: el,
    35        placement: 'top-start',
    36        interactive: true,
    37        role: 'dialog',
    38        interactiveBorder: 5,
    39        onShow: () => {
    40          el.firstChild.dispatchEvent(new CustomEvent('ce-load-context-popup', {detail: {owner, repo, index}}));
    41        }
    42      });
    43    }
    44  }