This repository has been archived on 2024-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
forgejo/web_src/js/features/contextpopup.js

41 lines
1 KiB
JavaScript
Raw Normal View History

import $ from 'jquery';
import {createApp} from 'vue';
import ContextPopup from '../components/ContextPopup.vue';
import {parseIssueHref} from '../utils.js';
import {createTippy} from '../modules/tippy.js';
export function initContextPopups() {
const refIssues = $('.ref-issue');
if (!refIssues.length) return;
refIssues.each(function () {
if ($(this).hasClass('ref-external-issue')) {
return;
}
const {owner, repo, index} = parseIssueHref($(this).attr('href'));
if (!owner) return;
const el = document.createElement('div');
this.parentNode.insertBefore(el, this.nextSibling);
const view = createApp(ContextPopup);
try {
view.mount(el);
} catch (err) {
console.error(err);
el.textContent = 'ContextPopup failed to load';
}
createTippy(this, {
content: el,
interactive: true,
interactiveBorder: 5,
onShow: () => {
el.firstChild.dispatchEvent(new CustomEvent('ce-load-context-popup', {detail: {owner, repo, index}}));
}
});
});
}