From cb1ebc1cd0ed3947c1b7baa1fa6a5623957460f1 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Tue, 1 Dec 2020 13:52:41 +0100 Subject: [PATCH] Drag 'n drop for files --- cps/static/js/main.js | 55 ++++++++++++++++++++++++++++++++++++++- cps/templates/layout.html | 12 --------- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/cps/static/js/main.js b/cps/static/js/main.js index f2d7b929..703ecb29 100644 --- a/cps/static/js/main.js +++ b/cps/static/js/main.js @@ -58,6 +58,59 @@ $(document).on("change", "select[data-controlall]", function() { } }); +// Syntax has to be bind not on, otherwise problems with firefox +$(".container-fluid").bind("dragenter dragover", function () { + if($("#btn-upload").length && !$('body').hasClass('shelforder')) { + $(this).css('background', '#e6e6e6'); + } + return false; +}); + +// Syntax has to be bind not on, otherwise problems with firefox +$(".container-fluid").bind("dragleave", function () { + if($("#btn-upload").length && !$('body').hasClass('shelforder')) { + $(this).css('background', ''); + } + return false; +}); + +// Syntax has to be bind not on, otherwise problems with firefox +$(".container-fluid").bind('drop', function (e) { + e.preventDefault() + e.stopPropagation(); + if($("#btn-upload").length) { + var files = e.originalEvent.dataTransfer.files; + var test = $("#btn-upload")[0].accept; + $(this).css('background', ''); + // var final = []; + const dt = new DataTransfer() + jQuery.each(files, function (index, item) { + if (test.indexOf(item.name.substr(item.name.lastIndexOf('.'))) !== -1) { + dt.items.add(item); + } + }); + if (dt.files.length) { + $("#btn-upload")[0].files = dt.files; + $("#form-upload").submit(); + } + } +}); + +$("#btn-upload").change(function() { + $("#form-upload").submit(); +}); + +$(document).ready(function() { + var inp = $('#query').first() + if (inp.length) { + var val = inp.val() + if (val.length) { + inp.val('').blur().focus().val(val) + } + } +}); + + $("#delete_confirm").click(function() { //get data-id attribute of the clicked element var pathname = document.getElementsByTagName("script"), src = pathname[pathname.length - 1].src; @@ -188,7 +241,7 @@ $(function() { } $(".load-more .row").isotope( "appended", $(data), null ); }); - + // fix for infinite scroll on CaliBlur Theme (#981) if ($("body").hasClass("blur")) { $(".col-sm-10").bind("scroll", function () { diff --git a/cps/templates/layout.html b/cps/templates/layout.html index 65867fe7..44d18a1e 100644 --- a/cps/templates/layout.html +++ b/cps/templates/layout.html @@ -217,18 +217,6 @@ modalFooter: "{{_('Close')}}", modalTitleFailed: "{{_('Error')}}" }); - $("#btn-upload").change(function() { - $("#form-upload").submit(); - }); - $(document).ready(function() { - var inp = $('#query').first() - if (inp.length) { - var val = inp.val() - if (val.length) { - inp.val('').blur().focus().val(val) - } - } - }); }); {% block js %}{% endblock %}