Skip to content

Commit 31e7099

Browse files
benmosherscottgonzalez
authored andcommitted
Resizable: alsoResize more than one element of a jQuery selection
Fixes #4666 Closes gh-1324 Closes gh-1461 (cherry picked from commit 19783fd)
1 parent 65f31c2 commit 31e7099

File tree

2 files changed

+51
-47
lines changed

2 files changed

+51
-47
lines changed

tests/unit/resizable/resizable_options.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,4 +433,34 @@ test( "alsoResize + containment", function() {
433433
equal( other.height(), 150, "alsoResize constrained height at containment edge" );
434434
});
435435

436+
test( "alsoResize + multiple selection", function() {
437+
expect( 6 );
438+
var other1 = $( "<div>" )
439+
.addClass( "other" )
440+
.css({
441+
width: 50,
442+
height: 50
443+
})
444+
.appendTo( "body" ),
445+
other2 = $( "<div>" )
446+
.addClass( "other" )
447+
.css({
448+
width: 50,
449+
height: 50
450+
})
451+
.appendTo( "body"),
452+
element = $( "#resizable1" ).resizable({
453+
alsoResize: other1.add( other2 ),
454+
containment: "#container"
455+
});
456+
457+
TestHelpers.resizable.drag( ".ui-resizable-se", 400, 400 );
458+
equal( element.width(), 300, "resizable constrained width at containment edge" );
459+
equal( element.height(), 200, "resizable constrained height at containment edge" );
460+
equal( other1.width(), 250, "alsoResize o1 constrained width at containment edge" );
461+
equal( other1.height(), 150, "alsoResize o1 constrained height at containment edge" );
462+
equal( other2.width(), 250, "alsoResize o2 constrained width at containment edge" );
463+
equal( other2.height(), 150, "alsoResize o2 constrained height at containment edge" );
464+
});
465+
436466
})(jQuery);

ui/resizable.js

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -983,29 +983,15 @@ $.ui.plugin.add("resizable", "alsoResize", {
983983

984984
start: function() {
985985
var that = $(this).resizable( "instance" ),
986-
o = that.options,
987-
_store = function(exp) {
988-
$(exp).each(function() {
989-
var el = $(this);
990-
el.data("ui-resizable-alsoresize", {
991-
width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
992-
left: parseInt(el.css("left"), 10), top: parseInt(el.css("top"), 10)
993-
});
994-
});
995-
};
986+
o = that.options;
996987

997-
if (typeof(o.alsoResize) === "object" && !o.alsoResize.parentNode) {
998-
if (o.alsoResize.length) {
999-
o.alsoResize = o.alsoResize[0];
1000-
_store(o.alsoResize);
1001-
} else {
1002-
$.each(o.alsoResize, function(exp) {
1003-
_store(exp);
1004-
});
1005-
}
1006-
} else {
1007-
_store(o.alsoResize);
1008-
}
988+
$(o.alsoResize).each(function() {
989+
var el = $(this);
990+
el.data("ui-resizable-alsoresize", {
991+
width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
992+
left: parseInt(el.css("left"), 10), top: parseInt(el.css("top"), 10)
993+
});
994+
});
1009995
},
1010996

1011997
resize: function(event, ui) {
@@ -1018,35 +1004,23 @@ $.ui.plugin.add("resizable", "alsoResize", {
10181004
width: (that.size.width - os.width) || 0,
10191005
top: (that.position.top - op.top) || 0,
10201006
left: (that.position.left - op.left) || 0
1021-
},
1007+
};
1008+
1009+
$(o.alsoResize).each(function() {
1010+
var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {},
1011+
css = el.parents(ui.originalElement[0]).length ?
1012+
[ "width", "height" ] :
1013+
[ "width", "height", "top", "left" ];
10221014

1023-
_alsoResize = function(exp, c) {
1024-
$(exp).each(function() {
1025-
var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {},
1026-
css = c && c.length ?
1027-
c :
1028-
el.parents(ui.originalElement[0]).length ?
1029-
[ "width", "height" ] :
1030-
[ "width", "height", "top", "left" ];
1031-
1032-
$.each(css, function(i, prop) {
1033-
var sum = (start[prop] || 0) + (delta[prop] || 0);
1034-
if (sum && sum >= 0) {
1035-
style[prop] = sum || null;
1036-
}
1037-
});
1038-
1039-
el.css(style);
1015+
$.each(css, function(i, prop) {
1016+
var sum = (start[prop] || 0) + (delta[prop] || 0);
1017+
if (sum && sum >= 0) {
1018+
style[prop] = sum || null;
1019+
}
10401020
});
1041-
};
10421021

1043-
if (typeof(o.alsoResize) === "object" && !o.alsoResize.nodeType) {
1044-
$.each(o.alsoResize, function(exp, c) {
1045-
_alsoResize(exp, c);
1022+
el.css(style);
10461023
});
1047-
} else {
1048-
_alsoResize(o.alsoResize);
1049-
}
10501024
},
10511025

10521026
stop: function() {

0 commit comments

Comments
 (0)