2022-01-29 05:00:11 +08:00
|
|
|
import $ from 'jquery';
|
2022-10-01 22:26:38 +08:00
|
|
|
import {createApp} from 'vue';
|
2021-07-14 02:09:19 +08:00
|
|
|
import ContextPopup from '../components/ContextPopup.vue';
|
2021-10-22 22:34:01 +08:00
|
|
|
import {parseIssueHref} from '../utils.js';
|
2022-07-19 06:33:34 +08:00
|
|
|
import {createTippy} from '../modules/tippy.js';
|
2020-02-12 09:53:18 +08:00
|
|
|
|
2022-12-24 00:03:11 +08:00
|
|
|
export function initContextPopups() {
|
2020-01-20 12:39:21 +08:00
|
|
|
const refIssues = $('.ref-issue');
|
|
|
|
if (!refIssues.length) return;
|
|
|
|
|
|
|
|
refIssues.each(function () {
|
2021-09-15 16:45:27 +08:00
|
|
|
if ($(this).hasClass('ref-external-issue')) {
|
|
|
|
return;
|
|
|
|
}
|
2021-10-22 22:34:01 +08:00
|
|
|
|
|
|
|
const {owner, repo, index} = parseIssueHref($(this).attr('href'));
|
|
|
|
if (!owner) return;
|
2020-01-20 12:39:21 +08:00
|
|
|
|
2021-07-14 02:09:19 +08:00
|
|
|
const el = document.createElement('div');
|
|
|
|
this.parentNode.insertBefore(el, this.nextSibling);
|
2020-01-20 12:39:21 +08:00
|
|
|
|
2022-10-01 22:26:38 +08:00
|
|
|
const view = createApp(ContextPopup);
|
2020-01-20 12:39:21 +08:00
|
|
|
|
2021-07-14 02:09:19 +08:00
|
|
|
try {
|
2022-10-01 22:26:38 +08:00
|
|
|
view.mount(el);
|
2021-07-14 02:09:19 +08:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
el.textContent = 'ContextPopup failed to load';
|
2020-01-20 12:39:21 +08:00
|
|
|
}
|
|
|
|
|
2022-07-19 06:33:34 +08:00
|
|
|
createTippy(this, {
|
|
|
|
content: el,
|
|
|
|
interactive: true,
|
2021-07-14 02:09:19 +08:00
|
|
|
onShow: () => {
|
2023-03-05 22:23:42 +08:00
|
|
|
el.firstChild.dispatchEvent(new CustomEvent('ce-load-context-popup', {detail: {owner, repo, index}}));
|
2022-07-19 06:33:34 +08:00
|
|
|
}
|
2020-01-20 12:39:21 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|