(main)
| 4 | |
| 5 | export default class Settings { |
| 6 | constructor(main) { |
| 7 | this.main = main; |
| 8 | |
| 9 | this.wrapper = main.wrapper.querySelector('.ptro-settings-widget-wrapper'); |
| 10 | this.inputPixelSize = main.wrapper.querySelector('.ptro-settings-widget-wrapper .ptro-pixel-size-input'); |
| 11 | |
| 12 | this.applyButton = main.wrapper.querySelector('.ptro-settings-widget-wrapper button.ptro-apply'); |
| 13 | this.closeButton = main.wrapper.querySelector('.ptro-settings-widget-wrapper button.ptro-close'); |
| 14 | this.clearButton = main.wrapper.querySelector('.ptro-settings-widget-wrapper button.ptro-clear'); |
| 15 | this.bgSelBtn = main.wrapper.querySelector('.ptro-settings-widget-wrapper .ptro-color-btn'); |
| 16 | this.errorHolder = main.wrapper.querySelector('.ptro-settings-widget-wrapper .ptro-error'); |
| 17 | |
| 18 | this.clearButton.onclick = () => { |
| 19 | this.main.currentBackground = this.main.colorWidgetState.bg.alphaColor; |
| 20 | this.main.currentBackgroundAlpha = this.main.colorWidgetState.bg.alpha; |
| 21 | this.main.clearBackground(); |
| 22 | this.startClose(); |
| 23 | }; |
| 24 | |
| 25 | this.bgSelBtn.onclick = () => { |
| 26 | this.main.colorPicker.open(this.main.colorWidgetState.bg); |
| 27 | }; |
| 28 | |
| 29 | this.closeButton.onclick = () => { |
| 30 | this.startClose(); |
| 31 | }; |
| 32 | |
| 33 | if (this.applyButton) { |
| 34 | this.applyButton.onclick = () => { |
| 35 | let pixelVal = trim(this.inputPixelSize.value); |
| 36 | let valid; |
| 37 | if (pixelVal.slice(-1) === '%') { |
| 38 | const checkInt = trim(pixelVal.slice(0, -1)); |
| 39 | valid = /^\d+$/.test(checkInt) && parseInt(checkInt, 10) !== 0; |
| 40 | if (valid) { |
| 41 | pixelVal = `${checkInt}%`; |
| 42 | } |
| 43 | } else { |
| 44 | valid = /^\d+$/.test(pixelVal) && parseInt(pixelVal, 10) !== 0; |
| 45 | } |
| 46 | if (valid) { |
| 47 | this.main.select.pixelizePixelSize = pixelVal; |
| 48 | setParam('pixelizePixelSize', pixelVal); |
| 49 | this.startClose(); |
| 50 | this.errorHolder.setAttribute('hidden', ''); |
| 51 | } else { |
| 52 | this.errorHolder.innerText = tr('wrongPixelSizeValue'); |
| 53 | this.errorHolder.removeAttribute('hidden'); |
| 54 | } |
| 55 | }; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | handleKeyDown(event) { |
| 60 | if (event.keyCode === KEYS.enter) { |
nothing calls this directly
no test coverage detected