Skip to content

Commit

Permalink
Merge branch 'MDL-72884' of git://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Nov 2, 2021
2 parents b4fbfb5 + c544288 commit ad7a388
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 42 deletions.
Expand Up @@ -92,7 +92,10 @@ var CSS = {
margin: '0 0 0 0.5em'
}
],

DEFAULTS = {
WIDTH: 160,
HEIGHT: 160,
},
REGEX = {
ISPERCENT: /\d+%/
},
Expand Down Expand Up @@ -550,22 +553,23 @@ Y.namespace('M.atto_image').Button = Y.Base.create('button', Y.M.editor_atto.Edi
image.onload = function() {
var input, currentwidth, currentheight, widthRatio, heightRatio;

// Store dimensions of the raw image, falling back to defaults for images without dimensions (e.g. SVG).
self._rawImageDimensions = {
width: this.width,
height: this.height
width: this.width || DEFAULTS.WIDTH,
height: this.height || DEFAULTS.HEIGHT,
};

input = self._form.one('.' + CSS.INPUTWIDTH);
currentwidth = input.get('value');
if (currentwidth === '') {
input.set('value', this.width);
currentwidth = "" + this.width;
input.set('value', self._rawImageDimensions.width);
currentwidth = "" + self._rawImageDimensions.width;
}
input = self._form.one('.' + CSS.INPUTHEIGHT);
currentheight = input.get('value');
if (currentheight === '') {
input.set('value', this.height);
currentheight = "" + this.height;
input.set('value', self._rawImageDimensions.height);
currentheight = "" + self._rawImageDimensions.height;
}
input = self._form.one('.' + CSS.IMAGEPREVIEW);
input.setAttribute('src', this.src);
Expand All @@ -576,13 +580,10 @@ Y.namespace('M.atto_image').Button = Y.Base.create('button', Y.M.editor_atto.Edi
input = self._form.one('.' + CSS.INPUTCONSTRAIN);
if (currentwidth.match(REGEX.ISPERCENT) && currentheight.match(REGEX.ISPERCENT)) {
input.set('checked', currentwidth === currentheight);
} else if (this.width === 0 || this.height === 0) {
// If we don't have both dimensions of the image, we can't auto-size it, so disable control.
input.set('disabled', 'disabled');
} else {
if (this.width === 0) {
this.width = 1;
}
if (this.height === 0) {
this.height = 1;
}
// This is the same as comparing to 3 decimal places.
widthRatio = Math.round(1000 * parseInt(currentwidth, 10) / this.width);
heightRatio = Math.round(1000 * parseInt(currentheight, 10) / this.height);
Expand Down

0 comments on commit ad7a388

Please sign in to comment.