Provide function callback when file is dropped

- https://stackoverflow.com/questions/6756583/prevent-browser-from-loading-a-drag-and-dropped-file
-
This commit is contained in:
Oliver Walters 2019-05-06 21:22:31 +10:00
parent dca26b5810
commit eec0fc34d2
3 changed files with 35 additions and 12 deletions

View File

@ -101,6 +101,18 @@
{% block js_ready %}
{{ block.super }}
$('#part-thumb').on('drop', function(event) {
var transfer = event.originalEvent.dataTransfer;
var files = transfer.files;
console.log('dropped');
//$(this).removeClass('dragover');
});
$("#show-qr-code").click(function() {
launchModalForm(
"{% url 'part-qr' part.id %}",

View File

@ -3,6 +3,16 @@ function inventreeDocReady() {
* This will be called for every page that extends "base.html"
*/
window.addEventListener("dragover",function(e){
e = e || event;
e.preventDefault();
},false);
window.addEventListener("drop",function(e){
e = e || event;
e.preventDefault();
},false);
/* Add drag-n-drop functionality to any element
* marked with the class 'dropzone'
*/
@ -10,7 +20,19 @@ function inventreeDocReady() {
$(this).addClass('dragover');
});
$('.dropzone').on('dragleave', function() {
$('.dropzone').on('dragleave drop', function() {
$(this).removeClass('dragover');
});
// Callback to launch the 'About' window
$('#launch-about').click(function() {
var modal = $('#modal-about');
modal.modal({
backdrop: 'static',
keyboard: 'false',
});
modal.modal('show');
});
}

View File

@ -88,17 +88,6 @@ $(document).ready(function () {
* Ref: static/script/inventree/notification.js
*/
showCachedAlerts();
$('#launch-about').click(function() {
var modal = $('#modal-about');
modal.modal({
backdrop: 'static',
keyboard: 'false',
});
modal.modal('show');
});
});
</script>