-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamiscript.html
254 lines (224 loc) · 8.99 KB
/
dynamiscript.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced Balloon Creator with Icons</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/dynamiscript@latest/dist/dynamiscript.min.js"></script>
<style>
body {
background: #2c2c2c; /* خلفية رمادية غامقة */
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
background-image: linear-gradient(0deg, transparent 1px, #3d3d3d 1px), linear-gradient(90deg, transparent 1px, #3d3d3d 1px);
background-size: 20px 20px; /* حجم الشبكة */
}
.balloon {
position: absolute;
background: #fff;
border: 1px solid #ddd;
border-radius: 15px;
padding: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2), 0 6px 12px rgba(0, 0, 0, 0.1);
color: #333;
font-weight: bold;
text-align: center;
cursor: pointer;
transition: background 0.3s, border-color 0.3s, box-shadow 0.3s, transform 0.3s;
max-width: 300px;
max-height: 250px;
overflow: hidden;
position: relative;
}
.balloon:hover {
background: #e0f7fa;
border-color: #80deea;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3), 0 8px 16px rgba(0, 0, 0, 0.15);
transform: scale(1.05);
}
.balloon:before {
content: '';
position: absolute;
bottom: -30px;
left: 50%;
margin-left: -15px;
border-width: 20px;
border-style: solid;
border-color: #fff transparent transparent transparent;
}
.balloon[data-tooltip]:hover:before {
content: attr(data-tooltip);
position: absolute;
background-color: #333;
color: #fff;
padding: 8px 12px;
border-radius: 6px;
top: -60px;
left: 50%;
transform: translateX(-50%);
white-space: nowrap;
font-size: 14px;
z-index: 10;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}
.balloon .icon {
font-size: 24px;
color: #00796b;
display: block;
margin-bottom: 10px;
}
.text-field {
width: 100%;
border: none;
background: transparent;
font-size: 18px;
text-align: center;
outline: none;
resize: none;
box-sizing: border-box;
font-family: 'Arial', sans-serif;
font-weight: normal;
line-height: 1.4;
}
.text-field:focus {
border-bottom: 2px solid #00796b;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}
.line {
position: absolute;
background: #000;
height: 2px;
z-index: -1;
transition: background 0.3s;
}
.line:hover {
background: #00796b;
}
#info {
position: fixed;
bottom: 10px;
left: 10px;
background: #fff;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 14px;
color: #333;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
z-index: 1000;
}
</style>
</head>
<body>
<div id="info"></div>
<script>
class Balloon {
constructor(text, x, y, options = {}) {
this.text = text;
this.x = x;
this.y = y;
this.color = options.color || '#e0f7fa';
this.tooltip = options.tooltip || '';
this.customClass = options.customClass || '';
this.iconClass = options.iconClass || 'fa-circle';
this.connections = [];
this.createBalloon();
this.makeDraggable();
}
createBalloon() {
this.element = document.createElement('div');
this.element.className = `balloon ${this.customClass}`;
this.element.style.top = `${this.y}px`;
this.element.style.left = `${this.x}px`;
this.element.style.background = this.color;
// Create and add the icon
this.icon = document.createElement('i');
this.icon.className = `icon fas ${this.iconClass}`;
this.element.appendChild(this.icon);
// Create and add the text area
this.textArea = document.createElement('textarea');
this.textArea.className = 'text-field';
this.textArea.value = this.text;
this.textArea.addEventListener('input', (e) => {
this.text = e.target.value;
});
this.element.appendChild(this.textArea);
if (this.tooltip) {
this.element.setAttribute('data-tooltip', this.tooltip);
}
document.body.appendChild(this.element);
this.updateInfo(); // Show initial info
}
connectTo(otherBalloon, lineColor = '#000') {
const line = document.createElement('div');
line.className = 'line';
line.style.background = lineColor;
document.body.appendChild(line);
this.updateLine(line, otherBalloon);
this.connections.push({ line, balloon: otherBalloon });
otherBalloon.connections.push({ line, balloon: this });
}
updateLine(line, otherBalloon) {
const x1 = this.element.offsetLeft + this.element.offsetWidth / 2;
const y1 = this.element.offsetTop + this.element.offsetHeight / 2;
const x2 = otherBalloon.element.offsetLeft + otherBalloon.element.offsetWidth / 2;
const y2 = otherBalloon.element.offsetTop + otherBalloon.element.offsetHeight / 2;
const length = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);
const angle = Math.atan2(y2 - y1, x2 - x1) * 180 / Math.PI;
line.style.width = `${length}px`;
line.style.transform = `rotate(${angle}deg)`;
line.style.transformOrigin = '0 0';
line.style.left = `${x1}px`;
line.style.top = `${y1}px`;
}
makeDraggable() {
let isDragging = false;
let offsetX, offsetY;
this.element.addEventListener('mousedown', (e) => {
isDragging = true;
offsetX = e.clientX - this.element.getBoundingClientRect().left;
offsetY = e.clientY - this.element.getBoundingClientRect().top;
e.preventDefault();
});
document.addEventListener('mousemove', (e) => {
if (isDragging) {
this.x = e.clientX - offsetX;
this.y = e.clientY - offsetY;
this.updatePosition();
this.updateInfo(); // Update info on move
}
});
document.addEventListener('mouseup', () => {
isDragging = false;
});
}
updatePosition() {
this.element.style.left = `${this.x}px`;
this.element.style.top = `${this.y}px`;
this.updateConnections();
}
updateConnections() {
this.connections.forEach(({ line, balloon }) => {
this.updateLine(line, balloon);
});
}
updateInfo() {
const info = document.getElementById('info');
info.textContent = `Balloon at: (${Math.round(this.x)}, ${Math.round(this.y)})`;
}
}
// Function to create a balloon through simple API
function createBalloon(text, x, y, options = {}) {
return new Balloon(text, x, y, options);
}
// Example usage
const balloon1 = createBalloon('Editable Balloon 1', 100, 100, { color: '#ffeb3b', tooltip: 'Edit this text', iconClass: 'fa-pencil-alt' });
const balloon2 = createBalloon('Editable Balloon 2', 300, 200, { color: '#8bc34a', iconClass: 'fa-check-circle' });
const balloon3 = createBalloon('Editable Balloon 3', 500, 100, { color: '#ff5722', tooltip: 'Another tooltip', iconClass: 'fa-exclamation-circle' });
balloon1.connectTo(balloon2, '#ff5722');
balloon2.connectTo(balloon3, '#3f51b5');
</script>
</body>
</html>