Mercurial > libervia-templates
changeset 239:61f3efd69fc3
js (common): prevent default behaviour for drag and drop:
we don't want that a file dropped on Libervia open the file
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 19 Jun 2020 17:57:13 +0200 |
parents | 0e4a2e0da438 |
children | cb08d92f181f |
files | sat_templates/templates/default/static/common.js |
diffstat | 1 files changed, 27 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/sat_templates/templates/default/static/common.js Fri Jun 19 17:57:13 2020 +0200 +++ b/sat_templates/templates/default/static/common.js Fri Jun 19 17:57:13 2020 +0200 @@ -174,3 +174,30 @@ /* adapt height to content, specially useful for iframe */ elt.style.height = elt.contentWindow.document.body.scrollHeight + 80 + 'px'; } + +/* we don't want default behaviour which load a dragged file */ + +window.addEventListener("dragenter", function(e) { + console.log(e.target.tagName + " " + e.target.type); + if (e.target.tagName != "INPUT" || e.target.type != "file") { + e.preventDefault(); + e.dataTransfer.effectAllowed = "none"; + e.dataTransfer.dropEffect = "none"; + } +}, false); + +window.addEventListener("dragover", function(e) { + if (e.target.tagName != "INPUT" || e.target.type != "file") { + e.preventDefault(); + e.dataTransfer.effectAllowed = "none"; + e.dataTransfer.dropEffect = "none"; + } +}); + +window.addEventListener("drop", function(e) { + if (e.target.tagName != "INPUT" || e.target.type != "file") { + e.preventDefault(); + e.dataTransfer.effectAllowed = "none"; + e.dataTransfer.dropEffect = "none"; + } +});