mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-10-05 01:44:18 +00:00
Resizable: correct aspectRatio handling with min/max dimensions. Fixed #4951 - Resizable with aspectRatio true & a maxWidth doesn't obey ratio once hit max width.
(cherry picked from commit 981e96948f
)
This commit is contained in:
parent
3735bab147
commit
b196d1fb61
34
ui/jquery.ui.resizable.js
vendored
34
ui/jquery.ui.resizable.js
vendored
@ -293,6 +293,8 @@ $.widget("ui.resizable", $.ui.mouse, {
|
|||||||
// Calculate the attrs that will be change
|
// Calculate the attrs that will be change
|
||||||
var data = trigger.apply(this, [event, dx, dy]), ie6 = $.browser.msie && $.browser.version < 7, csdif = this.sizeDiff;
|
var data = trigger.apply(this, [event, dx, dy]), ie6 = $.browser.msie && $.browser.version < 7, csdif = this.sizeDiff;
|
||||||
|
|
||||||
|
// Put this in the mouseDrag handler since the user can start pressing shift while resizing
|
||||||
|
this._updateVirtualBoundaries(event.shiftKey);
|
||||||
if (this._aspectRatio || event.shiftKey)
|
if (this._aspectRatio || event.shiftKey)
|
||||||
data = this._updateRatio(data, event);
|
data = this._updateRatio(data, event);
|
||||||
|
|
||||||
@ -351,6 +353,32 @@ $.widget("ui.resizable", $.ui.mouse, {
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_updateVirtualBoundaries: function(forceAspectRatio) {
|
||||||
|
var o = this.options, pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b;
|
||||||
|
|
||||||
|
b = {
|
||||||
|
minWidth: isNumber(o.minWidth) ? o.minWidth : 0,
|
||||||
|
maxWidth: isNumber(o.maxWidth) ? o.maxWidth : Infinity,
|
||||||
|
minHeight: isNumber(o.minHeight) ? o.minHeight : 0,
|
||||||
|
maxHeight: isNumber(o.maxHeight) ? o.maxHeight : Infinity
|
||||||
|
};
|
||||||
|
|
||||||
|
if(this._aspectRatio || forceAspectRatio) {
|
||||||
|
// We want to create an enclosing box whose aspect ration is the requested one
|
||||||
|
// First, compute the "projected" size for each dimension based on the aspect ratio and other dimension
|
||||||
|
pMinWidth = b.minHeight * this.aspectRatio;
|
||||||
|
pMinHeight = b.minWidth / this.aspectRatio;
|
||||||
|
pMaxWidth = b.maxHeight * this.aspectRatio;
|
||||||
|
pMaxHeight = b.maxWidth / this.aspectRatio;
|
||||||
|
|
||||||
|
if(pMinWidth > b.minWidth) b.minWidth = pMinWidth;
|
||||||
|
if(pMinHeight > b.minHeight) b.minHeight = pMinHeight;
|
||||||
|
if(pMaxWidth < b.maxWidth) b.maxWidth = pMaxWidth;
|
||||||
|
if(pMaxHeight < b.maxHeight) b.maxHeight = pMaxHeight;
|
||||||
|
}
|
||||||
|
this._vBoundaries = b;
|
||||||
|
},
|
||||||
|
|
||||||
_updateCache: function(data) {
|
_updateCache: function(data) {
|
||||||
var o = this.options;
|
var o = this.options;
|
||||||
this.offset = this.helper.offset();
|
this.offset = this.helper.offset();
|
||||||
@ -364,8 +392,8 @@ $.widget("ui.resizable", $.ui.mouse, {
|
|||||||
|
|
||||||
var o = this.options, cpos = this.position, csize = this.size, a = this.axis;
|
var o = this.options, cpos = this.position, csize = this.size, a = this.axis;
|
||||||
|
|
||||||
if (data.height) data.width = (csize.height * this.aspectRatio);
|
if (isNumber(data.height)) data.width = (data.height * this.aspectRatio);
|
||||||
else if (data.width) data.height = (csize.width / this.aspectRatio);
|
else if (isNumber(data.width)) data.height = (data.width / this.aspectRatio);
|
||||||
|
|
||||||
if (a == 'sw') {
|
if (a == 'sw') {
|
||||||
data.left = cpos.left + (csize.width - data.width);
|
data.left = cpos.left + (csize.width - data.width);
|
||||||
@ -381,7 +409,7 @@ $.widget("ui.resizable", $.ui.mouse, {
|
|||||||
|
|
||||||
_respectSize: function(data, event) {
|
_respectSize: function(data, event) {
|
||||||
|
|
||||||
var el = this.helper, o = this.options, pRatio = this._aspectRatio || event.shiftKey, a = this.axis,
|
var el = this.helper, o = this._vBoundaries, pRatio = this._aspectRatio || event.shiftKey, a = this.axis,
|
||||||
ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
|
ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
|
||||||
isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height);
|
isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user