Created
September 1, 2015 13:41
-
-
Save mfairchild365/62b6f4e0cda072b2f698 to your computer and use it in GitHub Desktop.
This is a work-around for twitter widgets adding a title attribute to the iframes they produce, which leads to a11y problems.
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 is a work-around for twitter widgets adding a title attribute to the iframes they produce, which leads to a11y problems. | |
--> | |
<!-- Include the twitter widget js on every page --> | |
<script>window.twttr = (function(d, s, id) { | |
var js, fjs = d.getElementsByTagName(s)[0], | |
t = window.twttr || {}; | |
if (d.getElementById(id)) return t; | |
js = d.createElement(s); | |
js.id = id; | |
js.src = "https://platform.twitter.com/widgets.js"; | |
fjs.parentNode.insertBefore(js, fjs); | |
t._e = []; | |
t.ready = function(f) { | |
t._e.push(f); | |
}; | |
return t; | |
}(document, "script", "twitter-wjs"));</script> | |
<!-- Include this script to add title attributes to widgets on every page, (this can be customized) --> | |
<script> | |
require(['jquery'], function($) { | |
twttr.ready( | |
function(twttr) { | |
// bind events here | |
twttr.events.bind( | |
'loaded', | |
function(event) { | |
event.widgets.forEach(function(widget) { | |
//Your logic here: | |
//Set title attributes | |
$(widget).attr('title', 'share this on twitter'); | |
}); | |
} | |
); | |
} | |
); | |
}); | |
</script> | |
<!-- Load your widget on your pages, note: You don't need the js that comes with each widget because it will already be loaded on every page --> | |
<a href="https://twitter.com/share" class="twitter-share-button" data-via="mfairchild365" data-name="tesst">Tweet</a> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment