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