summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/init_diff_stats_dropdown.js
blob: 27df761a10308f5bb69cfd53be3f280e5bbb5a9b (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
import Vue from 'vue';
import DiffStatsDropdown from '~/vue_shared/components/diff_stats_dropdown.vue';
import { stickyMonitor } from './lib/utils/sticky';

export const initDiffStatsDropdown = (stickyTop) => {
  if (stickyTop) {
    stickyMonitor(document.querySelector('.js-diff-files-changed'), stickyTop);
  }

  const el = document.querySelector('.js-diff-stats-dropdown');

  if (!el) {
    return false;
  }

  const { changed, added, deleted, files } = el.dataset;

  return new Vue({
    el,
    render: (createElement) =>
      createElement(DiffStatsDropdown, {
        props: {
          changed: parseInt(changed, 10),
          added: parseInt(added, 10),
          deleted: parseInt(deleted, 10),
          files: JSON.parse(files),
        },
      }),
  });
};