]> source.dussan.org Git - jquery-ui.git/commitdiff
Core: Added asynchronous focus. Fixed #3559 - :focusable, :tabbable, setFocus().
authorScott González <scott.gonzalez@gmail.com>
Sat, 18 Apr 2009 13:04:07 +0000 (13:04 +0000)
committerScott González <scott.gonzalez@gmail.com>
Sat, 18 Apr 2009 13:04:07 +0000 (13:04 +0000)
tests/unit/core/core.js
ui/ui.core.js

index 53f392370759596f06698f5512137046a75e2c66..96a197aa548cee594290a60aecf6621f77cc729b 100644 (file)
@@ -25,4 +25,27 @@ test("attr - aria", function() {
        equals(el.attr('aria-expanded'), 'false', 'aria expanded is false');
 });
 
+test('focus', function() {
+       expect(3);
+       
+       var el = $('#inputTabindex0'),
+               // used to remove focus from the main element
+               other = $('#inputTabindex10');
+       
+       // test original functionality
+       el.focus(function() {
+               ok(true, 'event triggered');
+       });
+       el.focus();
+       other.focus();
+       
+       // trigger event handler + callback
+       stop();
+       el.focus(500, function() {
+               start();
+               ok(true, 'callback triggered');
+       });
+       other.focus();
+});
+
 })(jQuery);
index 27b12681d95b385c4c1b7638ac99807988f6c50f..4068f96308a80b2cd92816c7cd3143573359cba6 100644 (file)
@@ -135,6 +135,19 @@ if (isFF2) {
 
 //jQuery plugins
 $.fn.extend({
+       _focus: $.fn.focus,
+       focus: function(delay, fn) {
+               return typeof delay === 'number'
+                       ? this.each(function() {
+                               var elem = this;
+                               setTimeout(function() {
+                                       $(elem).focus();
+                                       (fn && fn.call(elem));
+                               }, delay);
+                       })
+                       : this._focus.apply(this, arguments);
+       },
+       
        remove: function() {
                // Safari has a native remove event which actually removes DOM elements,
                // so we have to use triggerHandler instead of trigger (#3037).