diff options
-rw-r--r-- | tests/unit/widget/widget_core.js | 24 | ||||
-rw-r--r-- | ui/jquery.ui.widget.js | 9 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 0c4142539..0b272a0d5 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.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 ) ); diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 5b7942600..729e14cf9 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -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, { |