8000 resizable: aspect ratio was switched (width/height ratio was height/w… · jquery/jquery-ui@f9a7772 · GitHub
Skip to content

Commit f9a7772

Browse files
author
Paul Bakaus
committed
resizable: aspect ratio was switched (width/height ratio was height/width ratio), fixes #3450
1 parent 90d7b7f commit f9a7772

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ui/ui.resizable.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ $.widget("ui.resizable", $.extend({}, $.ui.mouse, {
312312
this.originalMousePosition = { left: e.pageX, top: e.pageY };
313313

314314
//Aspect Ratio
315-
o.aspectRatio = (typeof o.aspectRatio == 'number') ? o.aspectRatio : ((this.originalSize.height / this.originalSize.width)||1);
315+
o.aspectRatio = (typeof o.aspectRatio == 'number') ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height)||1);
316316

317317
if (o.preserveCursor)
318318
$('body').css('cursor', this.axis + '-resize');
@@ -394,10 +394,11 @@ $.widget("ui.resizable", $.extend({}, $.ui.mouse, {
394394
if (data.width) this.size.width = data.width;
395395
},
396396
_updateRatio: function(data, e) {
397+
397398
var o = this.options, cpos = this.position, csize = this.size, a = this.axis;
398399

399-
if (data.height) data.width = (csize.height / o.aspectRatio);
400-
else if (data.width) data.height = (csize.width * o.aspectRatio);
400+
if (data.height) data.width = (csize.height * o.aspectRatio);
401+
else if (data.width) data.height = (csize.width / o.aspectRatio);
401402

402403
if (a == 'sw') {
403404
data.left = cpos.left + (csize.width - data.width);
@@ -580,13 +581,13 @@ $.ui.plugin.add("resizable", "containment", {
580581

581582
if (cp.left < (o.helper ? co.left : cop.left)) {
582583
self.size.width = self.size.width + (o.helper ? (self.position.left - co.left) : (self.position.left - cop.left));
583-
if (pRatio) self.size.height = self.size.width * o.aspectRatio;
584+
if (pRatio) self.size.height = self.size.width / o.aspectRatio;
584585
self.position.left = o.helper ? co.left : cop.left;
585586
}
586587

587588
if (cp.top < (o.helper ? co.top : 0)) {
588589
self.size.height = self.size.height + (o.helper ? (self.position.top - co.top) : self.position.top);
589-
if (pRatio) self.size.width = self.size.height / o.aspectRatio;
590+
if (pRatio) self.size.width = self.size.height * o.aspectRatio;
590591
self.position.top = o.helper ? co.top : 0;
591592
}
592593

@@ -595,12 +596,12 @@ $.ui.plugin.add("resizable", "containment", {
595596

596597
if (woset + self.size.width >= self.parentData.width) {
597598
self.size.width = self.parentData.width - woset;
598-
if (pRatio) self.size.height = self.size.width * o.aspectRatio;
599+
if (pRatio) self.size.height = self.size.width / o.aspectRatio;
599600
}
600601

601602
if (hoset + self.size.height >= self.parentData.height) {
602603
self.size.height = self.parentData.height - hoset;
603-
if (pRatio) self.size.width = self.size.height / o.aspectRatio;
604+
if (pRatio) self.size.width = self.size.height * o.aspectRatio;
604605
}
605606
},
606607

0 commit comments

Comments
 (0)