Skip to content
Permalink
Browse files

Widget: Add a _delay method. Will be used in various places to replac…

…e setTimeout with custom binding (mostly getting rid of var self/that)
  • Loading branch information...
jzaefferer committed Sep 12, 2011
1 parent d12180d commit 2a6ca3fb394f2caee6ad92c4dfc76ac66553cd46
Showing with 33 additions and 0 deletions.
  1. +24 −0 tests/unit/widget/widget_core.js
  2. +9 −0 ui/jquery.ui.widget.js
@@ -1040,4 +1040,28 @@ test( "redefine", function() {
equal( $.ui.testWidget.foo, "bar", "static properties remain" );
});

asyncTest( "_delay", function() {
expect( 4 );
var order = 0,
that;
$.widget( "ui.testWidget", {
defaultElement: null,
_create: function() {
that = this;
this._delay(function() {
strictEqual( this, that );
equal( order, 1 );
start();
}, 500);
this._delay("callback");
},
callback: function() {
strictEqual( this, that );
equal( order, 0 );
order += 1;
}
});
$( "#widget" ).testWidget();
});

}( jQuery ) );
@@ -333,6 +333,15 @@ $.Widget.prototype = {
});
},

_delay: function( handler, delay ) {
function handlerProxy() {
return ( typeof handler === "string" ? instance[ handler ] : handler )
.apply( instance, arguments );
}
var instance = this;
setTimeout( handlerProxy, delay || 0 );
},

_hoverable: function( element ) {
this.hoverable = this.hoverable.add( element );
this._bind( element, {

0 comments on commit 2a6ca3f

Please sign in to comment.
You can’t perform that action at this time.