From f7ca6375e4fce4921488c5d2bf497b83452d32a5 Mon Sep 17 00:00:00 2001 From: Nick Freear Date: Thu, 8 Mar 2018 14:20:08 +0000 Subject: [PATCH] Bug #8, Add `accessibility_fixes()` Javascript function [iet:10308781] * Plus, minor re-factor Javascript --- .pa11yci.conf.js | 11 +++++++---- .travis.yml | 2 +- composer.json | 4 +++- js/index.js | 15 ++++++--------- js/src/ouop-utils.js | 35 +++++++++++++++++++++++++++++++++++ js/src/when-call.js | 8 +++++--- package.json | 2 +- style/login.css | 3 +++ 8 files changed, 61 insertions(+), 19 deletions(-) diff --git a/.pa11yci.conf.js b/.pa11yci.conf.js index 5cfcbe3..297c718 100644 --- a/.pa11yci.conf.js +++ b/.pa11yci.conf.js @@ -15,10 +15,12 @@ var config = { defaults: { screenCapture: './_pa11y-screen-capture.png', - standard: 'WCAG2AA', + standard: 'WCAG2AA', // Or, 'WCAG2AAA' + hideElements: '.coursesearchbox', // 'Fieldset does not contain a legend element.' GitHub:squizlabs/HTML_CodeSniffer--Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_3/1_3_1.js#L644 ignore: [ 'notice' ], - timeout: 5000, - wait: 1500 + timeout: 8000, + wait: 1500, // 2000, + 'X-verifyPage': null }, urls: [ '${TEST_SRV}/course/?_ua=pa11y', @@ -29,7 +31,8 @@ var config = { function myPa11yCiConfiguration (urls, defaults) { - console.error('Env:', process.env.TEST_SRV); + console.error('Standard:', defaults.standard); + // console.error('Env:', process.env.TEST_SRV); for (var idx = 0; idx < urls.length; idx++) { urls[ idx ] = urls[ idx ].replace('${TEST_SRV}', process.env.TEST_SRV); // substitute(urls[ idx ]); diff --git a/.travis.yml b/.travis.yml index d22f16d..bad6b43 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,10 +24,10 @@ script: - composer build - composer test - composer ci-test + - npm run pa11y-ci - composer validate after_script: - ls -al - - npm run pa11y-ci # End. diff --git a/composer.json b/composer.json index 3b07b52..3ab283e 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "iet-ou/moodle-auth-ouopenid", - "description": "This plugin is a wrapper around the OpenID authentication plugin for Moodle. © The Open University.", + "description": "This plugin is a wrapper around the OpenID authentication plugin for Moodle. © The Open University (IET)", "homepage": "https://github.com/IET-OU", "type": "moodle-auth", "license": "proprietary", @@ -10,6 +10,7 @@ }, "authors": [ { "name": "Nick Freear" } ], "autoload": { + "classmap": [ "classes/local/" ], "psr-4": { "IET_OU\\Moodle\\Auth\\Ouopenid\\Db\\": "db/" } @@ -85,6 +86,7 @@ "composer cn", "# npm run semi", "npm run eslint", + "# npm run pa11y-ci", "php -r 'simplexml_load_file(\"db/install.xml\");' && echo install.xml OK!" ], "mcs": "phpcs --standard=./moodle-core.xml --ignore=vendor --ignore=.git --extensions=php .", diff --git a/js/index.js b/js/index.js index 86928d4..ace5f63 100644 --- a/js/index.js +++ b/js/index.js @@ -14,24 +14,20 @@ var userJsonUrl = '/auth/ouopenid/user/ajax.php?r=' + util.rand(); require('./src/when-call')( function () { console.debug('>> when'); - return window.jQuery; + return util.set_jQuery(); }, - function ($) { - var W = window; - var L = W.location; - + function ($, W) { console.debug('>> call'); - if (L.pathname.match(/^\/admin\//)) { + if (util.is_admin_page()) { return console.warn('ouopenid: admin page, exiting.'); } var $body = $('body'); - var is_enrollment_page = $('#page-local-tesla-views-enrollment').length; - $body.addClass(L.href.match(/debug=1/) ? 'debug-param' : ''); + $body.addClass(util.is_debug_param() ? 'debug-param' : ''); - userJsonUrl += ( is_enrollment_page ? '&longtexts=true' : '' ); + userJsonUrl += ( util.is_tesla_enrol_page() ? '&longtexts=true' : '' ); console.warn('ouopenid $:', $.fn.jquery, BUILD_TIME, W.M.cfg); // W.Y.version @@ -41,6 +37,7 @@ require('./src/when-call')( util.set_strings(data); util.set_course_name($, data); util.site_message($, data); + util.accessibility_fixes(); data.util = util; data.$ = $; diff --git a/js/src/ouop-utils.js b/js/src/ouop-utils.js index 4098130..8309d25 100644 --- a/js/src/ouop-utils.js +++ b/js/src/ouop-utils.js @@ -3,8 +3,28 @@ // Javascript translation/localisation [i18n]. var trans = {}; +var L = window.location; +var $; + module.exports = { + set_jQuery: function () { + $ = window.jQuery; + return $; + }, + + is_debug_param: function () { + return L.href.match(/debug=1/); + }, + + is_admin_page: function () { + return L.pathname.match(/^\/admin\//); + }, + + is_tesla_enrol_page: function () { + return $('#page-local-tesla-views-enrollment').length; + }, + rand: function () { var min = 11; var max = 9999; @@ -45,6 +65,21 @@ module.exports = { } }, + accessibility_fixes: function () { + var a11y_fixes = { + 'fieldset.coursesearchbox': { + title: 'Search courses', + 'aria-label': 'Search' + } + }; + + $.each(a11y_fixes, function (sel, attrs) { + $(sel).attr(attrs); + }); + + console.warn('A11y fixes:', a11y_fixes); + }, + replace: replace_object, less_test: ouop_less_test }; diff --git a/js/src/when-call.js b/js/src/when-call.js index 2236e7e..b9b9b8b 100644 --- a/js/src/when-call.js +++ b/js/src/when-call.js @@ -3,11 +3,13 @@ module.exports = function (whenTrueFN, callbackFN, interval) { 'use strict'; - var intId = window.setInterval(function () { + var WIN = window; + + var intId = WIN.setInterval(function () { var result = whenTrueFN(); if (result) { - window.clearInterval(intId); - callbackFN(result); + WIN.clearInterval(intId); + callbackFN(result, WIN); } }, interval || 300); // Milliseconds. }; diff --git a/package.json b/package.json index 2795864..4213884 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "replace": "^0.3.0", "semistandard": "^11.0.0", "uglify-js": "^3.3.12", - "uncomment-cli": "https://github.com/nfreear/uncomment-cli.git#0.9.0" + "uncomment-cli": "git+https://github.com/nfreear/uncomment-cli.git#0.9.0" }, "x-deps": { "envify": "^4.1.0", diff --git a/style/login.css b/style/login.css index 5893af3..d4fc494 100644 --- a/style/login.css +++ b/style/login.css @@ -14,6 +14,9 @@ body { li { margin-top: 0.6em; } +a { + color: #0080a7; +} abbr { border-bottom: 1px dotted #aaa; cursor: help;