summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pages/projects/commit/show/index.js
blob: d5fb2a8be3c5da5081c633bcddd798b230bf389c (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
44
45
46
47
48
49
50
51
52
53
/* eslint-disable no-new */

import $ from 'jquery';
import Diff from '~/diff';
import ZenMode from '~/zen_mode';
import ShortcutsNavigation from '~/behaviors/shortcuts/shortcuts_navigation';
import MiniPipelineGraph from '~/mini_pipeline_graph_dropdown';
import initNotes from '~/init_notes';
import initChangesDropdown from '~/init_changes_dropdown';
import { fetchCommitMergeRequests } from '~/commit_merge_requests';
import '~/sourcegraph/load';
import { handleLocationHash } from '~/lib/utils/common_utils';
import axios from '~/lib/utils/axios_utils';
import syntaxHighlight from '~/syntax_highlight';
import flash from '~/flash';
import { __ } from '~/locale';
import loadAwardsHandler from '~/awards_handler';

document.addEventListener('DOMContentLoaded', () => {
  const hasPerfBar = document.querySelector('.with-performance-bar');
  const performanceHeight = hasPerfBar ? 35 : 0;
  initChangesDropdown(document.querySelector('.navbar-gitlab').offsetHeight + performanceHeight);
  new ZenMode();
  new ShortcutsNavigation();
  new MiniPipelineGraph({
    container: '.js-commit-pipeline-graph',
  }).bindEvents();
  initNotes();
  // eslint-disable-next-line no-jquery/no-load
  $('.commit-info.branches').load(document.querySelector('.js-commit-box').dataset.commitPath);
  fetchCommitMergeRequests();

  const filesContainer = $('.js-diffs-batch');

  if (filesContainer.length) {
    const batchPath = filesContainer.data('diffFilesPath');

    axios
      .get(batchPath)
      .then(({ data }) => {
        filesContainer.html($(data.html));
        syntaxHighlight(filesContainer);
        handleLocationHash();
        new Diff();
      })
      .catch(() => {
        flash(__('An error occurred while retrieving diff files'));
      });
  } else {
    new Diff();
  }
  loadAwardsHandler();
});