Skip to content

Commit

Permalink
Auto blur inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ricktu288 committed Jan 1, 2024
1 parent 5d08dbf commit c8e8ee2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
30 changes: 26 additions & 4 deletions simulator/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,16 @@ window.onload = function (e) {
});


document.getElementById('undo').onclick = undo;
document.getElementById('redo').onclick = redo;
document.getElementById('undo_mobile').onclick = undo;
document.getElementById('redo_mobile').onclick = redo;
document.getElementById('undo').onclick = function() {
this.blur();
undo();
}
document.getElementById('undo_mobile').onclick = document.getElementById('undo').onclick;
document.getElementById('redo').onclick = function() {
this.blur();
redo();
}
document.getElementById('redo_mobile').onclick = document.getElementById('redo').onclick;
document.getElementById('reset').onclick = function () {
history.replaceState('', document.title, window.location.pathname+window.location.search);
initParameters();
Expand Down Expand Up @@ -266,16 +272,20 @@ window.onload = function (e) {
document.getElementById('color_mode').checked = colorMode;
document.getElementById('color_mode_mobile').checked = colorMode;
selectObj(selectedObj);
this.blur();
draw(false, true);
};
document.getElementById('color_mode_mobile').onclick = document.getElementById('color_mode').onclick;

document.getElementById('show_help_popups').onclick = function () {
this.blur();
popoversEnabled = this.checked;
localStorage.rayOpticsHelp = popoversEnabled ? "on" : "off";
};

document.getElementById('show_status').onclick = function () {
this.blur();

document.getElementById('show_status').checked = this.checked;
document.getElementById('show_status_mobile').checked = this.checked;

Expand Down Expand Up @@ -335,9 +345,11 @@ window.onload = function (e) {

document.getElementById('zoomPlus').onclick = function () {
setScale(scale * 1.1);
this.blur();
}
document.getElementById('zoomMinus').onclick = function () {
setScale(scale / 1.1);
this.blur();
}
document.getElementById('zoomPlus_mobile').onclick = document.getElementById('zoomPlus').onclick;
document.getElementById('zoomMinus_mobile').onclick = document.getElementById('zoomMinus').onclick;
Expand All @@ -358,6 +370,7 @@ window.onload = function (e) {
document.getElementById('rayDensity').value = this.value;
document.getElementById('rayDensity_more').value = this.value;
document.getElementById('rayDensity_mobile').value = this.value;
this.blur();
draw(false, true);
createUndoPoint();
};
Expand All @@ -369,6 +382,7 @@ window.onload = function (e) {
document.getElementById('rayDensity').value = this.value;
document.getElementById('rayDensity_more').value = this.value;
document.getElementById('rayDensity_mobile').value = this.value;
this.blur();
draw(false, true);
createUndoPoint();
};
Expand All @@ -381,6 +395,7 @@ window.onload = function (e) {
document.getElementById('rayDensity').value = rayDensityValue;
document.getElementById('rayDensity_more').value = rayDensityValue;
document.getElementById('rayDensity_mobile').value = rayDensityValue;
this.blur();
draw(false, true);
};
document.getElementById('rayDensityMinus').onclick = function () {
Expand All @@ -389,6 +404,7 @@ window.onload = function (e) {
document.getElementById('rayDensity').value = rayDensityValue;
document.getElementById('rayDensity_more').value = rayDensityValue;
document.getElementById('rayDensity_mobile').value = rayDensityValue;
this.blur();
draw(false, true);
};
document.getElementById('rayDensityPlus_mobile').onclick = document.getElementById('rayDensityPlus').onclick;
Expand All @@ -401,6 +417,7 @@ window.onload = function (e) {
document.getElementById('grid').checked = e.target.checked;
document.getElementById('grid_more').checked = e.target.checked;
document.getElementById('grid_mobile').checked = e.target.checked;
this.blur();
//draw();
};
document.getElementById('grid_more').onclick = document.getElementById('grid').onclick;
Expand All @@ -410,6 +427,7 @@ window.onload = function (e) {
document.getElementById('showgrid').checked = e.target.checked;
document.getElementById('showgrid_more').checked = e.target.checked;
document.getElementById('showgrid_mobile').checked = e.target.checked;
this.blur();
draw(true, false);
};
document.getElementById('showgrid_more').onclick = document.getElementById('showgrid').onclick;
Expand All @@ -419,6 +437,7 @@ window.onload = function (e) {
document.getElementById('lockobjs').checked = e.target.checked;
document.getElementById('lockobjs_more').checked = e.target.checked;
document.getElementById('lockobjs_mobile').checked = e.target.checked;
this.blur();
};
document.getElementById('lockobjs_more').onclick = document.getElementById('lockobjs').onclick;
document.getElementById('lockobjs_mobile').onclick = document.getElementById('lockobjs').onclick;
Expand All @@ -432,13 +451,15 @@ window.onload = function (e) {
document.getElementById('restore').onclick = function () { restore() };

document.getElementById('setAttrAll').onclick = function () {
this.blur();
const checked = this.checked;
document.getElementById('setAttrAll').checked = checked;
document.getElementById('applytoall_mobile').checked = checked;
}
document.getElementById('applytoall_mobile').onclick = document.getElementById('setAttrAll').onclick;

document.getElementById('copy').onclick = function () {
this.blur();
objs[objs.length] = JSON.parse(JSON.stringify(objs[selectedObj]));
objTypes[objs[objs.length - 1].type].move(objs[objs.length - 1], gridSize, gridSize);
selectObj(objs.length - 1);
Expand All @@ -449,6 +470,7 @@ window.onload = function (e) {

document.getElementById('delete').onclick = function () {
var selectedObjType = objs[selectedObj].type;
this.blur();
removeObj(selectedObj);
draw(!(objTypes[selectedObjType].shoot || objTypes[selectedObjType].rayIntersection), true);
createUndoPoint();
Expand Down
4 changes: 4 additions & 0 deletions simulator/js/parameterBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ function createNumberAttr(label, min, max, step, value, func, elem, info, hideSl

objAttr_range.onmouseup = function()
{
this.blur();
createUndoPoint();
};

objAttr_range.ontouchend = function()
{
this.blur();
setAttr(function(obj) {
func(obj, objAttr_range.value * 1);
});
Expand Down Expand Up @@ -250,6 +252,7 @@ function createBooleanAttr(label, value, func, elem, info) {
elem.appendChild(space);

objAttr_checkbox.onchange = function() {
this.blur();
setAttr(function(obj) {
func(obj, objAttr_checkbox.checked);
});
Expand Down Expand Up @@ -374,6 +377,7 @@ function createButton(label, func, elem) {
button.className = 'btn btn-secondary';
button.innerHTML = label;
button.onclick = function() {
this.blur();
func(objs[selectedObj]);
};
elem.appendChild(button);
Expand Down

0 comments on commit c8e8ee2

Please sign in to comment.