Skip to content

Commit

Permalink
save previous value
Browse files Browse the repository at this point in the history
  • Loading branch information
maizy committed Oct 25, 2020
1 parent 8809545 commit f427cef
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
if (window.wlb === undefined) {
window.wlb = {
const SaveInput = function () {
this.timeInput = null;
this.lsKey = "input";
};
SaveInput.prototype.init = function () {
this.timeInput = document.getElementById("time-input");
this.ls = window.localStorage;
if (this.ls) {
this.timeInput.value = this.ls.getItem(this.lsKey);
this.bindAll();
}
};
SaveInput.prototype.bindAll = function () {
this.timeInput.addEventListener("input", this.onValueChange.bind(this));
this.timeInput.addEventListener("change", this.onValueChange.bind(this));
};
SaveInput.prototype.onValueChange = function () {
const currentValue = this.timeInput.value;
this.ls.setItem(this.lsKey, currentValue);
};

window.wlb = {
init: function () {
this.saveInput.init();
},
saveInput: new SaveInput(),
};

window.wlb.init();
}

0 comments on commit f427cef

Please sign in to comment.