Skip to content

Commit

Permalink
Merge pull request #114 from devforth/bug-out-of-memory
Browse files Browse the repository at this point in the history
fix bugs out-of-memory
  • Loading branch information
ivictbor authored Nov 20, 2020
2 parents 0d90b60 + 515b05e commit f357c7d
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions js/resizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export default class Resizer {
this.wrapper = main.wrapper.querySelector('.ptro-resize-widget-wrapper');
this.inputW = main.wrapper.querySelector('.ptro-resize-widget-wrapper .ptro-resize-width-input');
this.inputH = main.wrapper.querySelector('.ptro-resize-widget-wrapper .ptro-resize-heigth-input');
this.inputWLimit = 10000;
this.inputHLimit = 13000;

this.linkButton = main.wrapper.querySelector('.ptro-resize-widget-wrapper button.ptro-link');
this.linkButtonIcon = main.wrapper.querySelector('.ptro-resize-widget-wrapper button.ptro-link i');
Expand Down Expand Up @@ -65,15 +67,17 @@ export default class Resizer {
};

this.inputW.oninput = () => {
this.newW = +this.inputW.value;
const widthVal = Number(this.inputW.value);
this.validationWidth(widthVal);
if (this.linked) {
const ratio = this.main.size.ratio;
this.newH = Math.round(this.newW / ratio);
this.inputH.value = this.newH;
}
};
this.inputH.oninput = () => {
this.newH = +this.inputH.value;
const heightVal = Number(this.inputH.value);
this.validationHeight(heightVal);
if (this.linked) {
const ratio = this.main.size.ratio;
this.newW = Math.round(this.newH * ratio);
Expand All @@ -82,6 +86,32 @@ export default class Resizer {
};
}

validationWidthValue(value) {
return value <= this.inputWLimit;
}

validationHeightValue(value) {
return value <= this.inputHLimit;
}

validationHeight(value) {
if (this.validationHeightValue(value)) {
this.newH = value;
} else {
this.inputH.value = this.inputHLimit;
this.newH = this.inputHLimit;
}
}

validationWidth(value) {
if (this.validationWidthValue(value)) {
this.newW = value;
} else {
this.inputW.value = this.inputWLimit;
this.newW = this.inputWLimit;
}
}

open() {
this.wrapper.removeAttribute('hidden');
this.opened = true;
Expand Down

0 comments on commit f357c7d

Please sign in to comment.