010.xhtml (1265B)
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 'all','uninitialized'</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 </style> 17 <script type="application/ecmascript"> 18 var effects = ['all','uninitialized'], i = 0; 19 function selectText() 20 {window.getSelection().selectAllChildren(document.querySelector('p'))} 21 function dropSelection(event) 22 {event.target.appendChild(document.createTextNode((event.dataTransfer.dropEffect == 'copy' && event.dataTransfer.effectAllowed == effects[i])?' PASS ':' FAIL ')); 23 i = (i + 1)%2; 24 selectText();} 25 function start(event) 26 {event.dataTransfer.effectAllowed = effects[i]} 27 </script> 28 </head> 29 <body onload="selectText()"> 30 <p ondragstart="start(event)">Drag me</p> 31 <div ondragenter="event.preventDefault()" ondragover="return false" ondrop="dropSelection(event)"/> 32 <div ondragenter="event.preventDefault()" ondragover="return false" ondrop="dropSelection(event)"/> 33 <p>You should be able to drag selection and drop it onto any of the green boxes.</p> 34 </body> 35 </html>