-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
diamond9.html
185 lines (165 loc) · 5.96 KB
/
diamond9.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diamond 9 Generator</title>
<style>
#container {
position: relative;
width: 100%;
height: 80vh;
border: 1px solid #ccc;
margin-top: 20px;
display: flex;
justify-content: center;
align-items: center;
}
.draggable {
position: absolute;
z-index: 9;
width: 100px;
height: 50px;
border: 1px solid #000;
background-color: #f0f0f0;
text-align: center;
line-height: 50px;
cursor: move;
}
.background-box {
position: absolute;
z-index: 1;
width: 100px;
height: 50px;
border: 1px solid #000;
background-color: #d3d3d3;
}
.label {
position: absolute;
z-index: 2;
font-weight: bold;
text-align: center;
}
.textBox {
margin: 5px 0;
}
/* Positioning background boxes in the correct Diamond 9 shape */
.background-box:nth-child(1) { top: 5%; left: calc(50% - 50px); }
.background-box:nth-child(2) { top: 20%; left: calc(40% - 50px); }
.background-box:nth-child(3) { top: 20%; left: calc(60% - 50px); }
.background-box:nth-child(4) { top: 35%; left: calc(30% - 50px); }
.background-box:nth-child(5) { top: 35%; left: calc(50% - 50px); }
.background-box:nth-child(6) { top: 35%; left: calc(70% - 50px); }
.background-box:nth-child(7) { top: 50%; left: calc(40% - 50px); }
.background-box:nth-child(8) { top: 50%; left: calc(60% - 50px); }
.background-box:nth-child(9) { top: 65%; left: calc(50% - 50px); }
.label.top { top: 0; left: calc(50% - 50px); }
.label.bottom { top: 75%; left: calc(50% - 50px); }
</style>
</head>
<body>
<h1>Diamond 9 Generator</h1>
<div id="inputContainer">
<input class="textBox" type="text" id="text1" placeholder="Enter text 1">
<input class="textBox" type="text" id="text2" placeholder="Enter text 2">
<input class="textBox" type="text" id="text3" placeholder="Enter text 3">
<input class="textBox" type="text" id="text4" placeholder="Enter text 4">
<input class="textBox" type="text" id="text5" placeholder="Enter text 5">
<input class="textBox" type="text" id="text6" placeholder="Enter text 6">
<input class="textBox" type="text" id="text7" placeholder="Enter text 7">
<input class="textBox" type="text" id="text8" placeholder="Enter text 8">
<input class="textBox" type="text" id="text9" placeholder="Enter text 9">
<button onclick="createRectangles()">Make</button>
</div>
<div id="container">
<!-- Background boxes in Diamond 9 layout -->
<div class="background-box"></div>
<div class="background-box"></div>
<div class="background-box"></div>
<div class="background-box"></div>
<div class="background-box"></div>
<div class="background-box"></div>
<div class="background-box"></div>
<div class="background-box"></div>
<div class="background-box"></div>
<!-- Labels -->
<div class="label top">Most important</div>
<div class="label bottom">Least important</div>
</div>
<script>
function createRectangles() {
const container = document.getElementById('container');
const inputContainer = document.getElementById('inputContainer');
const words = [];
for (let i = 1; i <= 9; i++) {
const text = document.getElementById(`text${i}`).value.trim();
if (text) {
const div = document.createElement('div');
div.className = 'draggable';
div.textContent = text;
// Randomly position the user-entered boxes within the container
div.style.left = `${Math.random() * (container.clientWidth - 100)}px`;
div.style.top = `${Math.random() * (container.clientHeight - 50)}px`;
div.id = `mydiv${i}`;
dragElement(div);
container.appendChild(div);
words.push(encodeURIComponent(text));
}
}
// Hide the input boxes and button
inputContainer.style.display = 'none';
// Update URL with words
const url = new URL(window.location);
url.searchParams.set('words', words.join(','));
window.history.replaceState({}, '', url);
}
// Make the DIV element draggable
function dragElement(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
elmnt.onmousedown = function(e) {
e = e || window.event;
e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
};
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
}
function closeDragElement() {
/* stop moving when mouse button is released:*/
document.onmouseup = null;
document.onmousemove = null;
}
}
// On page load, recreate rectangles if words are in the URL and hide input boxes
window.onload = function () {
const urlParams = new URLSearchParams(window.location.search);
const words = urlParams.get('words');
if (words) {
const wordArray = words.split(',');
wordArray.forEach((word, index) => {
document.getElementById(`text${index + 1}`).value = decodeURIComponent(word);
});
createRectangles();
// Hide the input boxes and button since URL contains words
document.getElementById('inputContainer').style.display = 'none';
}
};
</script>
<script async defer src="https://scripts.simpleanalyticscdn.com/latest.js"></script>
<noscript><img src="https://queue.simpleanalyticscdn.com/noscript.gif" alt="" referrerpolicy="no-referrer-when-downgrade" /></noscript>
</body>
</html>