Skip to content

Commit

Permalink
Resizable: Trigger resize event only when element is resized. Fixed #…
Browse files Browse the repository at this point in the history
…5545

- Callbacks ignore the grid.
  • Loading branch information
eromba committed Nov 8, 2012
1 parent 1526860 commit 09706c2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 5 deletions.
79 changes: 76 additions & 3 deletions tests/unit/resizable/resizable_events.js
Expand Up @@ -5,8 +5,81 @@

module("resizable: events");

// this is here to make JSHint pass "unused", and we don't want to
// remove the parameter for when we finally implement
$.noop();
test("start", function() {

expect(1);

var count = 0,
handle = '.ui-resizable-se';
el = $("#resizable1").resizable({
handles: 'all',
start: function(event, ui) {
count++;
}
});

TestHelpers.resizable.drag(handle, 50, 50);

equal(count, 1, "start callback should happen exactly once");

});

test("resize", function() {

expect(1);

var count = 0,
handle = '.ui-resizable-e';
el = $("#resizable1").resizable({
handles: 'all',
resize: function(event, ui) {
count++;
}
});

TestHelpers.resizable.drag(handle, 50, 50);

equal(count, 2, "resize callback should happen exactly once per size adjustment");

});

test("resize (grid)", function() {

expect(1);

var count = 0,
handle = '.ui-resizable-se';
el = $("#resizable1").resizable({
handles: 'all',
grid: 50,
resize: function(event, ui) {
count++;
},
});

TestHelpers.resizable.drag(handle, 50, 50);

equal(count, 1, "resize callback should happen exactly once per grid-aligned size adjustment");

});

test("stop", function() {

expect(1);

var count = 0,
handle = '.ui-resizable-e';
el = $("#resizable1").resizable({
handles: 'all',
stop: function(event, ui) {
count++;
}
});

TestHelpers.resizable.drag(handle, 50, 50);

equal(count, 1, "stop callback should happen exactly once");

});

})(jQuery);
6 changes: 4 additions & 2 deletions ui/jquery.ui.resizable.js
Expand Up @@ -327,8 +327,10 @@ $.widget("ui.resizable", $.ui.mouse, {
if (!this._helper && this._proportionallyResizeElements.length)
this._proportionallyResize();

// calling the user callback at the end
this._trigger('resize', event, this.ui());
// Call the user callback if the element was resized
if ( ! $.isEmptyObject(props) ) {
this._trigger('resize', event, this.ui());
}

return false;
},
Expand Down

0 comments on commit 09706c2

Please sign in to comment.