Skip to content

Commit 519af06

Browse files
Redefined '=' key event
1 parent 31e2ea2 commit 519af06

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

pages/common.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ function setup() {
8484

8585
// set values when selecting a material
8686
selector.changed(updateMatProp);
87+
88+
// add event listeners to open equation editor
89+
addEquationKeyListeners();
8790
}
8891

8992
function updateMatProp() {
@@ -184,7 +187,7 @@ function Traction() {
184187
// EXPRESSION EDITOR FUNCTIONS
185188

186189
var editor = document.querySelector('#calc');
187-
var property = document.querySelector('#var');
190+
var variable = document.querySelector('#var');
188191
var textfield = document.querySelector('#expression');
189192
var result = document.querySelector('#result num');
190193
var icons = document.querySelectorAll('#result icon > *');
@@ -197,13 +200,23 @@ function closeEditor() {
197200
editor.style.display = 'none';
198201
}
199202

200-
function keyPressed() {
203+
function addEquationKeyListeners() {
204+
var target = document.querySelectorAll('table input[type=number]');
205+
console.log(target);
206+
target.forEach(item => item.addEventListener('keyup', openEditorForVariable));
207+
}
208+
209+
function openEditorForVariable(event) {
201210
// press '=' to open editor when closed and focus on textfield
202-
if (keyCode === 48 && editor.style.display == 'none') {
203-
openEditor();
204-
textfield.focus();
211+
if (event.key == '=' && editor.style.display == 'none') {
212+
variable.value = event.target.parentNode.previousElementSibling.innerHTML;
205213
textfield.value = '';
214+
textfield.focus();
215+
openEditor();
206216
}
207-
// press 'Esc' to close editor when open
208-
if (keyCode === 27 && editor.style.display !== 'none') closeEditor();
209-
}
217+
}
218+
219+
// function keyPressed() {
220+
// // press 'Esc' to close editor when open
221+
// if (keyCode === 27 && editor.style.display !== 'none') closeEditor();
222+
// }

0 commit comments

Comments
 (0)