app/scripts/plugins/a11y.coffee

EPFL accessibility plugin

Handle accessibility optimisations

requires: jQuery or Zepto DOM library
author: Julien Ramboz
version: 1.0

AMD loader

Try loading as AMD module or fall back to default loading

((plugin) -> if typeof define is "function" and define.amd define ["jslib", "plugin"], plugin else plugin @$, AbstractPlugin ).call this, a11ylinks = ($, AbstractPlugin) -> "use strict"

Plugin

The actual plugin class

class A11yLinks extends AbstractPlugin

Event handling

Attach evenets to the plugin

bindEvents: () -> @element.on "click", () -> target = this.href.replace /.*(#.*)/, "$1" if target $target = $(target) $target.attr "tabindex", 0 $target.focus() $target.attr "tabindex", -1 $(@element.attr("href").replace(/.*(#.*)/, "$1")).on "blur", -> $(this).removeAttr("tabindex") $(document).on "keydown", (ev) -> if not $(ev.target).is ":input" $("html").addClass "is-keyboard" $(document).on "mousedown", (ev) -> $("html").removeClass "is-keyboard"

Installation

Install the plugin into the JS library

A11yLinks.install("A11yLinks", () -> $(".a11y .focusable")["#{AbstractPlugin.namespace}a11ylinks"]() )