Giter Site home page Giter Site logo

accessibility's Introduction

ACCESSIBILITY

Add accessibility toolbar to your website with one line of code!

Alt text

USAGE:

npm install accessibility

include script: <script type="text/javascript" src="node_modules/accessibility/dist/main.bundle.js"></script>

or import: import { Accessibility } from 'accessibility';

initialize component: window.addEventListener('load', function() { new Accessibility(); }, false);

Full Documentation and demo

We are proud to announce that Joomla! are now using this repo as there built-in accessibility tool.

DESCRIPTION:

Features:

  • increase text size
  • decrease text size
  • increase line height
  • decrease line height
  • invert colors
  • gray hues
  • underline links
  • big cursor
  • reading guide
  • text to speech with 3 reading velocities
  • speech to text
  • suppress animations

Does not depend any other directory (jQuery is not required). Easy to use!

LIMITATIONS & KNOWN ISSUES:

  • Works with html5 browsers only (no IE8 and below)
  • Text to speech & speech to text works in supported browsers and languages only

MULTI LANGUAGE EXAMPLE:

var labels = {
    resetTitle: 'reset (in my language)',
    closeTitle: 'close (in my language)',
    menuTitle: 'title (in my language)',
    increaseText: 'increase text size (in my language)',
    decreaseText: 'decrease text size (in my language)',
    increaseTextSpacing: 'increase text spacing (in my language)',
    decreaseTextSpacing: 'decrease text spacing (in my language)',
    increaseLineHeight: 'increase line height (in my language)',
    decreaseLineHeight: 'decrease line height (in my language)',
    invertColors: 'invert colors (in my language)',
    grayHues: 'gray hues (in my language)',
    underlineLinks: 'underline links (in my language)',
    bigCursor: 'big cursor (in my language)',
    readingGuide: 'reading guide (in my language)',
    textToSpeech: 'text to speech (in my language)',
    speechToText: 'speech to text (in my language)',
    disableAnimations: 'disable animations (in my language)',
    hotkeyPrefix: 'Hotkey: (in my language)',
};
var options = { labels: labels };
options.textToSpeechLang = 'en-US'; // or any other language
options.speechToTextLang = 'en-US'; // or any other language
new Accessibility(options);

DISABLE FEATURES EXAMPLE:

options.modules = {
    decreaseText: [true/false],
    increaseText: [true/false],
    invertColors: [true/false],
    increaseTextSpacing: [true/false],
    decreaseTextSpacing: [true/false],
    increaseLineHeight: [true/false],
    decreaseLineHeight: [true/false],
    grayHues: [true/false],
    underlineLinks: [true/false],
    bigCursor: [true/false],
    readingGuide: [true/false],
    textToSpeech: [true/false],
    speechToText: [true/false],
    disableAnimations: [true/false]
};

When the default is true

TEXT SIZE MANIPULATION APPROACHES:

If text increase / decrease isn't working for your size your probably not using responsive font size units (such as em, rem etc.).
In that case you can initialize the accessibility tool like this:

new Accessibility({textPixelMode: true})

ANIMATIONS:

Cancel all buttons animations:

new Accessibility({animations: {buttons: false}})

POSITIONING:

You can position the accessibility icon in any place on the screen. The default position is bottom right:

body {
    --_access-icon-top: 50px;
    --_access-icon-left: 50px;
    --_access-icon-right: unset;
    --_access-icon-bottom: unset;
}

ICON IMAGE:

You can change the default icon as described here

PERSISTENT SESSION:

From version 3.0.1 the session will be persistent even after the user will refresh the page. To disable this feature use:

const options = {
    session: {
        persistent: false
    }
};
new Accessibility(options);

DIRECT ACCESS TO THE API:

You can toggle the menu buttons directly via the exposed API:

var instance = new Accessibility();

instance.menuInterface.increaseText();

instance.menuInterface.decreaseText();

instance.menuInterface.increaseTextSpacing();

instance.menuInterface.decreaseTextSpacing();

instance.menuInterface.invertColors();

instance.menuInterface.grayHues();

instance.menuInterface.underlineLinks();

instance.menuInterface.bigCursor();

instance.menuInterface.readingGuide();

instance.menuInterface.textToSpeech();

instance.menuInterface.speechToText();

instance.menuInterface.disableAnimations();

You can also override the functionality like this:

instance.menuInterface.increaseText = function() {
    // My own way to increase text size . . .
}

ADD CUSTOM IFRAME:

You can add buttons that will open a model with custom iframes (for accessibility terms for example) like so:

const options = {
    iframeModals: [{
        iframeUrl: 'https://github.com/ranbuch/accessibility',
        buttonText: 'terms',
        icon: 'favorite',
        emoji: '❤️'
    }
};
new Accessibility(options);

In case you will not provide the "icon" and the "emoji" we will use this setup:

icon: 'policy', emoji: '⚖️'

You can find icons here

ADD CUSTOM FUNCTIONS:

You can add buttons that will invoke custom functions like so:

const options = {
    customFunctions: [{
        method: (cf, state) => {
            console.log('The provided customFunctions object:', cf);
            console.log('Toggle state:', state);
        },
        buttonText: 'my foo',
        id: 1,
        toggle: true,
        icon: 'psychology_alt',
        emoji: '❓'
    }
};
new Accessibility(options);

In case you will not provide the "icon" and the "emoji" we will use this setup:

icon: 'psychology_alt', emoji: '❓'

You can find icons here

You have to provide the "id" parameter. This would also be your way to identify the button in case you are using more then on function while using the same custom function.

You have to provide the "toggle" parameter. This will determine whether the button will toggle his state active state (on and off) or not.

CUSTOMIZE STYLING:

You can use CSS variables to change the styling of the menu. Here is an example of how you can change the exposed variables in order to change the theme to dark mode:

:root {
    --_access-menu-background-color: #000;
    --_access-menu-item-button-background: #222;
    --_access-menu-item-color: rgba(255,255,255,.6);
    --_access-menu-header-color: rgba(255,255,255,.87);
    --_access-menu-item-button-active-color: #000;
    --_access-menu-item-button-active-background-color: #fff;
    --_access-menu-div-active-background-color: #fff;
    --_access-menu-item-button-hover-color: rgba(255,255,255,.8);
    --_access-menu-item-button-hover-background-color: #121212;
    --_access-menu-item-icon-color: rgba(255,255,255,.6);
    --_access-menu-item-hover-icon-color: rgba(255,255,255,.8);
    --_access-menu-item-active-icon-color: #000;
}

Alternatively, you can suppress the default CSS injection altogether (not recommended):

new Accessibility({suppressCssInjection: true});

You can also replace the icons by replacing the content attribute with the CSS variables currently being used.

You can suppress the default HTML injection altogether:

const instance = new Accessibility({suppressDomInjection: true});

You will need to provide your own DOM and call menuInterface functions.

You might need to replace the font-face-src:

const options = {
    icon: {
        fontFaceSrc: ['https://fonts.bunny.net/icon?family=Material+Icons']
    }
};
new Accessibility(options);

Another example with font-awesome icons:

const options = {
    icon: {
        fontFaceSrc: ['https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/v4-font-face.min.css'],
        fontFamily: '"FontAwesome"',
        img: '[optional - URL for an image that will replace the menu icon]',
        closeIcon: '[optional - replacement text for the close menu icon]',
        resetIcon: '[optional - replacement text for the reset all icon]',
        closeIconElem: {
            type: 'i',
            attrs: {
                'class': 'fa fa-window-close',
                'aria-hidden': 'true'
            }
        },
        imgElem: {
            type: 'i',
            attrs: {
                'class': 'fa fa-universal-access',
                'aria-hidden': 'true'
            }
        },
        resetIconElem: {
            type: 'i',
            attrs: {
                'class': 'fa fa-refresh',
                'aria-hidden': 'true'
            }
        }
    }
};
new Accessibility(options);
:root {
    --_access-menu-item-icon-increase-text: "\f062";
    --_access-menu-item-icon-decrease-text: "\f063";
}

Obviously you will need to add the missing variables for the rest of the fonts.

CHANGE MODULES ORDER:

You can determine the order of the modules:

new Accessibility({
    modulesOrder: [
        {
            type: AccessibilityModulesType.textToSpeech,
            order: 0
        }
    ]
});

LICENSE:

MIT License

accessibility's People

Contributors

brianteeman avatar dependabot[bot] avatar drmenzelit avatar fedyukrimon avatar hexa-3d avatar infograf768 avatar kennedyrose avatar omarmfs98 avatar ranbuch avatar sefex avatar szpluta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

accessibility's Issues

Some hotkeys still dont work

Verified on your demo site

Module or Function Hotkey Help Text Hotkey
Toggle Menu CTRL + ALT + A none
Gray Hues CTRL + ALT + G ✔️ ✔️
Underline Links CTRL + ALT + U ✔️
Big Cursor CTRL + ALT + C ✔️ ✔️
Reading Guide CTRL + ALT + R ✔️ ✔️
Text To Speech CTRL + ALT + T none ✔️
Speech To Text CTRL + ALT + S none ✔️
Invert Colors CTRL + ALT + I ✔️

ReferenceError: regeneratorRuntime is not defined

Hi I am using this tool in my Nuxt3 project.

But when I executed npm run dev, I encountered the following problem. I guessed it was because my dependency library version was too high, but I don't know which dependency it is. . . Could you please help me to have a look?

My dependencies are as follows:
image

ReferenceError: regeneratorRuntime is not defined 12:09:24
at D:\projects\develop\demo\node_modules\accessibility\dist\main.js:768:56
at D:\projects\develop\demo\node_modules\accessibility\dist\main.js:871:6
at Object. (D:\projects\develop\demo\node_modules\accessibility\dist\main.js:1540:2)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at ModuleWrap. (node:internal/modules/esm/translators:170:29)
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
statusCode: 500,
fatal: false,
unhandled: false,
statusMessage: undefined,
__nuxt_error: true
}

headless mode

Hey,

Thank you for the library!

It would be really cool to have option to exclude button and all the elements when initing Accessibility, so we could create our own UI and just call functions. I know we can call functions but it is a bit "annoying" how default UI can not simply be ommited.

Text to speech is not working

Hi,
When clicking on text to speech option I get the following error message -
'Cannot read property 'preventDefault' of undefined
at HTMLDocument.read' (main.js:738)'
I use chrome v 89.0.4389.128.
When I click on main.js i can see that window.event is undefined.
I tried to put manually while debugging - window.event = arguments[0] and it works as expected.
I have the package documentation tab open in my browser and can see that in this page the window.event is defined and the text to speech works correctly.
Am i missing something?

Thank you,
Ran

button order

How can I control the order that the buttons are displayed in. Specifically I want to place the CUSTOM IFRAME at the bottom of the list. Currently it appears between big cursor and reading guide and it would make more sense to me at the top or bottom of the list

#27 broke everything - please revert

The change in #27 just broke the script for everyone.

With this change you now get the following error

which results in
Uncaught (in promise) DOMException: Failed to execute 'check' on 'FontFaceSet': Could not resolve '1em Material+Icons' as a font.

windows chrome

image

mac safari monterey 15.1

image

If you revert that change then it works again

windows chrome

image

mac safari monterey 15.1

image

Disabling features does not work

Hi,

I tried disabling increaseLineHeight and decreaseLineHeight as per the available documentation and it doesn't seem to work.
Also, the interface IAccessibilityModulesOptions doesn't have those properties.

I coudn't disable any of the functions.

Scenario: Anuglar 8.2.5, TypeScript 3.5.3, accessibility 4.5.7

Anyway, great tool. Really useful :)

Close/Reset buttons wont work

if i'm opening the accesability menu i cant close it untill i refresh the page and the reset button wont reset the style to the basic one.

it loads fonts / icons

hi,

it looks good, but unfortunately it loads external fonts which nowadays may cause massive problems because of GDPR.

Any plans to change this?

Usage with custom buttons.

Hi,

You're doing a great work here. :)

I'm trying to use the library with some custom buttons. Would it be possible to add an option not to start the accessibility menu by default and just expose the methods? Or perhaps I just didn't find it in the documentation?

screenreader not working with submit buttons

Hi,

There seams to be an issue with the screen reader preventing some events from being passed forward in forms
I am using a react, this isn't happen always.
Might be a state issue in components using hooks

replacing the icons

Unfortunately it is not as simple as replacing the content attribute with the CSS variables currently being used as the built-in css also manipulates the icons eg

accessibility/src/main.ts

Lines 652 to 657 in 6077514

._access-menu ul li button[data-access-action="increaseTextSpacing"]:before {
content: var(--_access-menu-item-icon-increase-text-spacing, ${!this.options.icon.useEmojis ? '"unfold_more"' : '"🔼"'});
transform: rotate(90deg) translate(-7px, 2px);
top: 14px;
left: 0;
}

ability to resize the icon

Hi,
First of all thanks for this tool.
I was wondering is there is the possibility to change the icon size?
I could not find info about this on the documentation.
If currently it is not possible, will you be able to add this possibility?
Thanks

crash text to speech on chrome 93

while using google voices , google US English , google UK English male , google UK English female it reads some then crash only on google chrome and work well on others browsers and it even work well on chrome when i change default voice to microsoft zira voice

font not increase.

i used react and design with css
why when i wrote for element a class with font-size , and then i try to increase is not change...
for example
.title{
font-size:20px;
}
and when i try to increase or decrease is not change.. but if delete the font-size is change.
how i can make it that it will change any time?

Text To Speech doesn't working

Hello,
Thank you for your tool, it's amazing.

I'm having some issues trying to initialize the text-to-speech or speech-to-text module. They don't appear in the popup generated by the icon. These options simply do not show up, even with the default configs.

I've tried inserting "textToSpeechLang" or "textToSpeech" in various places within the options, but without success so far.
I also tried to manage with the interfaces or even replicate in a new project, but without success.

I'm using Next.js v13, Node 18, with your module on the latest version.

Below is the custom component I created to be loaded in _app.tsx.
import { useEffect } from "react";
import { Accessibility } from "accessibility/dist/main";
import { IAccessibilityOptions } from "accessibility/dist/accessibility";

interface AccessibilityInitializerProps {}

const labels = { resetTitle: "Reiniciar", closeTitle: "Fechar", menuTitle: "Opções de Acessibilidade", increaseText: "Aumentar texto", decreaseText: "Diminuir texto", increaseTextSpacing: "Aumentar espaçamento de texto", decreaseTextSpacing: "Diminuir espaçamento de texto", increaseLineHeight: "Aumentar altura da linha", decreaseLineHeight: "Diminuir altura da linha", invertColors: "Inverter cores", grayHues: "Escala de cinza", underlineLinks: "Sublinhar links", bigCursor: "Cursor grande", readingGuide: "Guia de leitura", textToSpeech: "Texto para voz", speechToText: "Voz para texto", disableAnimations: "Desabilitar animações", screenReader: "Leitor de tela", };

const AccessibilityInitializer: React.FC<
AccessibilityInitializerProps
> = () => {
const options: IAccessibilityOptions = {
labels: labels,
textToSpeechLang: "en-US",
speechToTextLang: "en-US",
icon: {
circular: true,
position: {
bottom: {
size: "50",
units: "%",
},
left: {
size: "10",
units: "px",
},
},
},
};
useEffect(() => {
new Accessibility(options);
return () => {};
}, []);

return null;
};

export default AccessibilityInitializer;

Also, I've attached a screenshot of the generated popup without the text-to-speech option.
Sometimes I got this issue also which was fixed adding this module with npm install.
regeneratorRuntime is not defined

Please let me know if I could help you in somehow.
Screenshot 2023-07-18 010055

Please create tags/releases for your releases here on github

Please create a tag for the version you released and create releases for the releases you are pushing to npm. Right now it looks as if this project was dead, because the last release was a non-stable release 6 years ago. Unless you have a look at npm. I would also like to be able to see what has changed between the last 2 versions.

Can not find window

Hello, Ran Buchnik.
I used accessibility module and feeling it is very good.
But I found an issue. When I use it in React it worked perfect.
Nowadays, I built a project using Frontity.
When run project, Accessibility is caused an issue that can't find window object.
So I replaced the last code of a JS file to solve this.

node_modules/accessibility/dist/accessibility.js.

if (typeof window !== 'undefined') {
  window.Accessibility = _main["default"];
}

I hope you fix this issue.

Regards.

Nextjs runtime error

on loading with nextjs 14 I'm getting this runtime error:
⨯ node_modules\accessibility\dist\accessibility.js (124:0) @ eval
⨯ ReferenceError: window is not defined

Panel Status Language Constants do not cater for multiple plurals

The system plugin Joomla Accessibility Checker needs to be changed so that the following language constants cater for languages with multiple plural forms.

PLG_SYSTEM_JOOA11Y_PANEL_STATUS_2="1 accessibility error and %(warningCount) warnings found."
PLG_SYSTEM_JOOA11Y_PANEL_STATUS_3="%(errorCount) accessibility errors and 1 warning found."
PLG_SYSTEM_JOOA11Y_PANEL_STATUS_4="%(errorCount) accessibility errors and %(warningCount) warnings found."
PLG_SYSTEM_JOOA11Y_PANEL_STATUS_6="%(errorCount) accessibility errors found."
PLG_SYSTEM_JOOA11Y_PANEL_STATUS_8="Please review %(warningCount) warnings."
PLG_SYSTEM_JOOA11Y_PANEL_STATUS_10="%(warningCount) <span class="jooa11y-visually-hidden">warnings found."
PLG_SYSTEM_JOOA11Y_PANEL_STATUS_11="%(totalCount) <span class="jooa11y-visually-hidden">total issues found."

Hot Keys don't work

I am unable to get any hotkeys to work

Your demo site has hotkeys enabled and I have tested with chrome, firefox and edge but nothing happens.

Is it me?

Crashing React App

I'm following the instructions to use this package:

  1. Download the package on npm (I've tried a couple of different versions)
  2. Added this line to the top level of my Javascript code: window.addEventListener('load', function() { new Accessibility(); }, false);

It strangely did work for a moment but it is now crashing the website it is embedded in and I can't figure out why. Has an issue like this been discovered before? Does it resemble any prior difficulties anyone has bad with this package?

Suggestion to add 2 important features

To my point of view, the plugin is missing 2 important features in menu that regulators follow them :

  1. Area with button to redirect to Accesibilty Disclaimer URL that site owner publish.
  2. Mailto button for reporting to site owner on accesibilty issue

Font size does not work correctly for rem units, and ignores browser settings

While trying to use your scrip I found that approach that you use to manipulate the font size does not work even if the font size of the site is in a relative units (rem in my case).

If you know what is rem unit then you already may guess the reason of bug.

Instead of changing <body> font size, the script should manipulate with document font size (that is <html> element).
Please check section "Base font size and accessibility"
https://betterwebtype.com/articles/2019/06/16/5-keys-to-accessible-web-typography/

To do this without loosing users who use "old school" body{font-size:12px}, I would suggest next:

  • on init, calculate html and body font sizes, and their difference
  • then set body font size in em (calculated difference from html)
  • set html font size in percent instead of pixels, this still will allow to users to use browser settings

Let say, html has font 16px (default for most browsers) and body 14px, the script need to set body font size 0.875em. And change html font size, when user click Bigger/Smaller, in % from existing font size.

btw, the demo page also ignores user font size from browser setting.

Additionally I would suggest to remove textPixelMode: true possibility, it just killing any site performance, especially big ones.

line height

Testing the increase/decrease line height and it would appear not to work as expected.

Increase seems ok but neither descrease nor reset will get the [age backl to the previous behaviour.

I made a codepen of an official bootstrap example plus this plaugin so you can see for yourself

codepen

Extract css

Is it possible to compile the script without and then use an external stylesheet.

It will mean using two lines of code instead of one to use the script but it will make it easier to customise the css to match the site

Disabling options not working

#56
Disabling the increaseLineHeight and decreaseLineHeight options does not work. I suspect this is because the IAccessibilityModulesOptions interface lacks these parameters.

new Accessibility({
  modules: {
    increaseLineHeight: false,
    decreaseLineHeight: false
  }
})

Invert colors filter breaks fixed positioned items on firefox

When Invert Colors options is toggled filter: invert(1) is added to html tag. Works good on Chrome, but there is a werid behaviour on Firefox where all fixed positioned elements suddenly lose this property going back to initial positioning.
This can be well seen on accessibility menu itself (it jumps to very bottom of the page).

I assume it's a Firefox bug.
https://bugzilla.mozilla.org/show_bug.cgi?id=1226095

Is there a walkaround you would suggest to make it work?

Icon on ios/Safari not working

Hello! On the iPad i always get a fallback to the Emoji with a message "Material Icons font was not loaded". I also tried hosting the font on my own.. but it does not work.

The CSS gets injected in the head, but I think the javascript query about the font does not work there

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.