+ this.loadFromLocalStorage();
+ this.applyToInputs(settingInputs);
+ this.listenToInputChanges(settingInputs);
+ }
+
+ applyToInputs(inputs) {
+ for (const input of inputs) {
+ const name = input.getAttribute('name').replace('md-', '');
+ input.checked = this.settingMap[name];
+ }
+ }
+
+ listenToInputChanges(inputs) {
+ for (const input of inputs) {
+ input.addEventListener('change', () => {
+ const name = input.getAttribute('name').replace('md-', '');
+ this.set(name, input.checked);
+ });
+ }
+ }
+
+ loadFromLocalStorage() {
+ const lsValString = window.localStorage.getItem('md-editor-settings');
+ if (!lsValString) {
+ return;
+ }
+
+ const lsVals = JSON.parse(lsValString);
+ for (const [key, value] of Object.entries(lsVals)) {
+ if (value !== null && this.settingMap[key] !== undefined) {
+ this.settingMap[key] = value;
+ }
+ }