diff --git a/README.md b/README.md index d1f588a..dea9b19 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ A comprehensive, lightweight accessibility tool that enhances web accessibility ## Installation +### Method 1: Direct Download 1. Download the `widget.js` file 2. Include it in your HTML page: @@ -33,27 +34,64 @@ A comprehensive, lightweight accessibility tool that enhances web accessibility ``` +### Method 2: NPM +```bash +npm install web-accessibility-widget +``` + +### Method 3: CDN +```html + +``` + That's it! The widget will automatically initialize when the page loads. ## Configuration -The widget is highly customizable through the `WIDGET_CONFIG` object at the top of the file. You can: +The widget is highly customizable. You can override the default settings by defining `window.ACCESSIBILITY_WIDGET_CONFIG` before loading the widget script. -### Enable/Disable Features -```javascript -const WIDGET_CONFIG = { +### Basic Configuration +```html + + +``` + +### Complete Configuration Options +```html + + +``` + +### Partial Configuration +You only need to specify the settings you want to change. The widget will merge your settings with the defaults: + +```html + + ``` ## Voice Commands @@ -140,8 +223,8 @@ When voice control is enabled, users can activate features using these commands: ### Custom Configuration ```html - + ``` ## Accessibility Standards diff --git a/widget.js b/widget.js index 0545313..16dd1f2 100644 --- a/widget.js +++ b/widget.js @@ -9,8 +9,8 @@ // CONFIGURATION VARIABLES // =========================================== -// Feature toggles - set to false to disable features -const WIDGET_CONFIG = { +// Default configuration - can be overridden by user +const DEFAULT_WIDGET_CONFIG = { // Core Features enableHighContrast: true, enableBiggerText: true, @@ -88,6 +88,29 @@ const WIDGET_CONFIG = { } }; +// Function to deep merge user configuration with defaults +function mergeConfigs(defaultConfig, userConfig) { + const result = { ...defaultConfig }; + + if (!userConfig) return result; + + for (const key in userConfig) { + if (userConfig.hasOwnProperty(key)) { + if (typeof userConfig[key] === 'object' && userConfig[key] !== null && !Array.isArray(userConfig[key])) { + result[key] = mergeConfigs(defaultConfig[key] || {}, userConfig[key]); + } else { + result[key] = userConfig[key]; + } + } + } + + return result; +} + +// Merge user configuration with defaults +// Users can define window.ACCESSIBILITY_WIDGET_CONFIG before loading this script +const WIDGET_CONFIG = mergeConfigs(DEFAULT_WIDGET_CONFIG, window.ACCESSIBILITY_WIDGET_CONFIG || {}); + // =========================================== // STYLES & VISUAL ASSETS // ===========================================