Skip to content

Commit 5beae72

Browse files
committed
Resizable: Fix size/position changes in resize event
Fixes #10351 Closes jquerygh-1292
1 parent 9bb51d3 commit 5beae72

File tree

2 files changed

+58
-23
lines changed

2 files changed

+58
-23
lines changed

tests/unit/resizable/resizable_events.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,27 @@ test("resize (grid)", function() {
146146

147147
});
148148

149+
test( "resize, custom adjustment", function() {
150+
expect( 4 );
151+
152+
var handle = ".ui-resizable-se",
153+
element = $( "#resizable1" ).resizable({
154+
resize: function( event, ui ) {
155+
ui.size.width = 100;
156+
ui.size.height = 200;
157+
ui.position.left = 300;
158+
ui.position.top = 400;
159+
}
160+
});
161+
162+
TestHelpers.resizable.drag( handle, 50, 50 );
163+
164+
equal( element.width(), 100, "resize event can control width" );
165+
equal( element.height(), 200, "resize event can control height" );
166+
equal( element.position().left, 300, "resize event can control left" );
167+
equal( element.position().top, 400, "resize event can control top" );
168+
});
169+
149170
test("stop", function() {
150171

151172
expect(5);

ui/resizable.js

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -321,22 +321,14 @@ $.widget("ui.resizable", $.ui.mouse, {
321321

322322
_mouseDrag: function(event) {
323323

324-
var data,
325-
el = this.helper, props = {},
324+
var data, props,
326325
smp = this.originalMousePosition,
327326
a = this.axis,
328327
dx = (event.pageX-smp.left)||0,
329328
dy = (event.pageY-smp.top)||0,
330329
trigger = this._change[a];
331330

332-
this.prevPosition = {
333-
top: this.position.top,
334-
left: this.position.left
335-
};
336-
this.prevSize = {
337-
width: this.size.width,
338-
height: this.size.height
339-
};
331+
this._updatePrevProperties();
340332

341333
if (!trigger) {
342334
return false;
@@ -355,26 +347,16 @@ $.widget("ui.resizable", $.ui.mouse, {
355347

356348
this._propagate("resize", event);
357349

358-
if ( this.position.top !== this.prevPosition.top ) {
359-
props.top = this.position.top + "px";
360-
}
361-
if ( this.position.left !== this.prevPosition.left ) {
362-
props.left = this.position.left + "px";
363-
}
364-
if ( this.size.width !== this.prevSize.width ) {
365-
props.width = this.size.width + "px";
366-
}
367-
if ( this.size.height !== this.prevSize.height ) {
368-
props.height = this.size.height + "px";
369-
}
370-
el.css( props );
350+
props = this._applyChanges();
371351

372352
if ( !this._helper && this._proportionallyResizeElements.length ) {
373353
this._proportionallyResize();
374354
}
375355

376356
if ( !$.isEmptyObject( props ) ) {
357+
this._updatePrevProperties();
377358
this._trigger( "resize", event, this.ui() );
359+
this._applyChanges();
378360
}
379361

380362
return false;
@@ -423,6 +405,38 @@ $.widget("ui.resizable", $.ui.mouse, {
423405

424406
},
425407

408+
_updatePrevProperties: function() {
409+
this.prevPosition = {
410+
top: this.position.top,
411+
left: this.position.left
412+
};
413+
this.prevSize = {
414+
width: this.size.width,
415+
height: this.size.height
416+
};
417+
},
418+
419+
_applyChanges: function() {
420+
var props = {};
421+
422+
if ( this.position.top !== this.prevPosition.top ) {
423+
props.top = this.position.top + "px";
424+
}
425+
if ( this.position.left !== this.prevPosition.left ) {
426+
props.left = this.position.left + "px";
427+
}
428+
if ( this.size.width !== this.prevSize.width ) {
429+
props.width = this.size.width + "px";
430+
}
431+
if ( this.size.height !== this.prevSize.height ) {
432+
props.height = this.size.height + "px";
433+
}
434+
435+
this.helper.css( props );
436+
437+
return props;
438+
},
439+
426440
_updateVirtualBoundaries: function(forceAspectRatio) {
427441
var pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b,
428442
o = this.options;

0 commit comments

Comments
 (0)