2022-01-28 14:00:11 -07:00
|
|
|
import $ from 'jquery';
|
2021-07-13 11:09:19 -07:00
|
|
|
import Vue from 'vue';
|
|
|
|
import ContextPopup from '../components/ContextPopup.vue';
|
2021-10-22 07:34:01 -07:00
|
|
|
import {parseIssueHref} from '../utils.js';
|
2020-02-11 18:53:18 -07:00
|
|
|
|
|
|
|
export default function initContextPopups() {
|
2020-01-19 21:39:21 -07:00
|
|
|
const refIssues = $('.ref-issue');
|
|
|
|
if (!refIssues.length) return;
|
|
|
|
|
|
|
|
refIssues.each(function () {
|
2021-09-15 01:45:27 -07:00
|
|
|
if ($(this).hasClass('ref-external-issue')) {
|
|
|
|
return;
|
|
|
|
}
|
2021-10-22 07:34:01 -07:00
|
|
|
|
|
|
|
const {owner, repo, index} = parseIssueHref($(this).attr('href'));
|
|
|
|
if (!owner) return;
|
2020-01-19 21:39:21 -07:00
|
|
|
|
2021-07-13 11:09:19 -07:00
|
|
|
const el = document.createElement('div');
|
|
|
|
el.className = 'ui custom popup hidden';
|
|
|
|
el.innerHTML = '<div></div>';
|
|
|
|
this.parentNode.insertBefore(el, this.nextSibling);
|
2020-01-19 21:39:21 -07:00
|
|
|
|
2021-07-13 11:09:19 -07:00
|
|
|
const View = Vue.extend({
|
|
|
|
render: (createElement) => createElement(ContextPopup),
|
|
|
|
});
|
2020-01-19 21:39:21 -07:00
|
|
|
|
2021-07-13 11:09:19 -07:00
|
|
|
const view = new View();
|
2020-01-19 21:39:21 -07:00
|
|
|
|
2021-07-13 11:09:19 -07:00
|
|
|
try {
|
|
|
|
view.$mount(el.firstChild);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
el.textContent = 'ContextPopup failed to load';
|
2020-01-19 21:39:21 -07:00
|
|
|
}
|
|
|
|
|
2021-07-13 11:09:19 -07:00
|
|
|
$(this).popup({
|
2020-01-19 21:39:21 -07:00
|
|
|
variation: 'wide',
|
|
|
|
delay: {
|
|
|
|
show: 250
|
|
|
|
},
|
2021-07-13 11:09:19 -07:00
|
|
|
onShow: () => {
|
|
|
|
view.$emit('load-context-popup', {owner, repo, index}, () => {
|
|
|
|
$(this).popup('reposition');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
popup: $(el),
|
2020-01-19 21:39:21 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|