Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
MattBudz committed Jul 4, 2023
1 parent 707959a commit 52cee24
Showing 1 changed file with 54 additions and 28 deletions.
82 changes: 54 additions & 28 deletions app/assets/javascripts/shared/fileupload.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,69 @@
// jQuery.fileUpload - handles attachment uploads (gem: jquery-fileupload-rails)

function fileUploadInit() {
$('[data-behavior~=jquery-upload]').fileupload({
autoUpload: true,
dropZone: function(){ return $('[data-behavior~=drop-zone]') },
pasteZone: function(){ return $('[data-behavior~=drop-zone]') },
singleFileUploads: true,
destroy: function(e, data) {
if (confirm('Are you sure?\n\nProceeding will delete this attachment from the associated node.')) {
$.blueimp.fileupload.prototype.options.destroy.call(this, e, data);
}
}
}).on('fileuploadadd', function (e, data) {
// data.$textarea is added to the input field owned by the editor and is
// only present when the image button is clicked. Copying, or dragging does
// not append the attribute.
var $textarea = (e.originalEvent !== undefined) ? $(e.originalEvent.target) : data.$textarea;
$('[data-behavior~=jquery-upload]')
.fileupload({
autoUpload: true,
dropZone: function () {
return $('[data-behavior~=drop-zone]');
},
pasteZone: function () {
return $('[data-behavior~=drop-zone]');
},
singleFileUploads: true,
destroy: function (e, data) {
if (
confirm(
'Are you sure?\n\nProceeding will delete this attachment from the associated node.'
)
) {
$.blueimp.fileupload.prototype.options.destroy.call(this, e, data);
}
},
downloadTemplateId:
$('[data-behavior~=jquery-upload]').data('template-download') === false
? null
: 'template-download',
uploadTemplateId:
$('[data-behavior~=jquery-upload]').data('template-upload') === false
? null
: 'template-upload',
})
.on('fileuploadadd', function (e, data) {
// data.$textarea is added to the input field owned by the editor and is
// only present when the image button is clicked. Copying, or dragging does
// not append the attribute.
var $textarea =
e.originalEvent !== undefined
? $(e.originalEvent.target)
: data.$textarea;

if ($textarea.is($('[data-behavior~=rich-toolbar]'))) {
var editorToolbar = $textarea.data('editorToolbar');
data.replaceImagePlaceholder = editorToolbar.replaceImagePlaceholder.bind(editorToolbar);
if ($textarea.is($('[data-behavior~=rich-toolbar]'))) {
var editorToolbar = $textarea.data('editorToolbar');
data.replaceImagePlaceholder =
editorToolbar.replaceImagePlaceholder.bind(editorToolbar);

$.each(data.files, editorToolbar.insertImagePlaceholder.bind(editorToolbar));
}
}).on('fileuploaddone', function (e, data) {
if (data.replaceImagePlaceholder !== undefined) {
$.each(data.files, data.replaceImagePlaceholder.bind(null, data));
}
});
$.each(
data.files,
editorToolbar.insertImagePlaceholder.bind(editorToolbar)
);
}
})
.on('fileuploaddone', function (e, data) {
if (data.replaceImagePlaceholder !== undefined) {
$.each(data.files, data.replaceImagePlaceholder.bind(null, data));
}
});
}

document.addEventListener("turbolinks:load", function() {
document.addEventListener('turbolinks:load', function () {
// Bind fileUpload on page load.
fileUploadInit();
});

// Un-bind fileUpload on page unload.
document.addEventListener('turbolinks:before-cache', function() {
$('[data-behavior~=jquery-upload]').each(function() {
document.addEventListener('turbolinks:before-cache', function () {
$('[data-behavior~=jquery-upload]').each(function () {
$(this).fileupload('destroy');
});
});

0 comments on commit 52cee24

Please sign in to comment.