summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pages/projects/commit/show/index.js
blob: 32fb35f97e346e9a5ebb2597ff6cfee7fc895d50 (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
/* eslint-disable no-new */

import $ from 'jquery';
import Diff from '~/diff';
import ZenMode from '~/zen_mode';
import ShortcutsNavigation from '~/behaviors/shortcuts/shortcuts_navigation';
import initNotes from '~/init_notes';
import initChangesDropdown from '~/init_changes_dropdown';
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';
import { initCommitBoxInfo } from '~/projects/commit_box/info';

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();

  initCommitBoxInfo();

  initNotes();

  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();
});