events-cross-document-suite-HELPER-2.html (3449B)
1 <!DOCTYPE html> 2 <title>drag & drop - event sequence for cross-document drag</title> 3 <style type="text/css"> 4 /* use margins instead of padding to make sure the body begins at the top of the page */ 5 html, body { 6 margin: 0; 7 padding: 0; 8 height: 100%; 9 } 10 #testhere div { 11 height: 100px; 12 width: 100px; 13 position: absolute; 14 top: 8px; 15 } 16 body::before { 17 height: 100px; 18 width: 100px; 19 position: absolute; 20 top: 8px; 21 left: 0px; 22 content: ""; 23 background-color: silver; 24 } 25 #yellow { 26 background-color: yellow; 27 left: 150px; 28 } 29 #blue { 30 background-color: navy; 31 left: 300px; 32 } 33 </style> 34 35 <script> 36 window.onload = function () { 37 var yellow = document.querySelector('#yellow') 38 var blue = document.querySelector('#blue') 39 var body = document.body; 40 41 /* Events for the fuchsia box */ 42 yellow.ondragstart = function () { parent.events.push('doc2.yellow.ondragstart'); }; 43 yellow.ondrag = function () { parent.events.push('doc2.yellow.ondrag'); }; 44 yellow.ondragenter = function () { parent.events.push('doc2.yellow.ondragenter'); return false; }; 45 yellow.ondragover = function () { parent.events.push('doc2.yellow.ondragover'); return false; }; 46 yellow.ondrop = function () { parent.events.push('doc2.yellow.ondrop'); return false; }; 47 yellow.ondragend = function () { parent.events.push('doc2.yellow.ondragend'); }; 48 yellow.onmousedown = function () { parent.events.push('doc2.yellow.onmousedown'); }; 49 yellow.onmouseup = function () { parent.events.push('doc2.yellow.onmouseup'); }; 50 51 /* Events for the blue box (droppable) */ 52 blue.ondragstart = function () { parent.events.push('doc2.blue.ondragstart'); }; 53 blue.ondrag = function () { parent.events.push('doc2.blue.ondrag'); }; 54 blue.ondragenter = function () { parent.events.push('doc2.blue.ondragenter'); return false; }; 55 blue.ondragover = function () { parent.events.push('doc2.blue.ondragover'); return false; }; 56 blue.ondrop = function () { parent.events.push('doc2.blue.ondrop'); return false; }; 57 blue.ondragend = function () { parent.events.push('doc2.blue.ondragend'); }; 58 blue.onmousedown = function () { parent.events.push('doc2.blue.onmousedown'); }; 59 blue.onmouseup = function () { parent.events.push('doc2.blue.onmouseup'); }; 60 61 /* Events for the page body */ 62 body.ondragstart = function (e) { parent.events.push( ( e.target == body ) ? 'doc2.body.ondragstart': 'doc2.bubble.ondragstart' ); }; 63 body.ondrag = function (e) { parent.events.push( ( e.target == body ) ? 'doc2.body.ondrag': 'doc2.bubble.ondrag' ); }; 64 body.ondragenter = function (e) { parent.events.push( ( e.target == body ) ? 'doc2.body.ondragenter': 'doc2.bubble.ondragenter' ); }; 65 body.ondragover = function (e) { parent.events.push( ( e.target == body ) ? 'doc2.body.ondragover': 'doc2.bubble.ondragover' ); }; 66 body.ondrop = function (e) { parent.events.push( ( e.target == body ) ? 'doc2.body.ondrop': 'doc2.bubble.ondrop' ); }; 67 body.ondragend = function (e) { parent.events.push( ( e.target == body ) ? 'doc2.body.ondragend': 'doc2.bubble.ondragend' ); }; 68 body.onmousedown = function (e) { parent.events.push( ( e.target == body ) ? 'doc2.body.onmousedown': 'doc2.bubble.onmousedown' ); }; 69 body.onmouseup = function (e) { parent.events.push( ( e.target == body ) ? 'doc2.body.onmouseup': 'doc2.bubble.onmouseup' ); }; 70 71 }; 72 </script> 73 74 <div id="testhere"> 75 <div id='yellow'></div> 76 <div id='blue'></div> 77 </div>