(main)
| 3 | |
| 4 | export default class Resizer { |
| 5 | constructor(main) { |
| 6 | this.main = main; |
| 7 | |
| 8 | this.wrapper = main.wrapper.querySelector('.ptro-resize-widget-wrapper'); |
| 9 | this.inputW = main.wrapper.querySelector('.ptro-resize-widget-wrapper .ptro-resize-width-input'); |
| 10 | this.inputH = main.wrapper.querySelector('.ptro-resize-widget-wrapper .ptro-resize-heigth-input'); |
| 11 | |
| 12 | this.inputWLimit = 10000; |
| 13 | this.inputHLimit = 13000; |
| 14 | |
| 15 | this.linkButton = main.wrapper.querySelector('.ptro-resize-widget-wrapper button.ptro-link'); |
| 16 | this.linkButtonIcon = main.wrapper.querySelector('.ptro-resize-widget-wrapper button.ptro-link i'); |
| 17 | this.closeButton = main.wrapper.querySelector('.ptro-resize-widget-wrapper button.ptro-close'); |
| 18 | this.scaleButton = main.wrapper.querySelector('.ptro-resize-widget-wrapper button.ptro-scale'); |
| 19 | this.resizeButton = main.wrapper.querySelector('.ptro-resize-widget-wrapper button.ptro-resize'); |
| 20 | this.linked = true; |
| 21 | this.closeButton.onclick = () => { |
| 22 | this.startClose(); |
| 23 | }; |
| 24 | |
| 25 | this.scaleButton.onclick = () => { |
| 26 | if (!Resizer.validationZeroValue(this.newH, this.newW)) return; |
| 27 | const origW = this.main.size.w; |
| 28 | const origH = this.main.size.h; |
| 29 | |
| 30 | const tmpData = this.main.canvas.toDataURL(); |
| 31 | |
| 32 | this.main.resize(this.newW, this.newH); |
| 33 | |
| 34 | this.main.ctx.save(); |
| 35 | // this.ctx.translate(h / 2, w / 2); |
| 36 | this.main.ctx.scale(this.newW / origW, this.newH / origH); |
| 37 | const img = new Image(); |
| 38 | img.onload = () => { |
| 39 | this.main.ctx.drawImage(img, 0, 0); |
| 40 | this.main.adjustSizeFull(); |
| 41 | this.main.ctx.restore(); |
| 42 | this.main.worklog.captureState(); |
| 43 | this.startClose(); |
| 44 | }; |
| 45 | img.src = tmpData; |
| 46 | }; |
| 47 | |
| 48 | this.resizeButton.onclick = () => { |
| 49 | if (!Resizer.validationZeroValue(this.newH, this.newW)) return; |
| 50 | const tmpData = this.main.canvas.toDataURL(); |
| 51 | this.main.resize(this.newW, this.newH); |
| 52 | this.main.clearBackground(); |
| 53 | const img = new Image(); |
| 54 | img.onload = () => { |
| 55 | this.main.ctx.drawImage(img, 0, 0); |
| 56 | this.main.adjustSizeFull(); |
| 57 | this.main.worklog.captureState(); |
| 58 | this.startClose(); |
| 59 | }; |
| 60 | img.src = tmpData; |
| 61 | }; |
| 62 |
nothing calls this directly
no test coverage detected