Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

65
LINES

< > BotCompany Repo | #1031912 // HFullScreenDropZone - allow drag&drop anywhere on a page

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3194L/18K).

sclass HFullScreenDropZone {
  S endOfBody() {
    ret div("", id := "fullScreenDropZone");
  }
  
  S css() {
    ret [[
      div#dropZone {
        background: gray;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 999;
        opacity: 0.6;
        visibility: hidden;
      }
    ]];
  }
  
  S js() {
    ret [[
      var dropZone = document.getElementById('fullScreenDropZone');
      
      function showDropZone() {
          dropZone.style.visibility = "visible";
      }
      function hideDropZone() {
          dropZone.style.visibility = "hidden";
      }
      
      function allowDrag(e) {
          if (true) {  // Test that the item being dragged is a valid one
              e.dataTransfer.dropEffect = 'copy';
              e.preventDefault();
          }
      }
      
      function handleDrop(e) {
          e.preventDefault();
          hideDropZone();
      
          alert('Drop!');
      }
      
      // 1
      window.addEventListener('dragenter', function(e) {
          showDropZone();
      });
      
      // 2
      dropZone.addEventListener('dragenter', allowDrag);
      dropZone.addEventListener('dragover', allowDrag);
      
      // 3
      dropZone.addEventListener('dragleave', function(e) {
          hideDropZone();
      });
      
      // 4
      dropZone.addEventListener('drop', handleDrop);
    ]];
  }
}

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: 82 / 195
Referenced in: [show references]