014.xhtml (1422B)
1 <?xml version="1.0" encoding="utf-8"?> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>Selection drag and drop: allowed effects 'copy','copyMove','invalid'</title> 5 <style type="text/css"> 6 div 7 {display:inline-block; 8 vertical-align:top; 9 background-color:olive; 10 color:white; 11 padding:20px; 12 width:100px; 13 height:100px;} 14 div:nth-child(2) 15 {background-color:green;} 16 div:nth-child(3) 17 {background-color:teal;} 18 </style> 19 <script type="application/ecmascript"> 20 var effects = ['copy','all','uninitialized'], i = 0; 21 function selectText() 22 {window.getSelection().selectAllChildren(document.querySelector('p'))} 23 function dropSelection(event) 24 {event.target.appendChild(document.createTextNode((event.dataTransfer.dropEffect == 'copy' && event.dataTransfer.effectAllowed == effects[i])?' PASS ':' FAIL ')); 25 i = (i + 1)%3; 26 selectText();} 27 function start(event) 28 {event.dataTransfer.effectAllowed = effects[i]} 29 </script> 30 </head> 31 <body onload="selectText()"> 32 <p ondragstart="start(event)">Drag me</p> 33 <div ondragenter="event.preventDefault()" ondragover="return false" ondrop="dropSelection(event)"/> 34 <div ondragenter="event.preventDefault()" ondragover="return false" ondrop="dropSelection(event)"/> 35 <div ondragenter="event.preventDefault()" ondragover="return false" ondrop="dropSelection(event)"/> 36 <p>You should be able to drag selection and drop it onto any of the green boxes.</p> 37 </body> 38 </html>