soiz commited on
Commit
ada97f6
·
verified ·
1 Parent(s): bb2712d

Update cl.js

Browse files
Files changed (1) hide show
  1. cl.js +44 -47
cl.js CHANGED
@@ -11,21 +11,12 @@
11
  height: 350px;
12
  background: rgba(0,0,0,0.8);
13
  top: 50px;
14
- left: 50%;
15
- transform: translateX(-50%);
 
16
  font-size: 0;
17
  z-index: 100000;
18
  }
19
- evalcontainer > .close-btn {
20
- position: absolute;
21
- top: 10px;
22
- right: 10px;
23
- background: transparent;
24
- border: none;
25
- color: white;
26
- font-size: 16px;
27
- cursor: pointer;
28
- }
29
  evalcontainer > textarea.EVALTEXTAREA {
30
  width: 500px;
31
  border: none;
@@ -93,23 +84,24 @@
93
  evalcontainer > evaloutput > evaloutputentry.EVALLOG::before {
94
  content: "";
95
  }
 
 
 
 
 
 
 
 
 
 
 
96
  `;
97
  document.head.appendChild(s);
98
  }
99
-
100
  if (!document.querySelector('evalcontainer')) {
101
  s = document.createElement("evalcontainer");
102
-
103
- // Close button
104
- var closeButton = document.createElement("button");
105
- closeButton.className = 'close-btn';
106
- closeButton.textContent = '×';
107
- closeButton.onclick = function() {
108
- evaljs.close();
109
- };
110
- s.appendChild(closeButton);
111
-
112
  var output = document.createElement("evaloutput");
 
113
  function createOutputEntry(words) {
114
  var t = document.createElement("evaloutputentry");
115
  t.innerHTML = words;
@@ -119,6 +111,14 @@
119
  createOutputEntry('To close this window, do evaljs.close();');
120
  createOutputEntry('To clear, do evaljs.clear();');
121
  s.appendChild(output);
 
 
 
 
 
 
 
 
122
 
123
  var textarea = document.createElement("textarea");
124
  textarea.className = 'EVALTEXTAREA';
@@ -126,7 +126,7 @@
126
  textarea.onkeypress = e => {
127
  if (e.keyCode === 13 && !e.shiftKey) {
128
  var t = document.createElement("evaloutputentry"),
129
- evaloutput;
130
  t.textContent = textarea.value;
131
  output.appendChild(t);
132
  t = document.createElement("evaloutputentry");
@@ -170,38 +170,41 @@
170
  return false;
171
  }
172
  };
173
-
174
  s.appendChild(textarea);
175
  document.body.appendChild(s);
 
 
 
 
 
 
 
 
 
 
 
176
 
177
- // Draggable functionality
178
  interact(s)
179
  .draggable({
180
  onmove: dragMoveListener
181
  });
182
 
183
- function dragMoveListener (event) {
184
- var target = event.target;
185
- var x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx;
186
- var y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
 
187
 
188
  // translate the element
189
  target.style.transform = 'translate(' + x + 'px, ' + y + 'px)';
190
 
 
191
  target.setAttribute('data-x', x);
192
  target.setAttribute('data-y', y);
193
  }
194
 
195
- evaljs = {
196
- window: s,
197
- clear() {
198
- while (output.hasChildNodes()) output.removeChild(output.lastChild);
199
- },
200
- close() {
201
- document.body.removeChild(this.window);
202
- }
203
- };
204
-
205
  function merp(u, t) {
206
  switch (typeof u) {
207
  case 'object':
@@ -230,7 +233,6 @@
230
  }
231
  return u;
232
  }
233
-
234
  console.log = function() {
235
  for (var i = 0; i < arguments.length; i++) {
236
  var t = document.createElement("evaloutputentry"), u = arguments[i];
@@ -261,9 +263,4 @@
261
  }
262
  };
263
  }
264
-
265
- // Load interact.js library dynamically
266
- var script = document.createElement('script');
267
- script.src = 'https://cdn.jsdelivr.net/npm/interactjs/dist/interact.min.js';
268
- document.head.appendChild(script);
269
- })();
 
11
  height: 350px;
12
  background: rgba(0,0,0,0.8);
13
  top: 50px;
14
+ left: 0;
15
+ right: 0;
16
+ margin: auto;
17
  font-size: 0;
18
  z-index: 100000;
19
  }
 
 
 
 
 
 
 
 
 
 
20
  evalcontainer > textarea.EVALTEXTAREA {
21
  width: 500px;
22
  border: none;
 
84
  evalcontainer > evaloutput > evaloutputentry.EVALLOG::before {
85
  content: "";
86
  }
87
+ .close-button {
88
+ position: absolute;
89
+ top: 10px;
90
+ right: 10px;
91
+ background: rgba(255, 0, 0, 0.8);
92
+ color: white;
93
+ border: none;
94
+ padding: 5px;
95
+ cursor: pointer;
96
+ z-index: 100001; /* above the container */
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");
107
  t.innerHTML = words;
 
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';
 
126
  textarea.onkeypress = e => {
127
  if (e.keyCode === 13 && !e.shiftKey) {
128
  var t = document.createElement("evaloutputentry"),
129
+ evaloutput;
130
  t.textContent = textarea.value;
131
  output.appendChild(t);
132
  t = document.createElement("evaloutputentry");
 
170
  return false;
171
  }
172
  };
 
173
  s.appendChild(textarea);
174
  document.body.appendChild(s);
175
+
176
+ // Initialize evaljs object
177
+ evaljs = {
178
+ window: s,
179
+ clear() {
180
+ while (output.hasChildNodes()) output.removeChild(output.lastChild);
181
+ },
182
+ close() {
183
+ document.body.removeChild(this.window);
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
  }
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];
 
263
  }
264
  };
265
  }
266
+ }());