Giter VIP home page Giter VIP logo

accessifyhtml5.js's Introduction

accessifyhtml5.js

The polyfill for a more accessible HTML5.

Which problem is solved with this polyfill?

While most browsers work all right with the new semantic elements of HTML5, they don’t add the ARIA accessibility attributes that the specification demands. This small JavaScript adds those attributes to enhance accessibility of web sites.

How to use accessifyhtml5.js?

Just link to the accessifyhtml5.js file and call the AccessifyHTML5-Function at the bottom of your page right before the closing </body> tag:

<script src="accessifyhtml5.js"></script>
<script>AccessifyHTML5();</script>

There are some options you’re able to specify as they can be on each web page only once.

  • header: A CSS selector that selects exactly one element on the page which will get the role banner.
  • footer: A CSS selector that selects exactly one element on the page which will get the role contentinfo.
  • main: A CSS selector that selects exactly one element on the page which will get the role main.

Example:

<script src="accessifyhtml5.js"></script>
<script>
	AccessifyHTML5({
		header:"body>header", 
		footer:"body>footer",
		main: "#main"
	});
</script>

jQuery

There is a jQuery variant of the script that is a bit smaller, so if you’re using jQuery anyway, go ahead.

<script src="accessifyhtml5.jquery.js"></script>
<script>AccessifyHTML5();</script>

CDN

I’ve created a small CDN that should serve the JS file quite fast. I recommend to use the code here and copy it into your project’s JS file. Code:

<script src="//yatil-cdn.s3.amazonaws.com/accessifyhtml5.min.js"></script>
<script>AccessifyHTML5();</script>

or

<script src="//yatil-cdn.s3.amazonaws.com/accessifyhtml5.jquery.min.js"></script>
<script>AccessifyHTML5();</script>

Changelog

Version 1.0

  • Added support for specifying the main part of the web site using the main parameter (as requested by @yellowled).
  • The script won’t overwrite your specified roles.

Version 1.0 beta

  • Added non-jQuery version (Using querySelector, adds support in IE8+, FF3.5+, Opera 10+, Safari, Chrome as well as iOS, Android and Opera Mobile)
  • Removed header.site getting role banner and footer.site getting role contentinfo -> If you need to add a class, you can also add the role directly to the HTML
  • Thanks to @adickson you can just add selectors for banner and contentinfo when calling the function
  • You’ll now have to call AccessifyHTML5-function like that: @AccessifyHTML5({header:"#header", footer:"#footer"});@

Acknowledgements:

  • @adickson for a really good non-jQuery solution
  • @stevefaulkner for his work exploring html5 a11y
  • @paddya91 for object notation
  • @ginader for reporting a typo
  • @webaxe for reporting an error
  • @divya for keeping me on track for a non-jQuery solution
  • @mathias for improving my javascript

Known Issues:

  • According to @jkiss, Window-Eyes 7.11 struggles with aria-roles and HTML5, this is nothing I can solve with this script but is a screen reader issue. See: https://twitter.com/#!/jkiss/status/5488643711967232
  • Firefox adds roles by itself, so this script is not needed for those browsers. I haven’t found a way to detect if those implicit roles are set, so I can’t test that at the moment.

License:

This project is MIT licensed.

Author:

accessifyhtml5.js's People

Contributors

adickson avatar mathiasbynens avatar yatil avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.