summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/blob_edit/blob_bundle.js
blob: b5500ac116f7b5f1b24c2f3048837eceaf7011d7 (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
/* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, no-var, quotes, vars-on-top, no-unused-vars, no-new, max-len */
/* global EditBlob */
/* global NewCommitForm */

import EditBlob from './edit_blob';
import BlobFileDropzone from '../blob/blob_file_dropzone';

$(() => {
  const editBlobForm = $('.js-edit-blob-form');
  const uploadBlobForm = $('.js-upload-blob-form');
  const deleteBlobForm = $('.js-delete-blob-form');

  if (editBlobForm.length) {
    const urlRoot = editBlobForm.data('relative-url-root');
    const assetsPath = editBlobForm.data('assets-prefix');
    const blobLanguage = editBlobForm.data('blob-language');
    const currentAction = $('.js-file-title').data('current-action');

    new EditBlob(`${urlRoot}${assetsPath}`, blobLanguage, currentAction);
    new NewCommitForm(editBlobForm);
  }

  if (uploadBlobForm.length) {
    const method = uploadBlobForm.data('method');

    new BlobFileDropzone(uploadBlobForm, method);
    new NewCommitForm(uploadBlobForm);

    window.gl.utils.disableButtonIfEmptyField(
      uploadBlobForm.find('.js-commit-message'),
      '.btn-upload-file',
    );
  }

  if (deleteBlobForm.length) {
    new NewCommitForm(deleteBlobForm);
  }
});