]> source.dussan.org Git - jquery-ui.git/commitdiff
Resizable: alsoResize more than one element of a jQuery selection
authorBen Mosher <me@benmosher.com>
Mon, 25 Aug 2014 18:07:25 +0000 (14:07 -0400)
committerScott González <scott.gonzalez@gmail.com>
Wed, 4 Mar 2015 13:51:06 +0000 (08:51 -0500)
Fixes #4666
Closes gh-1324
Closes gh-1461

tests/unit/resizable/resizable_options.js
ui/resizable.js

index a2c95790b58de258ff2a2d3ab59d767cad80df8b..6e3a93a2f8563c56f2c7148e49dd529f3e6ba37c 100644 (file)
@@ -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 = $( "<div>" )
+                       .addClass( "other" )
+                       .css({
+                               width: 50,
+                               height: 50
+                       })
+                       .appendTo( "body" ),
+               other2 = $( "<div>" )
+                       .addClass( "other" )
+                       .css({
+                               width: 50,
+                               height: 50
+                       })
+                       .appendTo( "body"),
+               element = $( "#resizable1" ).resizable({
+                       alsoResize: other1.add( 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);
index c4bc36529986ebf2793dfd34a950367e5bb77038..09efc9a37d61e21ced18c5479c87d71163a4bae0 100644 (file)
@@ -991,29 +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)
-                                       });
-                               });
-                       };
+                       o = that.options;
 
-               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);
-               }
+               $(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) {
@@ -1026,35 +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;
+                                       }
                                });
-                       };
 
-               if (typeof(o.alsoResize) === "object" && !o.alsoResize.nodeType) {
-                       $.each(o.alsoResize, function(exp, c) {
-                               _alsoResize(exp, c);
+                               el.css(style);
                        });
-               } else {
-                       _alsoResize(o.alsoResize);
-               }
        },
 
        stop: function() {