2022-01-29 00:00:11 +03:00
|
|
|
import $ from 'jquery';
|
2022-10-01 17:26:38 +03:00
|
|
|
import {createApp} from 'vue';
|
2021-07-13 21:09:19 +03:00
|
|
|
import ContextPopup from '../components/ContextPopup.vue';
|
2021-10-22 17:34:01 +03:00
|
|
|
import {parseIssueHref} from '../utils.js';
|
2022-07-19 01:33:34 +03:00
|
|
|
import {createTippy} from '../modules/tippy.js';
|
2020-02-12 04:53:18 +03:00
|
|
|
|
|
|
|
export default function initContextPopups() {
|
2020-01-20 07:39:21 +03:00
|
|
|
const refIssues = $('.ref-issue');
|
|
|
|
if (!refIssues.length) return;
|
|
|
|
|
|
|
|
refIssues.each(function () {
|
2021-09-15 11:45:27 +03:00
|
|
|
if ($(this).hasClass('ref-external-issue')) {
|
|
|
|
return;
|
|
|
|
}
|
2021-10-22 17:34:01 +03:00
|
|
|
|
|
|
|
const {owner, repo, index} = parseIssueHref($(this).attr('href'));
|
|
|
|
if (!owner) return;
|
2020-01-20 07:39:21 +03:00
|
|
|
|
2021-07-13 21:09:19 +03:00
|
|
|
const el = document.createElement('div');
|
|
|
|
this.parentNode.insertBefore(el, this.nextSibling);
|
2020-01-20 07:39:21 +03:00
|
|
|
|
2022-10-01 17:26:38 +03:00
|
|
|
const view = createApp(ContextPopup);
|
2020-01-20 07:39:21 +03:00
|
|
|
|
2021-07-13 21:09:19 +03:00
|
|
|
try {
|
2022-10-01 17:26:38 +03: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-20 07:39:21 +03:00
|
|
|
}
|
|
|
|
|
2022-07-19 01:33:34 +03:00
|
|
|
createTippy(this, {
|
|
|
|
content: el,
|
|
|
|
interactive: true,
|
2021-07-13 21:09:19 +03:00
|
|
|
onShow: () => {
|
2022-10-01 17:26:38 +03:00
|
|
|
el.firstChild.dispatchEvent(new CustomEvent('us-load-context-popup', {detail: {owner, repo, index}}));
|
2022-07-19 01:33:34 +03:00
|
|
|
}
|
2020-01-20 07:39:21 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|