Skip to content

Commit

Permalink
Core: Added asynchronous focus. Fixed #3559 - :focusable, :tabbable, …
Browse files Browse the repository at this point in the history
…setFocus().
  • Loading branch information
scottgonzalez committed Apr 18, 2009
1 parent 1578835 commit cedf663
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/unit/core/core.js
Expand Up @@ -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);
13 changes: 13 additions & 0 deletions ui/ui.core.js
Expand Up @@ -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).
Expand Down

0 comments on commit cedf663

Please sign in to comment.