Skip to content

Commit 42a0227

Browse files
committed
Add reset button for settings/checkboxes
1 parent ee81206 commit 42a0227

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

InteractiveHtmlBom/web/ibom.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@
238238
<div class="flexbox">
239239
<button class="savebtn" onclick="saveSettings()">Export</button>
240240
<button class="savebtn" onclick="loadSettings()">Import</button>
241+
<button class="savebtn" onclick="resetSettings()">Reset</button>
241242
</div>
242243
</div>
243244
<div class="menu-label">

InteractiveHtmlBom/web/util.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ function writeStorage(key, value) {
3636
}
3737

3838
function fancyDblClickHandler(el, onsingle, ondouble) {
39-
return function() {
39+
return function () {
4040
if (el.getAttribute("data-dblclick") == null) {
4141
el.setAttribute("data-dblclick", 1);
42-
setTimeout(function() {
42+
setTimeout(function () {
4343
if (el.getAttribute("data-dblclick") == 1) {
4444
onsingle();
4545
}
@@ -171,7 +171,7 @@ var units = {
171171
"FARAD", "Farad", "farad",
172172
"HENRY", "Henry", "henry"
173173
],
174-
getMultiplier: function(s) {
174+
getMultiplier: function (s) {
175175
if (this.prefixes.giga.includes(s)) return 1e9;
176176
if (this.prefixes.mega.includes(s)) return 1e6;
177177
if (this.prefixes.kilo.includes(s)) return 1e3;
@@ -360,7 +360,7 @@ function loadSettings() {
360360
var input = document.createElement("input");
361361
input.type = "file";
362362
input.accept = ".settings.json";
363-
input.onchange = function(e) {
363+
input.onchange = function (e) {
364364
var file = e.target.files[0];
365365
var reader = new FileReader();
366366
reader.onload = readerEvent => {
@@ -388,10 +388,10 @@ function loadSettings() {
388388
var currentMetadata = JSON.stringify(pcbdata.metadata, null, 4);
389389
var fileMetadata = JSON.stringify(newSettings.pcbmetadata, null, 4);
390390
if (!confirm(
391-
`Settins file metadata does not match current metadata.\n\n` +
392-
`Page metadata:\n${currentMetadata}\n\n` +
393-
`Settings file metadata:\n${fileMetadata}\n\n` +
394-
`Press OK if you would like to import settings anyway.`)) {
391+
`Settins file metadata does not match current metadata.\n\n` +
392+
`Page metadata:\n${currentMetadata}\n\n` +
393+
`Settings file metadata:\n${fileMetadata}\n\n` +
394+
`Press OK if you would like to import settings anyway.`)) {
395395
return;
396396
}
397397
}
@@ -402,6 +402,23 @@ function loadSettings() {
402402
input.click();
403403
}
404404

405+
function resetSettings() {
406+
if (!confirm(
407+
`This will reset all checkbox states and other settings.\n\n` +
408+
`Press OK if you want to continue.`)) {
409+
return;
410+
}
411+
if (storage) {
412+
var keys = [];
413+
for (var i = 0; i < storage.length; i++) {
414+
var key = storage.key(i);
415+
if (key.startsWith(storagePrefix)) keys.push(key);
416+
}
417+
for (var key of keys) storage.removeItem(key);
418+
}
419+
location.reload();
420+
}
421+
405422
function overwriteSettings(newSettings) {
406423
initDone = false;
407424
Object.assign(settings, newSettings);
@@ -594,14 +611,14 @@ const IBOM_EVENT_TYPES = {
594611

595612
const EventHandler = {
596613
callbacks: {},
597-
init: function() {
614+
init: function () {
598615
for (eventType of Object.values(IBOM_EVENT_TYPES))
599616
this.callbacks[eventType] = [];
600617
},
601-
registerCallback: function(eventType, callback) {
618+
registerCallback: function (eventType, callback) {
602619
this.callbacks[eventType].push(callback);
603620
},
604-
emitEvent: function(eventType, eventArgs) {
621+
emitEvent: function (eventType, eventArgs) {
605622
event = {
606623
eventType: eventType,
607624
args: eventArgs,

0 commit comments

Comments
 (0)