Update cl.js
Browse files
cl.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
| 1 |
(function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
var s;
|
| 3 |
if (!document.querySelector('style.EVALDOTJSSTYLETHING')) {
|
| 4 |
s = document.createElement("style");
|
|
@@ -10,10 +17,10 @@
|
|
| 10 |
width: 500px;
|
| 11 |
height: 350px;
|
| 12 |
background: rgba(0,0,0,0.8);
|
| 13 |
-
top:
|
| 14 |
left: 0;
|
| 15 |
right: 0;
|
| 16 |
-
margin: auto;
|
| 17 |
font-size: 0;
|
| 18 |
z-index: 100000;
|
| 19 |
}
|
|
@@ -84,23 +91,31 @@
|
|
| 84 |
evalcontainer > evaloutput > evaloutputentry.EVALLOG::before {
|
| 85 |
content: "";
|
| 86 |
}
|
| 87 |
-
.close-button {
|
| 88 |
position: absolute;
|
| 89 |
-
top:
|
| 90 |
right: 10px;
|
| 91 |
-
|
| 92 |
-
color:
|
| 93 |
-
border: none;
|
| 94 |
-
padding: 5px;
|
| 95 |
cursor: pointer;
|
| 96 |
-
|
| 97 |
}
|
| 98 |
`;
|
| 99 |
document.head.appendChild(s);
|
| 100 |
}
|
|
|
|
| 101 |
if (!document.querySelector('evalcontainer')) {
|
| 102 |
s = document.createElement("evalcontainer");
|
| 103 |
var output = document.createElement("evaloutput");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
function createOutputEntry(words) {
|
| 106 |
var t = document.createElement("evaloutputentry");
|
|
@@ -108,18 +123,11 @@
|
|
| 108 |
t.className = 'EVALLOG';
|
| 109 |
output.appendChild(t);
|
| 110 |
}
|
|
|
|
| 111 |
createOutputEntry('To close this window, do evaljs.close();');
|
| 112 |
createOutputEntry('To clear, do evaljs.clear();');
|
| 113 |
s.appendChild(output);
|
| 114 |
|
| 115 |
-
var closeButton = document.createElement("button");
|
| 116 |
-
closeButton.className = 'close-button';
|
| 117 |
-
closeButton.textContent = '×';
|
| 118 |
-
closeButton.onclick = function() {
|
| 119 |
-
evaljs.close();
|
| 120 |
-
};
|
| 121 |
-
s.appendChild(closeButton);
|
| 122 |
-
|
| 123 |
var textarea = document.createElement("textarea");
|
| 124 |
textarea.className = 'EVALTEXTAREA';
|
| 125 |
textarea.focus();
|
|
@@ -158,7 +166,7 @@
|
|
| 158 |
t.classList.add('EVALSTRING');
|
| 159 |
break;
|
| 160 |
}
|
| 161 |
-
} catch
|
| 162 |
evaloutput = e;
|
| 163 |
t.classList.add('EVALERROR');
|
| 164 |
}
|
|
@@ -172,8 +180,6 @@
|
|
| 172 |
};
|
| 173 |
s.appendChild(textarea);
|
| 174 |
document.body.appendChild(s);
|
| 175 |
-
|
| 176 |
-
// Initialize evaljs object
|
| 177 |
evaljs = {
|
| 178 |
window: s,
|
| 179 |
clear() {
|
|
@@ -184,27 +190,6 @@
|
|
| 184 |
}
|
| 185 |
};
|
| 186 |
|
| 187 |
-
// Interact.js for drag-and-drop functionality
|
| 188 |
-
interact(s)
|
| 189 |
-
.draggable({
|
| 190 |
-
onmove: dragMoveListener
|
| 191 |
-
});
|
| 192 |
-
|
| 193 |
-
function dragMoveListener(event) {
|
| 194 |
-
var target = event.target,
|
| 195 |
-
// keep the dragged position in the data-x/data-y attributes
|
| 196 |
-
x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx,
|
| 197 |
-
y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
|
| 198 |
-
|
| 199 |
-
// translate the element
|
| 200 |
-
target.style.transform = 'translate(' + x + 'px, ' + y + 'px)';
|
| 201 |
-
|
| 202 |
-
// update the position attributes
|
| 203 |
-
target.setAttribute('data-x', x);
|
| 204 |
-
target.setAttribute('data-y', y);
|
| 205 |
-
}
|
| 206 |
-
|
| 207 |
-
// Adjust console methods
|
| 208 |
function merp(u, t) {
|
| 209 |
switch (typeof u) {
|
| 210 |
case 'object':
|
|
@@ -233,6 +218,7 @@
|
|
| 233 |
}
|
| 234 |
return u;
|
| 235 |
}
|
|
|
|
| 236 |
console.log = function() {
|
| 237 |
for (var i = 0; i < arguments.length; i++) {
|
| 238 |
var t = document.createElement("evaloutputentry"), u = arguments[i];
|
|
@@ -242,6 +228,7 @@
|
|
| 242 |
output.appendChild(t);
|
| 243 |
}
|
| 244 |
};
|
|
|
|
| 245 |
console.warn = function() {
|
| 246 |
for (var i = 0; i < arguments.length; i++) {
|
| 247 |
var t = document.createElement("evaloutputentry"), u = arguments[i];
|
|
@@ -252,6 +239,7 @@
|
|
| 252 |
output.appendChild(t);
|
| 253 |
}
|
| 254 |
};
|
|
|
|
| 255 |
console.error = function() {
|
| 256 |
for (var i = 0; i < arguments.length; i++) {
|
| 257 |
var t = document.createElement("evaloutputentry"), u = arguments[i];
|
|
@@ -262,5 +250,27 @@
|
|
| 262 |
output.appendChild(t);
|
| 263 |
}
|
| 264 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
}
|
| 266 |
}());
|
|
|
|
| 1 |
(function() {
|
| 2 |
+
// Load interact.js dynamically if it is not already loaded
|
| 3 |
+
if (!window.interact) {
|
| 4 |
+
var script = document.createElement("script");
|
| 5 |
+
script.src = "https://cdn.jsdelivr.net/npm/interactjs/dist/interact.min.js";
|
| 6 |
+
document.head.appendChild(script);
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
var s;
|
| 10 |
if (!document.querySelector('style.EVALDOTJSSTYLETHING')) {
|
| 11 |
s = document.createElement("style");
|
|
|
|
| 17 |
width: 500px;
|
| 18 |
height: 350px;
|
| 19 |
background: rgba(0,0,0,0.8);
|
| 20 |
+
top: 0;
|
| 21 |
left: 0;
|
| 22 |
right: 0;
|
| 23 |
+
margin: 50px auto;
|
| 24 |
font-size: 0;
|
| 25 |
z-index: 100000;
|
| 26 |
}
|
|
|
|
| 91 |
evalcontainer > evaloutput > evaloutputentry.EVALLOG::before {
|
| 92 |
content: "";
|
| 93 |
}
|
| 94 |
+
.eval-close-button {
|
| 95 |
position: absolute;
|
| 96 |
+
top: 5px;
|
| 97 |
right: 10px;
|
| 98 |
+
font-size: 18px;
|
| 99 |
+
color: #fff;
|
|
|
|
|
|
|
| 100 |
cursor: pointer;
|
| 101 |
+
font-weight: bold;
|
| 102 |
}
|
| 103 |
`;
|
| 104 |
document.head.appendChild(s);
|
| 105 |
}
|
| 106 |
+
|
| 107 |
if (!document.querySelector('evalcontainer')) {
|
| 108 |
s = document.createElement("evalcontainer");
|
| 109 |
var output = document.createElement("evaloutput");
|
| 110 |
+
|
| 111 |
+
// Create close button
|
| 112 |
+
var closeButton = document.createElement("span");
|
| 113 |
+
closeButton.innerHTML = "×";
|
| 114 |
+
closeButton.className = "eval-close-button";
|
| 115 |
+
closeButton.onclick = function() {
|
| 116 |
+
evaljs.close();
|
| 117 |
+
};
|
| 118 |
+
s.appendChild(closeButton);
|
| 119 |
|
| 120 |
function createOutputEntry(words) {
|
| 121 |
var t = document.createElement("evaloutputentry");
|
|
|
|
| 123 |
t.className = 'EVALLOG';
|
| 124 |
output.appendChild(t);
|
| 125 |
}
|
| 126 |
+
|
| 127 |
createOutputEntry('To close this window, do evaljs.close();');
|
| 128 |
createOutputEntry('To clear, do evaljs.clear();');
|
| 129 |
s.appendChild(output);
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
var textarea = document.createElement("textarea");
|
| 132 |
textarea.className = 'EVALTEXTAREA';
|
| 133 |
textarea.focus();
|
|
|
|
| 166 |
t.classList.add('EVALSTRING');
|
| 167 |
break;
|
| 168 |
}
|
| 169 |
+
} catch(e) {
|
| 170 |
evaloutput = e;
|
| 171 |
t.classList.add('EVALERROR');
|
| 172 |
}
|
|
|
|
| 180 |
};
|
| 181 |
s.appendChild(textarea);
|
| 182 |
document.body.appendChild(s);
|
|
|
|
|
|
|
| 183 |
evaljs = {
|
| 184 |
window: s,
|
| 185 |
clear() {
|
|
|
|
| 190 |
}
|
| 191 |
};
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
function merp(u, t) {
|
| 194 |
switch (typeof u) {
|
| 195 |
case 'object':
|
|
|
|
| 218 |
}
|
| 219 |
return u;
|
| 220 |
}
|
| 221 |
+
|
| 222 |
console.log = function() {
|
| 223 |
for (var i = 0; i < arguments.length; i++) {
|
| 224 |
var t = document.createElement("evaloutputentry"), u = arguments[i];
|
|
|
|
| 228 |
output.appendChild(t);
|
| 229 |
}
|
| 230 |
};
|
| 231 |
+
|
| 232 |
console.warn = function() {
|
| 233 |
for (var i = 0; i < arguments.length; i++) {
|
| 234 |
var t = document.createElement("evaloutputentry"), u = arguments[i];
|
|
|
|
| 239 |
output.appendChild(t);
|
| 240 |
}
|
| 241 |
};
|
| 242 |
+
|
| 243 |
console.error = function() {
|
| 244 |
for (var i = 0; i < arguments.length; i++) {
|
| 245 |
var t = document.createElement("evaloutputentry"), u = arguments[i];
|
|
|
|
| 250 |
output.appendChild(t);
|
| 251 |
}
|
| 252 |
};
|
| 253 |
+
|
| 254 |
+
// Initialize drag-and-drop using interact.js
|
| 255 |
+
script.onload = function() {
|
| 256 |
+
interact('evalcontainer').draggable({
|
| 257 |
+
modifiers: [
|
| 258 |
+
interact.modifiers.restrictRect({
|
| 259 |
+
restriction: 'parent',
|
| 260 |
+
endOnly: true
|
| 261 |
+
})
|
| 262 |
+
],
|
| 263 |
+
listeners: {
|
| 264 |
+
move(event) {
|
| 265 |
+
var target = event.target;
|
| 266 |
+
var x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx;
|
| 267 |
+
var y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
|
| 268 |
+
target.style.transform = `translate(${x}px, ${y}px)`;
|
| 269 |
+
target.setAttribute('data-x', x);
|
| 270 |
+
target.setAttribute('data-y', y);
|
| 271 |
+
}
|
| 272 |
+
}
|
| 273 |
+
});
|
| 274 |
+
};
|
| 275 |
}
|
| 276 |
}());
|