r2473 - Core: Added asynchronous focus. Fixed #3559 - :focusable, :tabbable, setFocus().
Author: scott.gonzalez
Date: Sat Apr 18 06:04:07 2009
New Revision: 2473
Modified:
trunk/tests/unit/core/core.js
trunk/ui/ui.core.js
Log:
Core: Added asynchronous focus. Fixed #3559 - :focusable, :tabbable,
setFocus().
Modified: trunk/tests/unit/core/core.js
==============================================================================
--- trunk/tests/unit/core/core.js (original)
+++ trunk/tests/unit/core/core.js Sat Apr 18 06:04:07 2009
@@ -25,4 +25,27 @@
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);
Modified: trunk/ui/ui.core.js
==============================================================================
--- trunk/ui/ui.core.js (original)
+++ trunk/ui/ui.core.js Sat Apr 18 06:04:07 2009
@@ -135,6 +135,19 @@
//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).