gitlab-org--gitlab-foss/app/assets/javascripts/blob_edit/blob_bundle.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-06-16 13:20:30 +00:00
/* eslint-disable no-new */
import $ from 'jquery';
2017-11-20 20:28:29 +00:00
import NewCommitForm from '../new_commit_form';
import EditBlob from './edit_blob';
import BlobFileDropzone from '../blob/blob_file_dropzone';
2018-02-21 20:22:56 +00:00
export default () => {
const editBlobForm = $('.js-edit-blob-form');
const uploadBlobForm = $('.js-upload-blob-form');
2017-08-01 08:50:59 +00:00
const deleteBlobForm = $('.js-delete-blob-form');
if (editBlobForm.length) {
2018-02-20 22:20:48 +00:00
const urlRoot = editBlobForm.data('relativeUrlRoot');
const assetsPath = editBlobForm.data('assetsPrefix');
const filePath = `${editBlobForm.data('blobFilename')}`;
2018-02-20 22:20:48 +00:00
const currentAction = $('.js-file-title').data('currentAction');
2018-10-02 23:00:38 +00:00
const projectId = editBlobForm.data('project-id');
const isMarkdown = editBlobForm.data('is-markdown');
const commitButton = $('.js-commit-button');
const cancelLink = $('.btn.btn-cancel');
cancelLink.on('click', () => {
window.onbeforeunload = null;
});
commitButton.on('click', () => {
window.onbeforeunload = null;
});
new EditBlob({
assetsPath: `${urlRoot}${assetsPath}`,
filePath,
currentAction,
projectId,
isMarkdown,
});
new NewCommitForm(editBlobForm);
// returning here blocks page navigation
window.onbeforeunload = () => '';
}
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',
);
}
2017-08-01 08:50:59 +00:00
if (deleteBlobForm.length) {
new NewCommitForm(deleteBlobForm);
}
2018-02-21 20:22:56 +00:00
};