From 43024f0e81b0e4d623b54af60d09ce0e4431dbca Mon Sep 17 00:00:00 2001 From: Joshua Muheim Date: Wed, 11 Jan 2017 20:51:47 +0100 Subject: [PATCH 1/2] Add a11yfy --- app/assets/javascripts/a11yify.js | 465 +++++++++++++++++++ app/assets/javascripts/application.js.coffee | 1 + 2 files changed, 466 insertions(+) create mode 100644 app/assets/javascripts/a11yify.js diff --git a/app/assets/javascripts/a11yify.js b/app/assets/javascripts/a11yify.js new file mode 100644 index 00000000..e21b0d01 --- /dev/null +++ b/app/assets/javascripts/a11yify.js @@ -0,0 +1,465 @@ +###* +# +# jQuery module for accessibility +# +# The MIT License (MIT) +# +# Copyright (c) 2013, 2014 Dylan Barrell +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +### + +do (jQuery) -> + $politeAnnouncer = jQuery('#jquery-a11yfy-politeannouncer') + $assertiveAnnouncer = jQuery('#jquery-a11yfy-assertiveannouncer') + methods = + showAndFocus: (focus) -> + $focus = if focus then jQuery(focus) else focus + @each (index, value) -> + $this = jQuery(value) + $this.show() + if $focus and $focus.length + if platform == 'iOS' + jQuery('body').focus() + setTimeout (-> + $focus.focus() + return + ), 1000 + else + $focus.focus() + return + focus: -> + @each (index, value) -> + $this = jQuery(value) + if platform == 'iOS' + jQuery('body').focus() + setTimeout (-> + $this.focus() + return + ), 1000 + else + $this.focus() + return + validate: (options) -> + opts = jQuery.extend({}, jQuery.fn.a11yfy.defaults.validate, options) + @each (index, value) -> + $this = jQuery(value) + vOptions = jQuery.extend({}, opts.validatorOptions, + invalidHandler: invalidHandler + errorPlacement: errorPlacement + showErrors: showErrors) + + errorPlacement = -> + # do nothing - overrides default behavior + return + + showErrors = -> + # do nothing - overrides default behavior + return + + invalidHandler = (event, validator) -> + `var $this` + id = undefined + invalidIds = [] + $this = jQuery(this) + $errorSummary = $this.find('.a11yfy-error-summary') + $errorSummaryList = jQuery('