Skip to content

Commit

Permalink
Updated the skip link focus bug fix code.
Browse files Browse the repository at this point in the history
  • Loading branch information
kimcoleman committed May 7, 2018
1 parent 13df61c commit 7aba35a
Showing 1 changed file with 93 additions and 91 deletions.
184 changes: 93 additions & 91 deletions js/memberlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,110 +4,112 @@
jQuery( document ).ready(
function() {

// scroll to target links in page
jQuery( 'a[href*="#"]:not(.memberlite_tabs a)' ).on(
'click', function(event) {

var target = jQuery( jQuery( this ).attr( 'href' ) );

if ( target.length ) {
event.preventDefault();
jQuery( 'html, body' ).animate(
{
scrollTop: target.offset().top
}, 800
);
}
// scroll to target links in page
jQuery( 'a[href*="#"]:not(.memberlite_tabs a)' ).on(
'click', function(event) {

var target = jQuery( jQuery( this ).attr( 'href' ) );

if ( target.length ) {
event.preventDefault();
jQuery( 'html, body' ).animate(
{
scrollTop: target.offset().top
}, 800
);
}
);
}
);

// switch tab content when clicked
jQuery( '.memberlite_tabbable .memberlite_tabs li a' ).click(
function(e) {

// don't want to jump to #
e.preventDefault();

// which tab was clicked
var tab, tabarea;
tab = jQuery( this ).attr( 'href' ).replace( /#/, '' );
tabarea = jQuery( this ).closest( '.memberlite_tabbable' );

// hide all tab panes
tabarea.find( '.memberlite_tab_pane' ).hide();
tabarea.find( '.memberlite_tab_pane' ).removeClass( 'memberlite_active' );

// switch tab content when clicked
jQuery( '.memberlite_tabbable .memberlite_tabs li a' ).click(
function(e) {
// show the active one
jQuery( '#' + tab ).show();
jQuery( '#' + tab ).addClass( 'memberlite_active' );

// don't want to jump to #
e.preventDefault();
// unstyle tabs
tabarea.find( '.memberlite_tabs li' ).removeClass( 'memberlite_active' );

// which tab was clicked
var tab, tabarea;
tab = jQuery( this ).attr( 'href' ).replace( /#/, '' );
tabarea = jQuery( this ).closest( '.memberlite_tabbable' );
// highlight the active one
jQuery( this ).closest( 'li' ).addClass( 'memberlite_active' );

// hide all tab panes
tabarea.find( '.memberlite_tab_pane' ).hide();
tabarea.find( '.memberlite_tab_pane' ).removeClass( 'memberlite_active' );
}
);

// show the active one
jQuery( '#' + tab ).show();
jQuery( '#' + tab ).addClass( 'memberlite_active' );
// check if we should switch tab content on page loads
jQuery( 'a[href="' + window.location.hash + '"]' ).click();

// unstyle tabs
tabarea.find( '.memberlite_tabs li' ).removeClass( 'memberlite_active' );
// mobile navigation
var mobilenav_trigger = jQuery( 'button.menu-toggle' );
jQuery( '#mobile-navigation' ).after( jQuery( '<div id="mobile-navigation-height-col"></div>' ) );
mobilenav_trigger.click(
function() {

// highlight the active one
jQuery( this ).closest( 'li' ).addClass( 'memberlite_active' );
jQuery( '#mobile-navigation' ).toggleClass( 'toggled' );

if (jQuery( '#mobile-navigation' ).hasClass( 'toggled' )) {
jQuery( '#mobile-navigation' ).animate(
{
left: '0px'
}
);
jQuery( '#mobile-navigation-height-col' ).animate(
{
left: '0px'
}
);
} else {
jQuery( '#mobile-navigation' ).animate(
{
left: '-100%'
}
);
jQuery( '#mobile-navigation-height-col' ).animate(
{
left: '-100%'
}
);
}
);

// check if we should switch tab content on page loads
jQuery( 'a[href="' + window.location.hash + '"]' ).click();

// mobile navigation
var mobilenav_trigger = jQuery( 'button.menu-toggle' );
jQuery( '#mobile-navigation' ).after( jQuery( '<div id="mobile-navigation-height-col"></div>' ) );
mobilenav_trigger.click(
function() {

jQuery( '#mobile-navigation' ).toggleClass( 'toggled' );

if (jQuery( '#mobile-navigation' ).hasClass( 'toggled' )) {
jQuery( '#mobile-navigation' ).animate(
{
left: '0px'
}
);
jQuery( '#mobile-navigation-height-col' ).animate(
{
left: '0px'
}
);
} else {
jQuery( '#mobile-navigation' ).animate(
{
left: '-100%'
}
);
jQuery( '#mobile-navigation-height-col' ).animate(
{
left: '-100%'
}
);
}
}
);

// skip link focus fix
// borrowed from _s theme: https://git.io/vWdr2
var isIe = /(trident|msie)/i.test( navigator.userAgent );

if ( isIe && document.getElementById && window.addEventListener ) {
window.addEventListener( 'hashchange', function() {
var id = location.hash.substring( 1 ),
element;

if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) {
return;
}
);

// skip link focus fix
// borrowed from _s theme: https://git.io/vWdr2
var is_webkit = navigator.userAgent.toLowerCase().indexOf( 'webkit' ) > -1,
is_opera = navigator.userAgent.toLowerCase().indexOf( 'opera' ) > -1,
is_ie = navigator.userAgent.toLowerCase().indexOf( 'msie' ) > -1;

if ( ( is_webkit || is_opera || is_ie ) && document.getElementById && window.addEventListener ) {
window.addEventListener(
'hashchange', function() {
var element = document.getElementById( location.hash.substring( 1 ) );

if ( element ) {
if ( ! / ^ ( ?: a | select | input | button | textarea)$ / i.test( element.tagName ) ) {
element.tabIndex = -1;
}

element.focus();
element = document.getElementById( id );

if ( element ) {
if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) {
element.tabIndex = -1;
}
}, false
);
}

element.focus();
}
}, false );
}
}
);

0 comments on commit 7aba35a

Please sign in to comment.