diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-01-18 01:46:26 -0500 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-01-18 01:46:26 -0500 |
commit | 659db70caa2ff1e3a43e98f3895f0353ebcee154 (patch) | |
tree | f147fa26ce8db5c879f24582ac7bed93c96fa7fd /tests/unit/widget/widget_core.js | |
parent | 67b070f97a6dc4907cbb5e69b8899c0b5c716684 (diff) | |
download | jquery-ui-659db70caa2ff1e3a43e98f3895f0353ebcee154.tar.gz jquery-ui-659db70caa2ff1e3a43e98f3895f0353ebcee154.zip |
Widget: Added ._bind() for easily binding events with correct context and disabled checking. Pretty much a direct copy from the previous bind branch.
Diffstat (limited to 'tests/unit/widget/widget_core.js')
-rw-r--r-- | tests/unit/widget/widget_core.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 388e078b0..f0afaa956 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -404,6 +404,99 @@ test( ".widget() - overriden", function() { same( wrapper[0], $( "<div></div>" ).testWidget().testWidget( "widget" )[0] ); }); +test( "_bind to element (default)", function() { + expect( 12 ); + var self; + $.widget( "ui.testWidget", { + _create: function() { + self = this; + this._bind({ + keyup: this.keyup, + keydown: this.keydown + }); + }, + keyup: function( event ) { + equals( self, this ); + equals( self.element[0], event.currentTarget ); + equals( "keyup", event.type ); + }, + keydown: function( event ) { + equals( self, this ); + equals( self.element[0], event.currentTarget ); + equals( "keydown", event.type ); + } + }); + var widget = $( "<div></div>" ) + .testWidget() + .trigger( "keyup" ) + .trigger( "keydown" ); + widget + .testWidget( "disable" ) + .trigger( "keyup" ) + .trigger( "keydown" ); + widget + .testWidget( "enable" ) + .trigger( "keyup" ) + .trigger( "keydown" ); + widget + .testWidget( "destroy" ) + .trigger( "keyup" ) + .trigger( "keydown" ); +}); + +test( "_bind to descendent", function() { + expect( 12 ); + var self; + $.widget( "ui.testWidget", { + _create: function() { + self = this; + this._bind( this.element.find( "strong" ), { + keyup: this.keyup, + keydown: this.keydown + }); + }, + keyup: function( event ) { + equals( self, this ); + equals( self.element.find( "strong" )[0], event.currentTarget ); + equals( "keyup", event.type ); + }, + keydown: function(event) { + equals( self, this ); + equals( self.element.find( "strong" )[0], event.currentTarget ); + equals( "keydown", event.type ); + } + }); + // trigger events on both widget and descendent to ensure that only descendent receives them + var widget = $( "<div><p><strong>hello</strong> world</p></div>" ) + .testWidget() + .trigger( "keyup" ) + .trigger( "keydown" ); + var descendent = widget.find( "strong" ) + .trigger( "keyup" ) + .trigger( "keydown" ); + widget + .testWidget( "disable" ) + .trigger( "keyup" ) + .trigger( "keydown" ); + descendent + .trigger( "keyup" ) + .trigger( "keydown" ); + widget + .testWidget( "enable" ) + .trigger( "keyup" ) + .trigger( "keydown" ); + descendent + .trigger( "keyup" ) + .trigger( "keydown" ); + widget + .testWidget( "destroy" ) + .trigger( "keyup" ) + .trigger( "keydown" ); + descendent + .trigger( "keyup" ) + .trigger( "keydown" ); +}); + test( "._trigger() - no event, no ui", function() { expect( 7 ); var handlers = []; |