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