From adf427a9970cd98ad08603ebb39fd6aa81427c12 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Mon, 25 Aug 2014 14:07:25 -0400 Subject: [PATCH 1/2] Resizable: alsoResize more than one element of a jQuery selection Fixes #4666 Closes gh-1324 --- tests/unit/resizable/resizable_options.js | 30 +++++++++++++++++++++++ ui/resizable.js | 23 ++--------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/tests/unit/resizable/resizable_options.js b/tests/unit/resizable/resizable_options.js index a2c95790b58..e5cb1c71309 100644 --- a/tests/unit/resizable/resizable_options.js +++ b/tests/unit/resizable/resizable_options.js @@ -432,4 +432,34 @@ test( "alsoResize + containment", function() { equal( other.height(), 150, "alsoResize constrained height at containment edge" ); }); +test( "alsoResize + multiple selection", function() { + expect( 6 ); + var other1 = $( "
" ) + .addClass("other") + .css({ + width: 50, + height: 50 + }) + .appendTo( "body" ), + other2 = $( "
" ) + .addClass("other") + .css({ + width: 50, + height: 50 + }) + .appendTo( "body"), + element = $( "#resizable1" ).resizable({ + alsoResize: $.merge(other1, other2), + containment: "#container" + }); + + TestHelpers.resizable.drag( ".ui-resizable-se", 400, 400 ); + equal( element.width(), 300, "resizable constrained width at containment edge" ); + equal( element.height(), 200, "resizable constrained height at containment edge" ); + equal( other1.width(), 250, "alsoResize o1 constrained width at containment edge" ); + equal( other1.height(), 150, "alsoResize o1 constrained height at containment edge" ); + equal( other2.width(), 250, "alsoResize o2 constrained width at containment edge" ); + equal( other2.height(), 150, "alsoResize o2 constrained height at containment edge" ); +}); + })(jQuery); diff --git a/ui/resizable.js b/ui/resizable.js index c4bc3652998..d44370779b5 100644 --- a/ui/resizable.js +++ b/ui/resizable.js @@ -1001,19 +1001,7 @@ $.ui.plugin.add("resizable", "alsoResize", { }); }); }; - - if (typeof(o.alsoResize) === "object" && !o.alsoResize.parentNode) { - if (o.alsoResize.length) { - o.alsoResize = o.alsoResize[0]; - _store(o.alsoResize); - } else { - $.each(o.alsoResize, function(exp) { - _store(exp); - }); - } - } else { - _store(o.alsoResize); - } + _store(o.alsoResize); }, resize: function(event, ui) { @@ -1047,14 +1035,7 @@ $.ui.plugin.add("resizable", "alsoResize", { el.css(style); }); }; - - if (typeof(o.alsoResize) === "object" && !o.alsoResize.nodeType) { - $.each(o.alsoResize, function(exp, c) { - _alsoResize(exp, c); - }); - } else { - _alsoResize(o.alsoResize); - } + _alsoResize(o.alsoResize); }, stop: function() { From 7eb0f768802440a9e8c57045a8dc72e9fa7ed090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Tue, 3 Mar 2015 10:54:49 -0500 Subject: [PATCH 2/2] [fixup]: Clean up from gh-1324 --- tests/unit/resizable/resizable_options.js | 6 +-- ui/resizable.js | 55 ++++++++++------------- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/tests/unit/resizable/resizable_options.js b/tests/unit/resizable/resizable_options.js index e5cb1c71309..6e3a93a2f85 100644 --- a/tests/unit/resizable/resizable_options.js +++ b/tests/unit/resizable/resizable_options.js @@ -435,21 +435,21 @@ test( "alsoResize + containment", function() { test( "alsoResize + multiple selection", function() { expect( 6 ); var other1 = $( "
" ) - .addClass("other") + .addClass( "other" ) .css({ width: 50, height: 50 }) .appendTo( "body" ), other2 = $( "
" ) - .addClass("other") + .addClass( "other" ) .css({ width: 50, height: 50 }) .appendTo( "body"), element = $( "#resizable1" ).resizable({ - alsoResize: $.merge(other1, other2), + alsoResize: other1.add( other2 ), containment: "#container" }); diff --git a/ui/resizable.js b/ui/resizable.js index d44370779b5..09efc9a37d6 100644 --- a/ui/resizable.js +++ b/ui/resizable.js @@ -991,17 +991,15 @@ $.ui.plugin.add("resizable", "alsoResize", { start: function() { var that = $(this).resizable( "instance" ), - o = that.options, - _store = function(exp) { - $(exp).each(function() { - var el = $(this); - el.data("ui-resizable-alsoresize", { - width: parseInt(el.width(), 10), height: parseInt(el.height(), 10), - left: parseInt(el.css("left"), 10), top: parseInt(el.css("top"), 10) - }); - }); - }; - _store(o.alsoResize); + o = that.options; + + $(o.alsoResize).each(function() { + var el = $(this); + el.data("ui-resizable-alsoresize", { + width: parseInt(el.width(), 10), height: parseInt(el.height(), 10), + left: parseInt(el.css("left"), 10), top: parseInt(el.css("top"), 10) + }); + }); }, resize: function(event, ui) { @@ -1014,28 +1012,23 @@ $.ui.plugin.add("resizable", "alsoResize", { width: (that.size.width - os.width) || 0, top: (that.position.top - op.top) || 0, left: (that.position.left - op.left) || 0 - }, + }; + + $(o.alsoResize).each(function() { + var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {}, + css = el.parents(ui.originalElement[0]).length ? + [ "width", "height" ] : + [ "width", "height", "top", "left" ]; - _alsoResize = function(exp, c) { - $(exp).each(function() { - var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {}, - css = c && c.length ? - c : - el.parents(ui.originalElement[0]).length ? - [ "width", "height" ] : - [ "width", "height", "top", "left" ]; - - $.each(css, function(i, prop) { - var sum = (start[prop] || 0) + (delta[prop] || 0); - if (sum && sum >= 0) { - style[prop] = sum || null; - } - }); - - el.css(style); + $.each(css, function(i, prop) { + var sum = (start[prop] || 0) + (delta[prop] || 0); + if (sum && sum >= 0) { + style[prop] = sum || null; + } }); - }; - _alsoResize(o.alsoResize); + + el.css(style); + }); }, stop: function() {