Skip to content

Commit 19783fd

Browse files
benmosherscottgonzalez
authored andcommitted
Resizable: alsoResize more than one element of a jQuery selection
Fixes #4666 Closes gh-1324 Closes gh-1461
1 parent 18e301f commit 19783fd

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
@@ -432,4 +432,34 @@ test( "alsoResize + containment", function() {
432432
equal( other.height(), 150, "alsoResize constrained height at containment edge" );
433433
});
434434

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

ui/resizable.js

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

992992
start: function() {
993993
var that = $(this).resizable( "instance" ),
994-
o = that.options,
995-
_store = function(exp) {
996-
$(exp).each(function() {
997-
var el = $(this);
998-
el.data("ui-resizable-alsoresize", {
999-
width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
1000-
left: parseInt(el.css("left"), 10), top: parseInt(el.css("top"), 10)
1001-
});
1002-
});
1003-
};
994+
o = that.options;
1004995

1005-
if (typeof(o.alsoResize) === "object" && !o.alsoResize.parentNode) {
1006-
if (o.alsoResize.length) {
1007-
o.alsoResize = o.alsoResize[0];
1008-
_store(o.alsoResize);
1009-
} else {
1010-
$.each(o.alsoResize, function(exp) {
1011-
_store(exp);
1012-
});
1013-
}
1014-
} else {
1015-
_store(o.alsoResize);
1016-
}
996+
$(o.alsoResize).each(function() {
997+
var el = $(this);
998+
el.data("ui-resizable-alsoresize", {
999+
width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
1000+
left: parseInt(el.css("left"), 10), top: parseInt(el.css("top"), 10)
1001+
});
1002+
});
10171003
},
10181004

10191005
resize: function(event, ui) {
@@ -1026,35 +1012,23 @@ $.ui.plugin.add("resizable", "alsoResize", {
10261012
width: (that.size.width - os.width) || 0,
10271013
top: (that.position.top - op.top) || 0,
10281014
left: (that.position.left - op.left) || 0
1029-
},
1015+
};
1016+
1017+
$(o.alsoResize).each(function() {
1018+
var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {},
1019+
css = el.parents(ui.originalElement[0]).length ?
1020+
[ "width", "height" ] :
1021+
[ "width", "height", "top", "left" ];
10301022

1031-
_alsoResize = function(exp, c) {
1032-
$(exp).each(function() {
1033-
var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {},
1034-
css = c && c.length ?
1035-
c :
1036-
el.parents(ui.originalElement[0]).length ?
1037-
[ "width", "height" ] :
1038-
[ "width", "height", "top", "left" ];
1039-
1040-
$.each(css, function(i, prop) {
1041-
var sum = (start[prop] || 0) + (delta[prop] || 0);
1042-
if (sum && sum >= 0) {
1043-
style[prop] = sum || null;
1044-
}
1045-
});
1046-
1047-
el.css(style);
1023+
$.each(css, function(i, prop) {
1024+
var sum = (start[prop] || 0) + (delta[prop] || 0);
1025+
if (sum && sum >= 0) {
1026+
style[prop] = sum || null;
1027+
}
10481028
});
1049-
};
10501029

1051-
if (typeof(o.alsoResize) === "object" && !o.alsoResize.nodeType) {
1052-
$.each(o.alsoResize, function(exp, c) {
1053-
_alsoResize(exp, c);
1030+
el.css(style);
10541031
});
1055-
} else {
1056-
_alsoResize(o.alsoResize);
1057-
}
10581032
},
10591033

10601034
stop: function() {

0 commit comments

Comments
 (0)