Accessibility widget script
Required Level of JavaScript Knowledge
To configure and implement the WCAG accessibility script, basic knowledge of JavaScript is sufficient, including:
- Adding scripts to web pages.
- Creating and modifying JavaScript objects.
- Passing arguments to functions.
- Working with CSS selectors.
Advanced programming knowledge is not required – the script is designed to be easy to use for non-experts in coding.
Script Structure and Operation
Basic Script Skeleton:
Script Parameters:
'_TOKEN_'
- Description: A unique token that you can generate for free on your DockWCAG account.
- Required: Yes.
- Example:
'abcde12345'
.
{_CONFIGURATION_}
- Description: An object containing the widget’s operational details.
- Required: No, but recommended to customize the functionality.
- Possible parameters are described below.
Configuration Parameters {_CONFIGURATION_}
The object allows you to customize the widget’s behavior. Below are the available options presented in a clear format.
1. Widget
Parameter | Type | Description | Values |
---|---|---|---|
widget |
Boolean | Specifies whether to display the accessibility widget. | true , false |
2. Widget Options
Key | Type | Description | Availability in version |
---|---|---|---|
contrast |
Boolean | Enables high contrast mode. | Basic, Premium |
invertColor |
Boolean | Enables color inversion. | Basic, Premium |
fontSize |
Boolean | Allows changing the font size. | Basic, Premium |
underline |
Boolean | Underlines links on the page. | Basic, Premium |
letterSpacing |
Boolean | Increases letter spacing. | Premium |
lineHeight |
Boolean | Increases line height in text. | Premium |
textToSpeech |
Boolean | Adds text-to-speech functionality. | Premium |
saturation |
Boolean | Adjusts color saturation. | Premium |
enlargeCursor |
Boolean | Enlarges the cursor pointer. | Premium |
hideMedia |
Boolean | Hides multimedia elements on the page. | Premium |
disableAnimations |
Boolean | Disables animations on the page. | Premium |
showLine |
Boolean | Adds a line to help focus on reading. | Premium |
dyslexic |
Boolean | Changes the font to one that is dyslexia-friendly. | Premium |
Note: Features marked as “Premium” are only available in the advanced version.
3. Widget Position
Parameter | Type | Description | Values |
---|---|---|---|
position |
String | Sets the default position of the widget activation button. | "right" , "left" |
4. Color Customization
Key | Type | Description | Example Value |
---|---|---|---|
primary |
String | Defines the primary color of the widget. | #0021c8 |
secondary |
String | Defines the secondary color of the widget. | #000243 |
Example of the Object
colors: {primary: '#0021c8', secondary: '#000243'}
These parameters allow full customization of the widget’s appearance to match the color scheme of the website where it is placed. The colors are passed in hex format (e.g., #0021c8
), which is commonly used in CSS styles and allows precise color specification.
5. Custom Button Selectors
The selectors
object allows you to assign your own buttons to the accessibility functions. Each key corresponds to a specific function, and the value is a CSS selector pointing to the HTML element.
Key | Type | Description |
---|---|---|
invertColor |
String | Button to enable color inversion. |
contrast |
String | Button to enable high contrast mode. |
increase |
String | Button to increase font size. |
decrease |
String | Button to decrease font size. |
textResize |
String | Button for overall text resizing. |
showLine |
String | Button to enable a visible underline line. |
lineHeight |
String | Button to change line height. |
letterSpacing |
String | Button to increase letter spacing. |
underline |
String | Button to underline links. |
textToSpeech |
String | Button to enable text-to-speech functionality. |
saturation |
String | Button to adjust color saturation. |
enlargeCursor |
String | Button to enlarge the cursor pointer. |
hideMedia |
String | Button to hide multimedia elements. |
dyslexic |
String | Button to change the font to a dyslexia-friendly one. |
disableAnimations |
String | Button to disable animations. |
motorImpaired |
String | Button to activate the motor impairment profile. |
adhd |
String | Button to activate the ADHD support profile. |
blind |
String | Button to activate the blind support profile. |
cognitiveAndLearning |
String | Button to activate the cognitive and learning support profile. |
colorBlind |
String | Button to activate the colorblind support profile. |
dyslexia |
String | Button to activate the dyslexia support profile. |
epileptic |
String | Button to activate the epileptic support profile. |
lowVision |
String | Button to activate a profile that supports people with low vision. |
reset |
String | Button that resets all settings. |
statement |
String | Button displaying the accessibility statement. |
Example of selectors
object:
{
"invertColor": ".btn-invert",
"contrast": ".btn-contrast",
"fontSize": ".btn-font-size",
"textToSpeech": ".btn-tts"
}
Examples of implementation
Simple configuration with a ready-made widget
<script> (function (w, d, s, l, t, c = {}) { w[l] = c; w[l].token = t; var f = d.getElementsByTagName(s)[0], j = d.createElement(s), a = new Date().getTime(); j.async = true; j.src = '//wcag.dock.codes/accessibility/' + t + '/start.js?t=' + a; f.parentNode.insertBefore(j, f); })(window, document, 'script', 'accessibility', 'abcde12345', { widget: true, position: 'right', colors: {primary: '#0021c8', secondary: '#000243'}, options: {contrast: true, underline: true} }); </script>
Advanced configuration with custom selectors
<script> (function (w, d, s, l, t, c = {}) { w[l] = c; w[l].token = t; var f = d.getElementsByTagName(s)[0], j = d.createElement(s), a = new Date().getTime(); j.async = true; j.src = '//wcag.dock.codes/accessibility/' + t + '/start.js?t=' + a; f.parentNode.insertBefore(j, f); })(window, document, 'script', 'accessibility', 'abcde12345', { widget: false, selectors: { showLine: ".wcag-focus", lineHeight: ".wcag-line-height", letterSpacing: ".wcag-letter-spacings", underline: ".wcag-underline", textToSpeech: ".wcag-text-to-speech", saturation: ".wcag-saturation", reset: ".wcag-reset", } }); </script>
Concluding remarks
- Make sure your unique token is correct before deployment.
- Premium versions offer additional features that can significantly improve accessibility.
- Custom selectors give you full control over the features, so you can customize them to fit your site design.