annotate src/examples/drop.html @ 17:ab28b0591003

security
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 15 Sep 2024 07:04:14 -0600
parents 332d3e280f7e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 <!doctype html>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 <html>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 <head>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 <meta name="viewport" content="width=device-width, initial-scale=1">
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 <style>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 @import "/site.css";
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 @import "/dad.css";
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
7
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
9 [handle] {
4
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 display: inline-block;
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 background-color: LightGreen;
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 padding: 8px;
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 }
7
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
14 [outer] {
4
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 display: inline-block;
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 background-color: LightBlue;
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 padding: 8px;
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 position: relative;
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 }
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 </style>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 <script src="/dad.js"></script>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 <script>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 dad.whatToDrag = function(draggable) {
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 return draggable.parentNode;
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 };
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 dad.onDrop = function(event) {
5
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
28 let original = event.original;
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
29 let style = original.style;
4
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 let left = style.left ? parseInt(style.left) : 0;
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 let top = style.top ? parseInt(style.top) : 0;
5
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
32 let rectDragged = event.dragging.getBoundingClientRect();
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
33 let rectDraggable = original.getBoundingClientRect();
4
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 left += rectDragged.x - rectDraggable.x;
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 top += rectDragged.y - rectDraggable.y;
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 style.left = left + 'px';
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 style.top = top + 'px';
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 };
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 function init() {
7
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
41 let handle = document.querySelector('[handle]');
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
42 dad.setDraggable(handle);
4
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 }
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 </script>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 </head>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 <body>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 <h1>Handle</h1>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 <p>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 <span outer>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 <span handle>drag me</span>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 along for the ride
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 </span>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 </p>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 <p>bottom</p>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 </body>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 <script> init(); </script>
0130ae25ef94 add drop
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 </html>