Skip to content

Instantly share code, notes, and snippets.

@dustinleer

dustinleer/sharethis.js

Last active Dec 11, 2019
Embed
What would you like to do?
Sharethis a11y Functionality jQuery
jQuery(document).ready(function($) {
setTimeout(function(){
//--------------------------
// SHARETHIS a11y
//--------------------------
// Loop through an array of data-network names
['facebook', 'twitter', 'pinterest'].forEach(function( platform ) {
// Adds a11y to sharing icons
$('.st-btn[data-network="' + platform + '"').attr({
'title' : 'social ' + platform.charAt(0).toUpperCase() + platform.slice(1) + '',
'aria-label' : 'Open ' + platform + ' sharing modal',
'tabindex' : '0',
'role' : 'content-info',
});
// Adds enter key functionality to work like a click
$('.st-btn[data-network="' + platform + '"').keypress( function( e ) {
if ( e.which && e.which == 13 ) { // 13 is character code for enter
// event.preventDefault();
$(this).click();
}
});
});
// // Checks to see if container is empty because of browser social blocking
if ($('.sharethis-inline-share-buttons').is(':empty')) {
$('.share').addClass('no-social');
$('.sharethis-inline-share-buttons').append('<div class="no-social">Your browser may be blocking social sharing.</div>');
}
}, 100);
}
@dustinleer

This comment has been minimized.

Copy link
Owner Author

@dustinleer dustinleer commented May 10, 2019

This adds tabindex to add focus on tab selection and enter key functionality so it mimics a mouse click to trigger to popup window.

@dustinleer

This comment has been minimized.

Copy link
Owner Author

@dustinleer dustinleer commented May 14, 2019

Thanks to @zachfedor for the assist on streamlining this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.