mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Widget: Add a _delay method. Will be used in various places to replace setTimeout with custom binding (mostly getting rid of var self/that)
This commit is contained in:
parent
d12180d1a5
commit
2a6ca3fb39
@ -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 ) );
|
||||
|
9
ui/jquery.ui.widget.js
vendored
9
ui/jquery.ui.widget.js
vendored
@ -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, {
|
||||
|
Loading…
Reference in New Issue
Block a user