Skip to content

Commit a5e1871

Browse files
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.
1 parent 69175da commit a5e1871

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

Diff for: modules/Inputfield/InputfieldFile/InputfieldFile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ $(document).ready(function() {
405405
}, false);
406406
dropArea.addEventListener("dragenter", function() {
407407
$(this).addClass('ui-state-hover');
408-
$(this).closest('.Inputfield').addClass('pw-drag-in-file InputfieldStateConfirmLeave');
408+
$(this).closest('.Inputfield').addClass('pw-drag-in-file');
409409
}, false);
410410

411411
dropArea.addEventListener("dragover", function (evt) {
@@ -419,7 +419,7 @@ $(document).ready(function() {
419419

420420
dropArea.addEventListener("drop", function (evt) {
421421
traverseFiles(evt.dataTransfer.files);
422-
$(this).removeClass("ui-state-hover").closest('.Inputfield').removeClass('pw-drag-in-file InputfieldStateConfirmLeave');
422+
$(this).removeClass("ui-state-hover").closest('.Inputfield').removeClass('pw-drag-in-file');
423423
evt.preventDefault();
424424
evt.stopPropagation();
425425
}, false);

Diff for: modules/Inputfield/InputfieldFile/InputfieldFile.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: modules/Inputfield/InputfieldImage/InputfieldImage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ function InputfieldImage($) {
11761176
function dragStart() {
11771177
if($inputfield.hasClass('pw-drag-in-file')) return;
11781178
$el.addClass('ui-state-hover');
1179-
$inputfield.addClass('pw-drag-in-file InputfieldStateConfirmLeave');
1179+
$inputfield.addClass('pw-drag-in-file');
11801180
}
11811181

11821182
function dragStop() {

Diff for: modules/Inputfield/InputfieldImage/InputfieldImage.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: templates-admin/scripts/inputfields.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,6 @@ function InputfieldColumnWidths($target) {
900900
*/
901901
function InputfieldFormBeforeUnloadEvent(e) {
902902
var $changes = $(".InputfieldFormConfirm:not(.InputfieldFormSubmitted) .InputfieldStateChanged");
903-
if($changes.length == 0) $changes = $('.InputfieldStateConfirmLeave');
904903
if($changes.length == 0) return;
905904
var msg = $('.InputfieldFormConfirm:eq(0)').attr('data-confirm') + "\n";
906905
$changes.each(function() {
@@ -1217,7 +1216,21 @@ function InputfieldIntentions() {
12171216
// allow submissions again once they are out of the field
12181217
$form.removeClass('nosubmit');
12191218
});
1220-
});
1219+
});
1220+
1221+
// prevent dragged in files from loading in the browser (does not interfere with other drag/drop handlers)
1222+
if($("input[type=file]").length) {
1223+
$(document).on({
1224+
dragover: function() {
1225+
if($(this).is("input[type=file]")) return;
1226+
return false;
1227+
},
1228+
drop: function() {
1229+
if($(this).is("input[type=file]")) return;
1230+
return false;
1231+
}
1232+
});
1233+
}
12211234
}
12221235

12231236
/***********************************************************************************/

0 commit comments

Comments
 (0)