1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-16 11:44:42 +02:00

Fix issue processwire/processwire-issues#202 where the leave confirm box was appearing when it shouldn't, after saving after a file had been uploaded. Also added drag/drop protection so that if you accidentially drag/drop a file outside of the specified dropzone, it gets ignored, rather than loading the file in the browser.

This commit is contained in:
Ryan Cramer
2017-03-10 08:38:16 -05:00
parent 6fe703f699
commit b899bc42e7
6 changed files with 21 additions and 8 deletions

View File

@@ -405,7 +405,7 @@ $(document).ready(function() {
}, false);
dropArea.addEventListener("dragenter", function() {
$(this).addClass('ui-state-hover');
$(this).closest('.Inputfield').addClass('pw-drag-in-file InputfieldStateConfirmLeave');
$(this).closest('.Inputfield').addClass('pw-drag-in-file');
}, false);
dropArea.addEventListener("dragover", function (evt) {
@@ -419,7 +419,7 @@ $(document).ready(function() {
dropArea.addEventListener("drop", function (evt) {
traverseFiles(evt.dataTransfer.files);
$(this).removeClass("ui-state-hover").closest('.Inputfield').removeClass('pw-drag-in-file InputfieldStateConfirmLeave');
$(this).removeClass("ui-state-hover").closest('.Inputfield').removeClass('pw-drag-in-file');
evt.preventDefault();
evt.stopPropagation();
}, false);

File diff suppressed because one or more lines are too long

View File

@@ -1176,7 +1176,7 @@ function InputfieldImage($) {
function dragStart() {
if($inputfield.hasClass('pw-drag-in-file')) return;
$el.addClass('ui-state-hover');
$inputfield.addClass('pw-drag-in-file InputfieldStateConfirmLeave');
$inputfield.addClass('pw-drag-in-file');
}
function dragStop() {

File diff suppressed because one or more lines are too long

View File

@@ -900,7 +900,6 @@ function InputfieldColumnWidths($target) {
*/
function InputfieldFormBeforeUnloadEvent(e) {
var $changes = $(".InputfieldFormConfirm:not(.InputfieldFormSubmitted) .InputfieldStateChanged");
if($changes.length == 0) $changes = $('.InputfieldStateConfirmLeave');
if($changes.length == 0) return;
var msg = $('.InputfieldFormConfirm:eq(0)').attr('data-confirm') + "\n";
$changes.each(function() {
@@ -1218,6 +1217,20 @@ function InputfieldIntentions() {
$form.removeClass('nosubmit');
});
});
// prevent dragged in files from loading in the browser (does not interfere with other drag/drop handlers)
if($("input[type=file]").length) {
$(document).on({
dragover: function() {
if($(this).is("input[type=file]")) return;
return false;
},
drop: function() {
if($(this).is("input[type=file]")) return;
return false;
}
});
}
}
/***********************************************************************************/

File diff suppressed because one or more lines are too long