2 Copyright 2007 University of Toronto
4 Licensed under the GNU Public License or the MIT license.
5 You may not use this file except in compliance with one these
8 You may obtain a copy of the GPL and MIT License at
9 https://source.fluidproject.org/svn/sandbox/tabindex/trunk/LICENSE.txt
13 var normalizeTabIndexName = function () {
14 return $.browser.msie ? "tabIndex" : "tabindex";
17 var getValue = function (elements) {
18 if (!elements.hasTabIndex ()) {
22 // Get the attribute (.attr () doesn't work for tabIndex in IE) and return it as a number value.
23 var value = elements[0].getAttribute (normalizeTabIndexName ());
24 return Number (value);
27 var setValue = function (elements, toIndex) {
28 return elements.each (function (i, item) {
29 $ (item).attr (normalizeTabIndexName (), toIndex);
34 $.fn.tabIndex = function (toIndex) {
35 if (toIndex !== null && toIndex !== undefined) {
36 return setValue (this, toIndex);
38 return getValue (this);
42 $.fn.removeTabIndex = function () {
43 return this.each(function (i, item) {
44 $ (item).removeAttr (normalizeTabIndexName ());
48 $.fn.hasTabIndex = function () {
49 var attributeNode = this[0].getAttributeNode (normalizeTabIndexName ());
50 return attributeNode ? attributeNode.specified : false;