Libraryless. Click here for Pure Java version (3194L/18K).
1 | sclass HFullScreenDropZone {
|
2 | S endOfBody() {
|
3 | ret div("", id := "fullScreenDropZone");
|
4 | } |
5 | |
6 | S css() {
|
7 | ret [[ |
8 | div#dropZone {
|
9 | background: gray; |
10 | position: fixed; |
11 | top: 0; |
12 | left: 0; |
13 | width: 100%; |
14 | height: 100%; |
15 | z-index: 999; |
16 | opacity: 0.6; |
17 | visibility: hidden; |
18 | } |
19 | ]]; |
20 | } |
21 | |
22 | S js() {
|
23 | ret [[ |
24 | var dropZone = document.getElementById('fullScreenDropZone');
|
25 | |
26 | function showDropZone() {
|
27 | dropZone.style.visibility = "visible"; |
28 | } |
29 | function hideDropZone() {
|
30 | dropZone.style.visibility = "hidden"; |
31 | } |
32 | |
33 | function allowDrag(e) {
|
34 | if (true) { // Test that the item being dragged is a valid one
|
35 | e.dataTransfer.dropEffect = 'copy'; |
36 | e.preventDefault(); |
37 | } |
38 | } |
39 | |
40 | function handleDrop(e) {
|
41 | e.preventDefault(); |
42 | hideDropZone(); |
43 | |
44 | alert('Drop!');
|
45 | } |
46 | |
47 | // 1 |
48 | window.addEventListener('dragenter', function(e) {
|
49 | showDropZone(); |
50 | }); |
51 | |
52 | // 2 |
53 | dropZone.addEventListener('dragenter', allowDrag);
|
54 | dropZone.addEventListener('dragover', allowDrag);
|
55 | |
56 | // 3 |
57 | dropZone.addEventListener('dragleave', function(e) {
|
58 | hideDropZone(); |
59 | }); |
60 | |
61 | // 4 |
62 | dropZone.addEventListener('drop', handleDrop);
|
63 | ]]; |
64 | } |
65 | } |
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
| Snippet ID: | #1031912 |
| Snippet name: | HFullScreenDropZone - allow drag&drop anywhere on a page |
| Eternal ID of this version: | #1031912/1 |
| Text MD5: | a3e0901693b163b51eeeb5bd6a96dc19 |
| Transpilation MD5: | 15ab1a6ced48985843198f543cf91c97 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-07-28 23:31:03 |
| Source code size: | 1492 bytes / 65 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 376 / 580 |
| Referenced in: | [show references] |