| 
4
 | 
     1 <!doctype html>
 | 
| 
 | 
     2 <html>
 | 
| 
 | 
     3 	<head>
 | 
| 
 | 
     4 		<meta name="viewport" content="width=device-width, initial-scale=1">
 | 
| 
 | 
     5 		<style>
 | 
| 
 | 
     6 			@import "/site.css";
 | 
| 
 | 
     7 			@import "/dad.css";
 | 
| 
 | 
     8 
 | 
| 
7
 | 
     9 			[handle] {
 | 
| 
4
 | 
    10 				display: inline-block;
 | 
| 
 | 
    11 				background-color: LightGreen;
 | 
| 
 | 
    12 				padding: 8px;
 | 
| 
 | 
    13 			}
 | 
| 
7
 | 
    14 			[outer] {
 | 
| 
4
 | 
    15 				display: inline-block;
 | 
| 
 | 
    16 				background-color: LightBlue;
 | 
| 
 | 
    17 				padding: 8px;
 | 
| 
 | 
    18 				position: relative;
 | 
| 
 | 
    19 			}
 | 
| 
 | 
    20 		</style>
 | 
| 
 | 
    21 		<script src="/dad.js"></script>
 | 
| 
 | 
    22 		<script>
 | 
| 
 | 
    23 			dad.whatToDrag = function(draggable) {
 | 
| 
 | 
    24 				return draggable.parentNode;
 | 
| 
 | 
    25 			};
 | 
| 
 | 
    26 
 | 
| 
 | 
    27 			dad.onDrop = function(event) {
 | 
| 
5
 | 
    28 				let original = event.original;
 | 
| 
 | 
    29 				let style = original.style;
 | 
| 
4
 | 
    30 				let left = style.left ? parseInt(style.left) : 0;
 | 
| 
 | 
    31 				let top = style.top ? parseInt(style.top) : 0;
 | 
| 
5
 | 
    32 				let rectDragged = event.dragging.getBoundingClientRect();
 | 
| 
 | 
    33 				let rectDraggable = original.getBoundingClientRect();
 | 
| 
4
 | 
    34 				left += rectDragged.x - rectDraggable.x;
 | 
| 
 | 
    35 				top += rectDragged.y - rectDraggable.y;
 | 
| 
 | 
    36 				style.left = left + 'px';
 | 
| 
 | 
    37 				style.top = top + 'px';
 | 
| 
 | 
    38 			};
 | 
| 
 | 
    39 
 | 
| 
 | 
    40 			function init() {
 | 
| 
7
 | 
    41 				let handle = document.querySelector('[handle]');
 | 
| 
 | 
    42 				dad.setDraggable(handle);
 | 
| 
4
 | 
    43 			}
 | 
| 
 | 
    44 		</script>
 | 
| 
 | 
    45 	</head>
 | 
| 
 | 
    46 	<body>
 | 
| 
 | 
    47 		<h1>Handle</h1>
 | 
| 
 | 
    48 		<p>
 | 
| 
 | 
    49 			<span outer>
 | 
| 
 | 
    50 				<span handle>drag me</span>
 | 
| 
 | 
    51 				along for the ride
 | 
| 
 | 
    52 			</span>
 | 
| 
 | 
    53 		</p>
 | 
| 
 | 
    54 		<p>bottom</p>
 | 
| 
 | 
    55 	</body>
 | 
| 
 | 
    56 	<script> init(); </script>
 | 
| 
 | 
    57 </html>
 |