onlydropzoneevents.html (2448B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>Modifier keys being used with a dropzone attribute and dragenter/dragover events</title> 5 <style type="text/css"> 6 div:first-child { 7 height: 100px; 8 width: 100px; 9 background: orange; 10 display: inline-block; 11 } 12 div:first-child + div { 13 height: 100px; 14 width: 100px; 15 background: blue; 16 display: inline-block; 17 } 18 div:first-child + div + div { 19 height: 100px; 20 width: 100px; 21 background: fuchsia; 22 display: inline-block; 23 } 24 table { 25 display: inline-table; 26 margin-right: 1em; 27 border-collapse: collapse; 28 } 29 table, th, td { 30 border: 1px solid black; 31 } 32 thead th { 33 background: silver; 34 color: black; 35 } 36 </style> 37 <script type="text/javascript"> 38 window.onload = function () { 39 var orange = document.getElementsByTagName('div')[0]; 40 orange.ondragstart = function (e) { 41 e.dataTransfer.setData('text/plain','http://example.com/'); 42 e.dataTransfer.effectAllowed = 'copy'; 43 }; 44 var fuchsia = document.getElementsByTagName('div')[2], fde, fdo; 45 fuchsia.ondragenter = function (e) { 46 fde = e.dataTransfer.dropEffect; 47 }; 48 fuchsia.ondragover = function (e) { 49 fdo = e.dataTransfer.dropEffect; 50 }; 51 fuchsia.ondrop = function (e) { 52 //dropzone overrides the modifier, always, and ignores effectAllowed 53 e.preventDefault(); 54 var sequence = ([fde,fdo,e.dataTransfer.dropEffect]).join('=>') 55 var desiredsequence = (['move','move','link']).join('=>') 56 if( sequence == desiredsequence ) { 57 document.getElementsByTagName('div')[3].innerHTML = 'PASS'; 58 } else { 59 document.getElementsByTagName('div')[3].innerHTML = 'FAIL, got:<br>'+sequence+'<br>instead of:<br>'+desiredsequence; 60 } 61 }; 62 }; 63 </script> 64 </head> 65 <body> 66 67 <div draggable="true"></div> 68 <div></div> 69 <div dropzone="link string:text/plain"></div> 70 <div> </div> 71 <ol> 72 <li>Drag the orange square over the blue square</li> 73 <li>Press the relevant modifier keys for your platform to request a "move" drop effect (eg. Shift on Windows/Unix/Linux, Command on Mac)</li> 74 <li>Continue dragging over the pink square</li> 75 <li>If supported by the platform, the mouse cursor should show that a "link" drop effect will be used</li> 76 <li>Release the drag, then the keys</li> 77 <li>Fail if no new text appears above this list</li> 78 </ol> 79 <noscript><p>Enable JavaScript and reload</p></noscript> 80 81 </body> 82 </html>