Skip to content
Browse files

convert all tabs to spaces

  • Loading branch information...
1 parent 2ba2b70 commit 3dd5e0e089a4db2e25e7761512733e7ba5a2385e @julienw committed May 9, 2012
Showing with 119 additions and 119 deletions.
  1. +119 −119 jquery.trap.js
View
238 jquery.trap.js
@@ -23,137 +23,137 @@ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED.
*/
/*jshint boss: true, bitwise: true, curly: true, expr: true, newcap: true, noarg: true, nonew: true, latedef: true, regexdash: true */
-
- var DATA_ISTRAPPING_KEY = "trap.isTrapping";
+
+ var DATA_ISTRAPPING_KEY = "trap.isTrapping";
- function onkeypress(e) {
- if (e.keyCode === 9) {
- var goReverse = !!(e.shiftKey);
- if (processTab(this, e.target, goReverse)) {
- e.preventDefault();
- e.stopPropagation();
- }
- }
- }
-
- // will return true if we could process the tab event
- // otherwise, return false
- function processTab(container, elt, goReverse) {
- var $focussable = getFocusableElementsInContainer(container),
- curElt = elt,
- index, nextIndex, prevIndex, lastIndex;
-
- do {
-
- index = $focussable.index(curElt);
- nextIndex = index + 1;
- prevIndex = index - 1;
- lastIndex = $focussable.length - 1;
+ function onkeypress(e) {
+ if (e.keyCode === 9) {
+ var goReverse = !!(e.shiftKey);
+ if (processTab(this, e.target, goReverse)) {
+ e.preventDefault();
+ e.stopPropagation();
+ }
+ }
+ }
+
+ // will return true if we could process the tab event
+ // otherwise, return false
+ function processTab(container, elt, goReverse) {
+ var $focussable = getFocusableElementsInContainer(container),
+ curElt = elt,
+ index, nextIndex, prevIndex, lastIndex;
+
+ do {
+
+ index = $focussable.index(curElt);
+ nextIndex = index + 1;
+ prevIndex = index - 1;
+ lastIndex = $focussable.length - 1;
- switch(index) {
- case -1:
- return false; // that's strange, let the browser do its job
- case 0:
- prevIndex = lastIndex;
- break;
- case lastIndex:
- nextIndex = 0;
- break;
- }
-
- if (goReverse) {
- nextIndex = prevIndex;
- }
-
- curElt = $focussable.get(nextIndex);
+ switch(index) {
+ case -1:
+ return false; // that's strange, let the browser do its job
+ case 0:
+ prevIndex = lastIndex;
+ break;
+ case lastIndex:
+ nextIndex = 0;
+ break;
+ }
+
+ if (goReverse) {
+ nextIndex = prevIndex;
+ }
+
+ curElt = $focussable.get(nextIndex);
// IE sometimes throws when an element is not visible
try {
curElt.focus();
} catch(e) {
}
-
- } while (elt === elt.ownerDocument.activeElement);
+
+ } while (elt === elt.ownerDocument.activeElement);
- return true;
- }
-
- function filterKeepSpeciallyFocusable() {
- return this.tabIndex > 0;
- }
-
- function filterKeepNormalElements() {
- return !this.tabIndex; // true if no tabIndex or tabIndex == 0
- }
-
- function sortFocusable(a, b) {
- return (a.t - b.t) || (a.i - b.i);
- }
-
- function getFocusableElementsInContainer(container) {
- var $container = $(container);
- var result = [],
- cnt = 0;
+ return true;
+ }
+
+ function filterKeepSpeciallyFocusable() {
+ return this.tabIndex > 0;
+ }
+
+ function filterKeepNormalElements() {
+ return !this.tabIndex; // true if no tabIndex or tabIndex == 0
+ }
+
+ function sortFocusable(a, b) {
+ return (a.t - b.t) || (a.i - b.i);
+ }
+
+ function getFocusableElementsInContainer(container) {
+ var $container = $(container);
+ var result = [],
+ cnt = 0;
fixIndexSelector.enable && fixIndexSelector.enable();
-
- // leaving away command and details for now
- $container.find("a[href], link[href], [draggable=true], [contenteditable=true], :input:enabled, [tabindex=0]")
- .filter(":visible")
- .filter(filterKeepNormalElements)
- .each(function(i, val) {
- result.push({
- v: val, // value
- t: 0, // tabIndex
- i: cnt++ // index for stable sort
- });
- });
-
- $container
- .find("[tabindex]")
- .filter(":visible")
- .filter(filterKeepSpeciallyFocusable)
- .each(function(i, val) {
- result.push({
- v: val, // value
- t: val.tabIndex, // tabIndex
- i: cnt++ // index
- });
- });
+
+ // leaving away command and details for now
+ $container.find("a[href], link[href], [draggable=true], [contenteditable=true], :input:enabled, [tabindex=0]")
+ .filter(":visible")
+ .filter(filterKeepNormalElements)
+ .each(function(i, val) {
+ result.push({
+ v: val, // value
+ t: 0, // tabIndex
+ i: cnt++ // index for stable sort
+ });
+ });
+
+ $container
+ .find("[tabindex]")
+ .filter(":visible")
+ .filter(filterKeepSpeciallyFocusable)
+ .each(function(i, val) {
+ result.push({
+ v: val, // value
+ t: val.tabIndex, // tabIndex
+ i: cnt++ // index
+ });
+ });
fixIndexSelector.disable && fixIndexSelector.disable();
-
- result = $.map(result.sort(sortFocusable), // needs stable sort
- function(val) {
- return val.v;
- }
- );
-
-
- return $(result);
-
- }
-
- function trap() {
- this.keydown(onkeypress);
- this.data(DATA_ISTRAPPING_KEY, true);
- return this;
- }
-
- function untrap() {
- this.unbind('keydown', onkeypress);
- this.removeData(DATA_ISTRAPPING_KEY);
- return this;
- }
-
- function isTrapping() {
- return !!this.data(DATA_ISTRAPPING_KEY);
- }
-
- $.fn.extend({
- trap: trap,
- untrap: untrap,
- isTrapping: isTrapping
- });
+
+ result = $.map(result.sort(sortFocusable), // needs stable sort
+ function(val) {
+ return val.v;
+ }
+ );
+
+
+ return $(result);
+
+ }
+
+ function trap() {
+ this.keydown(onkeypress);
+ this.data(DATA_ISTRAPPING_KEY, true);
+ return this;
+ }
+
+ function untrap() {
+ this.unbind('keydown', onkeypress);
+ this.removeData(DATA_ISTRAPPING_KEY);
+ return this;
+ }
+
+ function isTrapping() {
+ return !!this.data(DATA_ISTRAPPING_KEY);
+ }
+
+ $.fn.extend({
+ trap: trap,
+ untrap: untrap,
+ isTrapping: isTrapping
+ });
// jQuery 1.6.x tabindex attr hooks management
// this triggers problems for tabindex attribute

0 comments on commit 3dd5e0e

Please sign in to comment.
Something went wrong with that request. Please try again.