-
-
Save reubenmoes/5df08e898f20cecb4e0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This Module adds the ability to :focus on divs that are linked to from | |
* the .skip-links section with a hash href. | |
*/ | |
app.skipLinks = (function($){ | |
'use strict'; | |
//A list of all skip-link hashes | |
var hashes = []; | |
function bindActions(){ | |
//Create array with all hash links | |
$('.skip-links a').each(function(){ | |
hashes.push(this.hash); | |
}); | |
//Listen to hashchange event | |
$(window).on('hashchange', function() { | |
var hash = window.location.hash; | |
//Check if the hash is from the .skip-links section | |
//and if an element with that ID exists | |
if ( $.inArray(hash, hashes) !== -1 && $(hash).length) { | |
$(hash) | |
.attr('tabindex', 0) | |
.focus() | |
.on('blur', function(){ | |
this.removeAttribute('tabindex'); | |
}); | |
} | |
}); | |
} | |
$(document).on('ready', bindActions); | |
return {}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment