summaryrefslogtreecommitdiffstats
path: root/web_src/js/features/contextpopup.js
blob: 8583c6253cd9f99526bf30fd902471b4a3d75c7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Vue from 'vue';

import ContextPopup from '../components/ContextPopup.vue';

export default function initContextPopups() {
  const refIssues = $('.ref-issue');
  if (!refIssues.length) return;

  refIssues.each(function () {
    const [index, _issues, repo, owner] = $(this).attr('href').replace(/[#?].*$/, '').split('/').reverse();

    const el = document.createElement('div');
    el.className = 'ui custom popup hidden';
    el.innerHTML = '<div></div>';
    this.parentNode.insertBefore(el, this.nextSibling);

    const View = Vue.extend({
      render: (createElement) => createElement(ContextPopup),
    });

    const view = new View();

    try {
      view.$mount(el.firstChild);
    } catch (err) {
      console.error(err);
      el.textContent = 'ContextPopup failed to load';
    }

    $(this).popup({
      variation: 'wide',
      delay: {
        show: 250
      },
      onShow: () => {
        view.$emit('load-context-popup', {owner, repo, index}, () => {
          $(this).popup('reposition');
        });
      },
      popup: $(el),
    });
  });
}