]> source.dussan.org Git - jquery-ui.git/commitdiff
Resizable: Modified to allow jquery objects as handles
authorPatricia Juarez <patrixd@gmail.com>
Thu, 14 Nov 2013 12:40:57 +0000 (13:40 +0100)
committerScott González <scott.gonzalez@gmail.com>
Tue, 10 Mar 2015 16:23:56 +0000 (12:23 -0400)
Custom handlers did not work as jquery objects (outside the resizable element)

Fixes #9658
Closes gh-1445
(cherry picked from commit 18e301f4e29c2080e9aa9dac87c00dee137cb6c9)

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

index 5668c909a226ec3ef1e2c6d4ef2563794ad39414..a44346e7cbaaaa15ab1947d5f89531b0545a96a6 100644 (file)
@@ -69,6 +69,7 @@
 
 <div id="container">
        <div id="resizable1">I'm a resizable.</div>
+       <div id="resizer1" class="ui-resizable-handle ui-resizable-s"></div>
 </div>
 
 <div id="container2">
index 2b66fda3e45fe8803a9a96c113fe095fbef466b1..d6829484528c3f7753c97d2003b8a33c3669fd42 100644 (file)
@@ -375,6 +375,35 @@ test("ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1
        equal( target.height(), 100, "compare maxHeight" );
 });
 
+
+test( "custom handles { handles: { 's': $('#resizer1'), containment: 'parent' }", function () {
+       expect( 2 );
+
+       var handle = "#resizer1",
+               target = $( "#resizable1" ).resizable({ handles: { "s": $( "#resizer1" ) }, containment: "parent" });
+
+       TestHelpers.resizable.drag( handle, 0, 70 );
+       equal( target.height(), 170, "compare height" );
+
+       TestHelpers.resizable.drag( handle, 0, -70 );
+       equal( target.height(), 100, "compare height" );
+});
+
+
+test( "custom handles { handles: { 's': $('#resizer1')[0], containment: 'parent' }", function () {
+       expect( 2 );
+
+       var handle = "#resizer1",
+               target = $( "#resizable1" ).resizable({ handles: { "s": $( "#resizer1" )[ 0 ] }, containment: "parent" });
+
+       TestHelpers.resizable.drag( handle, 0, 70 );
+       equal( target.height(), 170, "compare height" );
+
+       TestHelpers.resizable.drag( handle, 0, -70 );
+       equal( target.height(), 100, "compare height" );
+});
+
+
 test("zIndex, applied to all handles", function() {
        expect(8);
 
index 88b9ee7ea3dcfd5ae099edbc75f00297fb91b728..2df2413c7c7efe6e865a6dd9d90c42c221f07dfb 100644 (file)
@@ -160,7 +160,8 @@ $.widget("ui.resizable", $.ui.mouse, {
                                        nw: ".ui-resizable-nw"
                                } );
 
-               if (this.handles.constructor === String) {
+               this._handles = $();
+               if ( this.handles.constructor === String ) {
 
                        if ( this.handles === "all") {
                                this.handles = "n,e,s,w,se,sw,ne,nw";
@@ -198,6 +199,9 @@ $.widget("ui.resizable", $.ui.mouse, {
 
                                if (this.handles[i].constructor === String) {
                                        this.handles[i] = this.element.children( this.handles[ i ] ).first().show();
+                               } else if ( this.handles[ i ].jquery || this.handles[ i ].nodeType ) {
+                                       this.handles[ i ] = $( this.handles[ i ] );
+                                       this._on( this.handles[ i ], { "mousedown": that._mouseDown });
                                }
 
                                if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/^(textarea|input|select|button)$/i)) {
@@ -214,21 +218,17 @@ $.widget("ui.resizable", $.ui.mouse, {
                                        target.css(padPos, padWrapper);
 
                                        this._proportionallyResize();
-
                                }
 
-                               // TODO: What's that good for? There's not anything to be executed left
-                               if (!$(this.handles[i]).length) {
-                                       continue;
-                               }
+                               this._handles = this._handles.add( this.handles[ i ] );
                        }
                };
 
                // TODO: make renderAxis a prototype function
                this._renderAxis(this.element);
 
-               this._handles = $(".ui-resizable-handle", this.element)
-                       .disableSelection();
+               this._handles = this._handles.add( this.element.find( ".ui-resizable-handle" ) );
+               this._handles.disableSelection();
 
                this._handles.mouseover(function() {
                        if (!that.resizing) {
@@ -262,7 +262,6 @@ $.widget("ui.resizable", $.ui.mouse, {
                }
 
                this._mouseInit();
-
        },
 
        _destroy: function() {