Skip to content

Commit 686f7eb

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
1 parent 17c7f69 commit 686f7eb

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
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
@@ -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

ui/resizable.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ $.widget("ui.resizable", $.ui.mouse, {
165165
nw: ".ui-resizable-nw"
166166
} );
167167

168-
if (this.handles.constructor === String) {
168+
this._handles = $();
169+
if ( this.handles.constructor === String ) {
169170

170171
if ( this.handles === "all") {
171172
this.handles = "n,e,s,w,se,sw,ne,nw";
@@ -195,14 +196,21 @@ $.widget("ui.resizable", $.ui.mouse, {
195196

196197
this._renderAxis = function(target) {
197198

198-
var i, axis, padPos, padWrapper;
199+
var i, axis, padPos, padWrapper, mouseDownHandlers = {
200+
mousedown: function( event ) {
201+
return that._mouseDown( event );
202+
}
203+
};
199204

200205
target = target || this.element;
201206

202207
for (i in this.handles) {
203208

204209
if (this.handles[i].constructor === String) {
205210
this.handles[i] = this.element.children( this.handles[ i ] ).first().show();
211+
} else if ( this.handles[ i ].jquery || this.handles[i].nodeType ) {
212+
this.handles[ i ] = $( this.handles[ i ] );
213+
this._on( this.handles[ i ], mouseDownHandlers );
206214
}
207215

208216
if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/^(textarea|input|select|button)$/i)) {
@@ -219,11 +227,12 @@ $.widget("ui.resizable", $.ui.mouse, {
219227
target.css(padPos, padWrapper);
220228

221229
this._proportionallyResize();
222-
223230
}
224231

232+
this._handles = this._handles.add( this.handles[ i ] );
233+
225234
// TODO: What's that good for? There's not anything to be executed left
226-
if (!$(this.handles[i]).length) {
235+
if ( !$( this.handles[ i ] ).length ) {
227236
continue;
228237
}
229238
}
@@ -232,8 +241,8 @@ $.widget("ui.resizable", $.ui.mouse, {
232241
// TODO: make renderAxis a prototype function
233242
this._renderAxis(this.element);
234243

235-
this._handles = $(".ui-resizable-handle", this.element)
236-
.disableSelection();
244+
this._handles = this._handles.add( $( ".ui-resizable-handle", this.element ) );
245+
this._handles.disableSelection();
237246

238247
this._handles.mouseover(function() {
239248
if (!that.resizing) {
@@ -267,7 +276,6 @@ $.widget("ui.resizable", $.ui.mouse, {
267276
}
268277

269278
this._mouseInit();
270-
271279
},
272280

273281
_destroy: function() {

0 commit comments

Comments
 (0)