Skip to content

Commit 18e301f

Browse files
patrixdtjvantoll
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
1 parent 4b017b4 commit 18e301f

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

Diff for: tests/unit/resizable/resizable.html

+1
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">

Diff for: tests/unit/resizable/resizable_options.js

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

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

Diff for: ui/resizable.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ $.widget("ui.resizable", $.ui.mouse, {
168168
nw: ".ui-resizable-nw"
169169
} );
170170

171-
if (this.handles.constructor === String) {
171+
this._handles = $();
172+
if ( this.handles.constructor === String ) {
172173

173174
if ( this.handles === "all") {
174175
this.handles = "n,e,s,w,se,sw,ne,nw";
@@ -206,6 +207,9 @@ $.widget("ui.resizable", $.ui.mouse, {
206207

207208
if (this.handles[i].constructor === String) {
208209
this.handles[i] = this.element.children( this.handles[ i ] ).first().show();
210+
} else if ( this.handles[ i ].jquery || this.handles[ i ].nodeType ) {
211+
this.handles[ i ] = $( this.handles[ i ] );
212+
this._on( this.handles[ i ], { "mousedown": that._mouseDown });
209213
}
210214

211215
if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/^(textarea|input|select|button)$/i)) {
@@ -222,21 +226,17 @@ $.widget("ui.resizable", $.ui.mouse, {
222226
target.css(padPos, padWrapper);
223227

224228
this._proportionallyResize();
225-
226229
}
227230

228-
// TODO: What's that good for? There's not anything to be executed left
229-
if (!$(this.handles[i]).length) {
230-
continue;
231-
}
231+
this._handles = this._handles.add( this.handles[ i ] );
232232
}
233233
};
234234

235235
// TODO: make renderAxis a prototype function
236236
this._renderAxis(this.element);
237237

238-
this._handles = $(".ui-resizable-handle", this.element)
239-
.disableSelection();
238+
this._handles = this._handles.add( this.element.find( ".ui-resizable-handle" ) );
239+
this._handles.disableSelection();
240240

241241
this._handles.mouseover(function() {
242242
if (!that.resizing) {
@@ -270,7 +270,6 @@ $.widget("ui.resizable", $.ui.mouse, {
270270
}
271271

272272
this._mouseInit();
273-
274273
},
275274

276275
_destroy: function() {

0 commit comments

Comments
 (0)