diff options
-rw-r--r-- | tests/unit/resizable/resizable_events.js | 21 | ||||
-rw-r--r-- | ui/resizable.js | 60 |
2 files changed, 58 insertions, 23 deletions
diff --git a/tests/unit/resizable/resizable_events.js b/tests/unit/resizable/resizable_events.js index 18e25bfdf..d3851f72e 100644 --- a/tests/unit/resizable/resizable_events.js +++ b/tests/unit/resizable/resizable_events.js @@ -146,6 +146,27 @@ test("resize (grid)", function() { }); +test( "resize, custom adjustment", function() { + expect( 4 ); + + var handle = ".ui-resizable-se", + element = $( "#resizable1" ).resizable({ + resize: function( event, ui ) { + ui.size.width = 100; + ui.size.height = 200; + ui.position.left = 300; + ui.position.top = 400; + } + }); + + TestHelpers.resizable.drag( handle, 50, 50 ); + + equal( element.width(), 100, "resize event can control width" ); + equal( element.height(), 200, "resize event can control height" ); + equal( element.position().left, 300, "resize event can control left" ); + equal( element.position().top, 400, "resize event can control top" ); +}); + test("stop", function() { expect(5); diff --git a/ui/resizable.js b/ui/resizable.js index 869cc3ebe..b2e3a6626 100644 --- a/ui/resizable.js +++ b/ui/resizable.js @@ -321,22 +321,14 @@ $.widget("ui.resizable", $.ui.mouse, { _mouseDrag: function(event) { - var data, - el = this.helper, props = {}, + var data, props, smp = this.originalMousePosition, a = this.axis, dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0, trigger = this._change[a]; - this.prevPosition = { - top: this.position.top, - left: this.position.left - }; - this.prevSize = { - width: this.size.width, - height: this.size.height - }; + this._updatePrevProperties(); if (!trigger) { return false; @@ -355,26 +347,16 @@ $.widget("ui.resizable", $.ui.mouse, { this._propagate("resize", event); - if ( this.position.top !== this.prevPosition.top ) { - props.top = this.position.top + "px"; - } - if ( this.position.left !== this.prevPosition.left ) { - props.left = this.position.left + "px"; - } - if ( this.size.width !== this.prevSize.width ) { - props.width = this.size.width + "px"; - } - if ( this.size.height !== this.prevSize.height ) { - props.height = this.size.height + "px"; - } - el.css( props ); + props = this._applyChanges(); if ( !this._helper && this._proportionallyResizeElements.length ) { this._proportionallyResize(); } if ( !$.isEmptyObject( props ) ) { + this._updatePrevProperties(); this._trigger( "resize", event, this.ui() ); + this._applyChanges(); } return false; @@ -423,6 +405,38 @@ $.widget("ui.resizable", $.ui.mouse, { }, + _updatePrevProperties: function() { + this.prevPosition = { + top: this.position.top, + left: this.position.left + }; + this.prevSize = { + width: this.size.width, + height: this.size.height + }; + }, + + _applyChanges: function() { + var props = {}; + + if ( this.position.top !== this.prevPosition.top ) { + props.top = this.position.top + "px"; + } + if ( this.position.left !== this.prevPosition.left ) { + props.left = this.position.left + "px"; + } + if ( this.size.width !== this.prevSize.width ) { + props.width = this.size.width + "px"; + } + if ( this.size.height !== this.prevSize.height ) { + props.height = this.size.height + "px"; + } + + this.helper.css( props ); + + return props; + }, + _updateVirtualBoundaries: function(forceAspectRatio) { var pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b, o = this.options; |