Skip to content

Commit db2a260

Browse files
Added behavior on Esc and Enter
1 parent 519af06 commit db2a260

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Note: _The order of this list might not match the order these features will be a
6666

6767
_Release date: ???????????????????????_
6868

69-
_Work Time: 2h 30min_
69+
_Work Time: 4h_
7070

7171
-
7272

pages/common.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var combo, selector;
55
var imageSpace;
66
var pageName;
77

8-
// dimensions = list of all dimensions called in all pages, update while coding pages
8+
// dimensions = list of all dimensions called in all pages
99
var dimensions = ['L', 'D', 't', 'B', 'b', 'H', 'R', 'A', 'h'];
1010
var dim = {};
1111
var matProp = ['density', 'brake', 'yeld'];
@@ -187,10 +187,11 @@ function Traction() {
187187
// EXPRESSION EDITOR FUNCTIONS
188188

189189
var editor = document.querySelector('#calc');
190-
var variable = document.querySelector('#var');
190+
var property = document.querySelector('#var');
191191
var textfield = document.querySelector('#expression');
192192
var result = document.querySelector('#result num');
193193
var icons = document.querySelectorAll('#result icon > *');
194+
var button = document.querySelector('#calc button');
194195

195196
function openEditor() {
196197
editor.style.display = 'grid';
@@ -202,21 +203,25 @@ function closeEditor() {
202203

203204
function addEquationKeyListeners() {
204205
var target = document.querySelectorAll('table input[type=number]');
205-
console.log(target);
206206
target.forEach(item => item.addEventListener('keyup', openEditorForVariable));
207207
}
208208

209209
function openEditorForVariable(event) {
210210
// press '=' to open editor when closed and focus on textfield
211211
if (event.key == '=' && editor.style.display == 'none') {
212-
variable.value = event.target.parentNode.previousElementSibling.innerHTML;
212+
property.innerHTML = event.target.parentNode.previousElementSibling.innerHTML;
213213
textfield.value = '';
214214
textfield.focus();
215215
openEditor();
216216
}
217217
}
218218

219-
// function keyPressed() {
220-
// // press 'Esc' to close editor when open
221-
// if (keyCode === 27 && editor.style.display !== 'none') closeEditor();
222-
// }
219+
editor.addEventListener('keyup', function (event) {
220+
// do something only if the editor is open
221+
if (editor.style.display !== 'none') {
222+
// press 'Esc' to close editor
223+
if (event.key == 'Escape') closeEditor();
224+
// press 'Enter' to act as pressing the button
225+
if (event.key == 'Enter') button.click();
226+
}
227+
});

0 commit comments

Comments
 (0)