2022-10-01 16:26:38 +02:00
|
|
|
import {createApp} from 'vue';
|
2021-07-13 21:09:19 +03:00
|
|
|
import ContextPopup from '../components/ContextPopup.vue';
|
2021-10-22 22:34:01 +08:00
|
|
|
import {parseIssueHref} from '../utils.js';
|
2022-07-19 00:33:34 +02:00
|
|
|
import {createTippy} from '../modules/tippy.js';
|
2020-02-11 19:53:18 -06:00
|
|
|
|
2022-12-23 17:03:11 +01:00
|
|
|
export function initContextPopups() {
|
2024-02-17 15:11:56 +02:00
|
|
|
const refIssues = document.querySelectorAll('.ref-issue');
|
2023-04-03 16:02:57 +08:00
|
|
|
attachRefIssueContextPopup(refIssues);
|
|
|
|
|
}
|
2020-01-19 22:39:21 -06:00
|
|
|
|
2023-04-03 16:02:57 +08:00
|
|
|
export function attachRefIssueContextPopup(refIssues) {
|
2023-04-03 18:06:57 +08:00
|
|
|
for (const refIssue of refIssues) {
|
|
|
|
|
if (refIssue.classList.contains('ref-external-issue')) {
|
2021-09-15 09:45:27 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2021-10-22 22:34:01 +08:00
|
|
|
|
2023-04-03 18:06:57 +08:00
|
|
|
const {owner, repo, index} = parseIssueHref(refIssue.getAttribute('href'));
|
2021-10-22 22:34:01 +08:00
|
|
|
if (!owner) return;
|
2020-01-19 22:39:21 -06:00
|
|
|
|
2021-07-13 21:09:19 +03:00
|
|
|
const el = document.createElement('div');
|
2024-04-30 16:52:46 +02:00
|
|
|
el.classList.add('tw-p-3');
|
2023-04-03 18:06:57 +08:00
|
|
|
refIssue.parentNode.insertBefore(el, refIssue.nextSibling);
|
2020-01-19 22:39:21 -06:00
|
|
|
|
2022-10-01 16:26:38 +02:00
|
|
|
const view = createApp(ContextPopup);
|
2020-01-19 22:39:21 -06:00
|
|
|
|
2021-07-13 21:09:19 +03:00
|
|
|
try {
|
2022-10-01 16:26:38 +02:00
|
|
|
view.mount(el);
|
2021-07-13 21:09:19 +03:00
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
el.textContent = 'ContextPopup failed to load';
|
2020-01-19 22:39:21 -06:00
|
|
|
}
|
|
|
|
|
|
2023-04-03 18:06:57 +08:00
|
|
|
createTippy(refIssue, {
|
2024-04-30 16:52:46 +02:00
|
|
|
theme: 'default',
|
2022-07-19 00:33:34 +02:00
|
|
|
content: el,
|
2023-03-23 17:56:15 +08:00
|
|
|
placement: 'top-start',
|
2022-07-19 00:33:34 +02:00
|
|
|
interactive: true,
|
2023-06-15 16:09:16 +08:00
|
|
|
role: 'dialog',
|
2023-03-05 23:40:50 +08:00
|
|
|
interactiveBorder: 5,
|
2021-07-13 21:09:19 +03:00
|
|
|
onShow: () => {
|
2023-03-05 22:23:42 +08:00
|
|
|
el.firstChild.dispatchEvent(new CustomEvent('ce-load-context-popup', {detail: {owner, repo, index}}));
|
2024-03-22 15:06:53 +01:00
|
|
|
},
|
2020-01-19 22:39:21 -06:00
|
|
|
});
|
2023-04-03 18:06:57 +08:00
|
|
|
}
|
2020-01-19 22:39:21 -06:00
|
|
|
}
|