4c8ee5ac618511cb8f02debc6af29f12377420e7
[atutor.git] / mods / photo_album / fluid / component-templates / js / jquery.tabindex / jquery.tabindex.js
1 /*
2 Copyright 2007 University of Toronto
3
4 Licensed under the GNU Public License or the MIT license. 
5 You may not use this file except in compliance with one these
6 Licenses.
7
8 You may obtain a copy of the GPL and MIT License at
9 https://source.fluidproject.org/svn/sandbox/tabindex/trunk/LICENSE.txt
10 */
11 (function ($) {
12         // Private functions.
13         var normalizeTabIndexName = function () {
14             return $.browser.msie ? "tabIndex" : "tabindex";
15         }
16
17         var getValue = function (elements) {
18                 if (!elements.hasTabIndex ()) {
19                         return undefined;
20                 }
21
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);
25         };
26
27         var setValue = function (elements, toIndex) {
28                 return elements.each (function (i, item) {
29                         $ (item).attr (normalizeTabIndexName (), toIndex);
30                 });
31         };
32
33         // Public methods.
34         $.fn.tabIndex = function (toIndex) {
35                 if (toIndex !== null && toIndex !== undefined) {
36                         return setValue (this, toIndex);
37                 } else {
38                         return getValue (this);
39                 }
40         };
41
42         $.fn.removeTabIndex = function () {
43                 return this.each(function (i, item) {
44                         $ (item).removeAttr (normalizeTabIndexName ());
45                 });
46         };
47
48         $.fn.hasTabIndex = function () {
49             var attributeNode = this[0].getAttributeNode (normalizeTabIndexName ());
50         return attributeNode ? attributeNode.specified : false;
51         };
52 }) (jQuery);