Skip to content

Commit 65f31c2

Browse files
patrixdscottgonzalez
authored andcommitted
Resizable: Modified to allow jquery objects as handles
Custom handlers did not work as jquery objects (outside the resizable element) Fixes #9658 Closes gh-1445 (cherry picked from commit 18e301f)
1 parent de75b40 commit 65f31c2

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

tests/unit/resizable/resizable.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969

7070
<div id="container">
7171
<div id="resizable1">I'm a resizable.</div>
72+
<div id="resizer1" class="ui-resizable-handle ui-resizable-s"></div>
7273
</div>
7374

7475
<div id="container2">

tests/unit/resizable/resizable_options.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,35 @@ test("ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1
375375
equal( target.height(), 100, "compare maxHeight" );
376376
});
377377

378+
379+
test( "custom handles { handles: { 's': $('#resizer1'), containment: 'parent' }", function () {
380+
expect( 2 );
381+
382+
var handle = "#resizer1",
383+
target = $( "#resizable1" ).resizable({ handles: { "s": $( "#resizer1" ) }, containment: "parent" });
384+
385+
TestHelpers.resizable.drag( handle, 0, 70 );
386+
equal( target.height(), 170, "compare height" );
387+
388+
TestHelpers.resizable.drag( handle, 0, -70 );
389+
equal( target.height(), 100, "compare height" );
390+
});
391+
392+
393+
test( "custom handles { handles: { 's': $('#resizer1')[0], containment: 'parent' }", function () {
394+
expect( 2 );
395+
396+
var handle = "#resizer1",
397+
target = $( "#resizable1" ).resizable({ handles: { "s": $( "#resizer1" )[ 0 ] }, containment: "parent" });
398+
399+
TestHelpers.resizable.drag( handle, 0, 70 );
400+
equal( target.height(), 170, "compare height" );
401+
402+
TestHelpers.resizable.drag( handle, 0, -70 );
403+
equal( target.height(), 100, "compare height" );
404+
});
405+
406+
378407
test("zIndex, applied to all handles", function() {
379408
expect(8);
380409

ui/resizable.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ $.widget("ui.resizable", $.ui.mouse, {
160160
nw: ".ui-resizable-nw"
161161
} );
162162

163-
if (this.handles.constructor === String) {
163+
this._handles = $();
164+
if ( this.handles.constructor === String ) {
164165

165166
if ( this.handles === "all") {
166167
this.handles = "n,e,s,w,se,sw,ne,nw";
@@ -198,6 +199,9 @@ $.widget("ui.resizable", $.ui.mouse, {
198199

199200
if (this.handles[i].constructor === String) {
200201
this.handles[i] = this.element.children( this.handles[ i ] ).first().show();
202+
} else if ( this.handles[ i ].jquery || this.handles[ i ].nodeType ) {
203+
this.handles[ i ] = $( this.handles[ i ] );
204+
this._on( this.handles[ i ], { "mousedown": that._mouseDown });
201205
}
202206

203207
if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/^(textarea|input|select|button)$/i)) {
@@ -214,21 +218,17 @@ $.widget("ui.resizable", $.ui.mouse, {
214218
target.css(padPos, padWrapper);
215219

216220
this._proportionallyResize();
217-
218221
}
219222

220-
// TODO: What's that good for? There's not anything to be executed left
221-
if (!$(this.handles[i]).length) {
222-
continue;
223-
}
223+
this._handles = this._handles.add( this.handles[ i ] );
224224
}
225225
};
226226

227227
// TODO: make renderAxis a prototype function
228228
this._renderAxis(this.element);
229229

230-
this._handles = $(".ui-resizable-handle", this.element)
231-
.disableSelection();
230+
this._handles = this._handles.add( this.element.find( ".ui-resizable-handle" ) );
231+
this._handles.disableSelection();
232232

233233
this._handles.mouseover(function() {
234234
if (!that.resizing) {
@@ -262,7 +262,6 @@ $.widget("ui.resizable", $.ui.mouse, {
262262
}
263263

264264
this._mouseInit();
265-
266265
},
267266

268267
_destroy: function() {

0 commit comments

Comments
 (0)