Lines of Code | 33 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | import './style.scss'; |
||
2 | import templateHTML from './template.html'; |
||
3 | import { Storage } from '../storage'; |
||
4 | |||
5 | export class Control { |
||
6 | constructor() { |
||
7 | this.storage = new Storage(); |
||
8 | } |
||
9 | |||
10 | getItem( settingName ) { |
||
11 | return this.storage.getItem( settingName ); |
||
12 | } |
||
13 | |||
14 | render() { |
||
15 | this.$control = $( templateHTML ); |
||
16 | this.$save = this.$control.find( '.save-settings' ); |
||
17 | this.$clear = this.$control.find( '.clear-storage' ); |
||
18 | |||
19 | $( 'save-ui' ).replaceWith( this.$control ); |
||
20 | } |
||
21 | |||
22 | setup( settingName, getValueCb ) { |
||
23 | this.$save.on( 'click', () => { |
||
24 | this.storage.setItem( settingName, getValueCb( settingName ) ); |
||
25 | setTimeout( () => location.reload() ); |
||
26 | } ); |
||
27 | |||
28 | this.$clear.on( 'click', () => { |
||
29 | this.storage.removeItem( settingName ); |
||
30 | setTimeout( () => location.reload() ); |
||
31 | } ); |
||
32 | } |
||
33 | } |
||
34 |