-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
manip.html
199 lines (174 loc) · 6.61 KB
/
manip.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Draggable Manipulatives</title>
<style>
#manipulatives-container {
width: 100%;
height: 100vh;
border: 1px solid #ccc;
position: relative;
overflow: auto;
margin-top: 10px;
}
.manipulative {
display: inline-block;
padding: 10px;
margin: 5px;
color: white;
border-radius: 5px;
cursor: grab;
position: absolute;
user-select: none; /* Prevent text selection while dragging */
font-size: 1em;
}
.green {
background-color: #4CAF50; /* Default green */
}
.blue {
background-color: #2196F3; /* Blue for * */
}
.red {
background-color: #F44336; /* Red for ** */
}
#input-container {
display: block;
margin: 10px 0;
}
#title {
text-align: center;
font-size: 2em;
margin-top: 20px;
font-weight: bold;
}
#scale-container {
display: block;
position: fixed;
bottom: 20px;
left: 20px;
z-index: 1000;
background-color: white;
padding: 10px;
border: 1px solid #ccc;
}
#scale-label {
display: inline-block;
margin-right: 10px;
}
</style>
</head>
<body>
<h2 id="title">Draggable Manipulatives Generator</h2>
<div id="input-container">
<input type="text" id="title-input" placeholder="Enter title here" style="width: 50%; display: block; margin-bottom: 10px;">
<textarea id="text-input" rows="5" cols="50" placeholder="Enter words or phrases, each on a new line. Use * for blue and ** for red"></textarea>
<br>
<button id="generate-btn" onclick="generateManipulatives()">Generate Manipulatives</button>
</div>
<!-- Slider for scaling -->
<div id="scale-container">
<label id="scale-label">Scale:</label>
<input type="range" id="scale-slider" min="0.5" max="3" step="0.1" value="1" oninput="scaleManipulativesAndTitle(this.value)">
</div>
<div id="manipulatives-container"></div>
<script>
// Function to create draggable manipulatives
function generateManipulatives() {
const titleText = document.getElementById('title-input').value;
const inputText = document.getElementById('text-input').value;
const phrases = sanitizeText(inputText);
if (!phrases.length || !titleText.trim()) return; // Avoid empty title or phrases
// Update the URL with the title and phrases
const encodedTitle = encodeURIComponent(titleText);
const encodedPhrases = encodeURIComponent(phrases.join('\n'));
const newUrl = `${window.location.origin}${window.location.pathname}?title=${encodedTitle}&phrases=${encodedPhrases}`;
window.history.pushState({}, '', newUrl);
// Set the title and hide the input fields
document.getElementById('title').textContent = titleText;
document.getElementById('input-container').style.display = 'none';
createManipulatives(phrases);
}
// Function to sanitize and process input text
function sanitizeText(inputText) {
return inputText
.split(/\n+/) // Split by newline characters
.filter(phrase => phrase.trim().length > 0) // Remove empty entries
.map(phrase => phrase.trim()); // Remove extra spaces
}
// Function to create manipulatives on the screen
function createManipulatives(phrases) {
const container = document.getElementById('manipulatives-container');
container.innerHTML = ''; // Clear previous manipulatives
phrases.forEach((phrase) => {
const manipulative = document.createElement('div');
manipulative.classList.add('manipulative');
// Set class based on * or ** at the start of the phrase
if (phrase.startsWith('**')) {
manipulative.classList.add('red'); // Red if it starts with **
phrase = phrase.substring(2).trim(); // Remove the **
} else if (phrase.startsWith('*')) {
manipulative.classList.add('blue'); // Blue if it starts with *
phrase = phrase.substring(1).trim(); // Remove the *
} else {
manipulative.classList.add('green'); // Default green
}
manipulative.textContent = phrase;
manipulative.style.top = `${Math.random() * 250}px`; // Random position
manipulative.style.left = `${Math.random() * 250}px`;
// Add manual drag functionality
let isDragging = false;
let offsetX, offsetY;
manipulative.addEventListener('mousedown', function(e) {
isDragging = true;
offsetX = e.clientX - parseInt(manipulative.style.left);
offsetY = e.clientY - parseInt(manipulative.style.top);
manipulative.style.cursor = 'grabbing'; // Change cursor while dragging
});
document.addEventListener('mousemove', function(e) {
if (isDragging) {
manipulative.style.top = `${e.clientY - offsetY}px`;
manipulative.style.left = `${e.clientX - offsetX}px`;
}
});
document.addEventListener('mouseup', function() {
if (isDragging) {
isDragging = false;
manipulative.style.cursor = 'grab'; // Reset cursor when not dragging
}
});
container.appendChild(manipulative);
});
}
// Function to scale manipulatives and the title based on slider value
function scaleManipulativesAndTitle(scaleValue) {
const manipulatives = document.querySelectorAll('.manipulative');
const title = document.getElementById('title');
// Scale manipulatives
manipulatives.forEach(manipulative => {
manipulative.style.fontSize = `${scaleValue}em`;
});
// Scale title
title.style.fontSize = `${scaleValue * 2}em`; // Title is larger, so scale it accordingly
}
// Automatically generate manipulatives if title and phrases are in the URL
window.onload = function() {
const urlParams = new URLSearchParams(window.location.search);
const titleParam = urlParams.get('title');
const phrasesParam = urlParams.get('phrases');
if (titleParam && phrasesParam) {
const decodedTitle = decodeURIComponent(titleParam);
const decodedPhrases = decodeURIComponent(phrasesParam).split('\n');
// Set title and hide input fields
document.getElementById('title').textContent = decodedTitle;
document.getElementById('input-container').style.display = 'none';
// Generate manipulatives
createManipulatives(decodedPhrases);
}
};
</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>