Search and Top Navigation
Ticket #3559: core.diff
File core.diff, 2.0 KB (added by trixta, November 11, 2008 09:51PM UTC)
some additions to the patch by colin: area is only focusable, if a href-attribute is available. + IE8 detection
Index: ui.core.js
===================================================================
--- ui.core.js (revision 909)
+++ ui.core.js (working copy)
@@ -1,34 +1,35 @@
(function($) {
-
+
+var normalizedTabindex = ($.browser.msie && parseInt($.browser.version, 10) < 8) ?
+ 'tabIndex' :
+ 'tabindex';
+
+function hasTabindexAttr(element) {
+ var attributeNode = element.getAttributeNode(normalizedTabindex);
+ return attributeNode ? attributeNode.specified : false;
+}
function getTabIndex(element) {
- var index = parseInt(element.getAttribute('tabIndex'), 10);
- if (isNaN(index)) {
- index = element.tabIndex;
- }
-
- return index;
+ if (!hasTabindexAttr(element)) {
+ return undefined;
+ }
+ var value = parseInt(element.getAttribute(normalizedTabindex), 10);
+ return !isNaN(value) ? value : undefined;
}
$.extend($.expr[':'], {
focusable: function(element) {
var nodeName = element.nodeName.toLowerCase(),
tabIndex = getTabIndex(element);
-
- if ($(element).is(':hidden') || $(element).parents(':hidden').length) {
- return false;
- }
-
- return (/input|select|textarea|button|object|area/.test(nodeName)
- ? !('hidden' == element.type || element.disabled)
- : 'a' == nodeName
+ return (/input|select|textarea|button|object/.test(nodeName)
+ ? !(element.disabled)
+ : 'a' == nodeName || 'area' == nodeName
? element.href || !isNaN(tabIndex)
- : !isNaN(tabIndex));
+ : !isNaN(tabIndex)) && (!$(element).parents().andSelf().filter(':hidden').length) ? true : false;
},
tabbable: function(element) {
var tabIndex = getTabIndex(element);
-
- return !isNaN(tabIndex) && tabIndex >= 0 && $(element).is(':focusable');
+ return (isNaN(tabIndex) || tabIndex >= 0) && $(element).is(':focusable');
}
});
@@ -36,9 +37,9 @@
var element = this[0];
if (element) {
- if (!isNaN(getTabIndex(element))) {
- $(element).attr('tabIndex', -1);
- }
+ //if (!isNaN(getTabIndex(element))) {
+ $(element).attr('tabIndex', -1);
+ //}
setTimeout(function() {
element.focus();
Download in other formats:
Original Format
File core.diff, 2.0 KB (added by trixta, November 11, 2008 09:51PM UTC)
some additions to the patch by colin: area is only focusable, if a href-attribute is available. + IE8 detection
Index: ui.core.js
===================================================================
--- ui.core.js (revision 909)
+++ ui.core.js (working copy)
@@ -1,34 +1,35 @@
(function($) {
-
+
+var normalizedTabindex = ($.browser.msie && parseInt($.browser.version, 10) < 8) ?
+ 'tabIndex' :
+ 'tabindex';
+
+function hasTabindexAttr(element) {
+ var attributeNode = element.getAttributeNode(normalizedTabindex);
+ return attributeNode ? attributeNode.specified : false;
+}
function getTabIndex(element) {
- var index = parseInt(element.getAttribute('tabIndex'), 10);
- if (isNaN(index)) {
- index = element.tabIndex;
- }
-
- return index;
+ if (!hasTabindexAttr(element)) {
+ return undefined;
+ }
+ var value = parseInt(element.getAttribute(normalizedTabindex), 10);
+ return !isNaN(value) ? value : undefined;
}
$.extend($.expr[':'], {
focusable: function(element) {
var nodeName = element.nodeName.toLowerCase(),
tabIndex = getTabIndex(element);
-
- if ($(element).is(':hidden') || $(element).parents(':hidden').length) {
- return false;
- }
-
- return (/input|select|textarea|button|object|area/.test(nodeName)
- ? !('hidden' == element.type || element.disabled)
- : 'a' == nodeName
+ return (/input|select|textarea|button|object/.test(nodeName)
+ ? !(element.disabled)
+ : 'a' == nodeName || 'area' == nodeName
? element.href || !isNaN(tabIndex)
- : !isNaN(tabIndex));
+ : !isNaN(tabIndex)) && (!$(element).parents().andSelf().filter(':hidden').length) ? true : false;
},
tabbable: function(element) {
var tabIndex = getTabIndex(element);
-
- return !isNaN(tabIndex) && tabIndex >= 0 && $(element).is(':focusable');
+ return (isNaN(tabIndex) || tabIndex >= 0) && $(element).is(':focusable');
}
});
@@ -36,9 +37,9 @@
var element = this[0];
if (element) {
- if (!isNaN(getTabIndex(element))) {
- $(element).attr('tabIndex', -1);
- }
+ //if (!isNaN(getTabIndex(element))) {
+ $(element).attr('tabIndex', -1);
+ //}
setTimeout(function() {
element.focus();