-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclick-to-add.html
127 lines (122 loc) · 4.95 KB
/
click-to-add.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Patchbay.js - Click to add</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 flex-col flex items-center space-y-12 h-screen py-6 px-4">
<div class="max-w-lg w-full mb-3">
<a href="../examples/index.html" class="text-blue-600 inline-block hover:underline mb-4">
← Back to examples
</a>
<h1 class="mb-4 text-2xl font-bold">Click to add - Add ports by clicking on the patch bay</h1>
<p class="text-gray-500">
Using <code>startCableFromPoint()</code> we can start a cable from a specific point, and then connect it to
another point.
</p>
</div>
<div class="bg-zinc-900 w-full max-w-lg flex flex-col gap-4 p-4 rounded-lg shadow-md">
<!-- Upper side -->
<div class="grid grid-cols-6 gap-2">
<div
id="input-1"
class="cursor-pointer cable-connector bg-zinc-900 size-8 rounded-full border-2 border-zinc-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="input-2"
class="cursor-pointer cable-connector bg-zinc-900 size-8 rounded-full border-2 border-zinc-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="input-3"
class="cursor-pointer cable-connector bg-zinc-900 size-8 rounded-full border-2 border-zinc-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="input-4"
class="cursor-pointer cable-connector bg-zinc-900 size-8 rounded-full border-2 border-zinc-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="input-5"
class="cursor-pointer cable-connector bg-zinc-900 size-8 rounded-full border-2 border-zinc-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="input-6"
class="cursor-pointer cable-connector bg-zinc-900 size-8 rounded-full border-2 border-zinc-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
</div>
<hr class="border-zinc-800" />
<!-- Lower side -->
<div class="grid grid-cols-6 gap-2">
<div
id="output-1"
class="cursor-pointer cable-connector bg-zinc-900 size-8 rounded-full border-2 border-blue-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="output-2"
class="cursor-pointer cable-connector bg-zinc-900 size-8 rounded-full border-2 border-blue-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="output-3"
class="cursor-pointer cable-connector bg-zinc-900 size-8 rounded-full border-2 border-blue-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="output-4"
class="cursor-pointer cable-connector bg-zinc-900 size-8 rounded-full border-2 border-blue-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="output-5"
class="cursor-pointer cable-connector bg-zinc-900 size-8 rounded-full border-2 border-blue-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
<div
id="output-6"
class="cursor-pointer cable-connector bg-zinc-900 size-8 rounded-full border-2 border-blue-600 flex items-center justify-center mx-auto"
>
<div class="bg-zinc-500 size-3 rounded-full"></div>
</div>
</div>
</div>
<script src="../dist/patchbay.umd.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
const patchbay = new Patchbay({
container: document.body,
gravity: 2,
iterations: 5,
slack: 1.2,
segments: 20,
snapRadius: 100,
});
let connectorElements = document.querySelectorAll("div[id^='input-'], div[id^='output-']");
connectorElements.forEach((element) => {
element.addEventListener("click", (e) => {
patchbay.startCable(element, { color: "#6468F0" });
});
});
patchbay.start();
});
</script>
</body>
</html>