aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/unit/core/core.js23
-rw-r--r--ui/ui.core.js13
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/unit/core/core.js b/tests/unit/core/core.js
index 53f392370..96a197aa5 100644
--- a/tests/unit/core/core.js
+++ b/tests/unit/core/core.js
@@ -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);
diff --git a/ui/ui.core.js b/ui/ui.core.js
index 27b12681d..4068f9630 100644
--- a/ui/ui.core.js
+++ b/ui/ui.core.js
@@ -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).