2022-01-29 02:30:11 +05:30
|
|
|
import $ from 'jquery';
|
2021-07-13 23:39:19 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import ContextPopup from '../components/ContextPopup.vue';
|
2021-10-22 20:04:01 +05:30
|
|
|
import {parseIssueHref} from '../utils.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');
|
|
|
|
el.className = 'ui custom popup hidden';
|
|
|
|
el.innerHTML = '<div></div>';
|
|
|
|
this.parentNode.insertBefore(el, this.nextSibling);
|
2020-01-20 10:09:21 +05:30
|
|
|
|
2021-07-13 23:39:19 +05:30
|
|
|
const View = Vue.extend({
|
|
|
|
render: (createElement) => createElement(ContextPopup),
|
|
|
|
});
|
2020-01-20 10:09:21 +05:30
|
|
|
|
2021-07-13 23:39:19 +05:30
|
|
|
const view = new View();
|
2020-01-20 10:09:21 +05:30
|
|
|
|
2021-07-13 23:39:19 +05:30
|
|
|
try {
|
|
|
|
view.$mount(el.firstChild);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
el.textContent = 'ContextPopup failed to load';
|
2020-01-20 10:09:21 +05:30
|
|
|
}
|
|
|
|
|
2021-07-13 23:39:19 +05:30
|
|
|
$(this).popup({
|
2020-01-20 10:09:21 +05:30
|
|
|
variation: 'wide',
|
|
|
|
delay: {
|
|
|
|
show: 250
|
|
|
|
},
|
2021-07-13 23:39:19 +05:30
|
|
|
onShow: () => {
|
|
|
|
view.$emit('load-context-popup', {owner, repo, index}, () => {
|
|
|
|
$(this).popup('reposition');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
popup: $(el),
|
2020-01-20 10:09:21 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|