Skip to content

API Reference ​

The BrowseAid Widget provides a comprehensive JavaScript API for programmatic control of accessibility features. This allows developers to integrate accessibility tools seamlessly into their applications.

Quick Example ​

javascript
// Access the widget API
const api = window.BrowseAidWidget.api;

// Enable dark mode
api.enableTool('dark-mode');

// Listen for tool changes
api.onToolChange((toolName, settings) => {
  console.log(`${toolName} changed:`, settings);
});

// Toggle widget visibility
api.toggleWidget();

API Structure ​

The BrowseAid Widget API is organized into several main areas:

Tool Management ​

  • Tool Control: Enable, disable, and configure accessibility tools
  • State Management: Get current tool states and settings
  • Batch Operations: Reset multiple tools or apply profiles

Event System ​

  • Tool Events: Listen for tool state changes
  • Widget Events: Monitor widget visibility and initialization
  • Language Events: Track language changes

Configuration ​

  • Widget Settings: Control widget appearance and behavior
  • Localization: Change languages and manage translations
  • Theme Control: Switch between light/dark themes

Available Methods ​

MethodDescription
enableTool(toolName, options?)Enable a specific tool with optional settings
disableTool(toolName)Disable a specific tool
toggleTool(toolName, options?)Toggle a tool's enabled state
updateTool(toolName, settings)Update tool with specific settings
getToolState(toolName)Get current state of a tool
resetAllTools()Reset all tools to defaults
setLanguage(language)Change widget language
getLanguage()Get current language
showWidget()Show the widget interface
hideWidget()Hide the widget interface
toggleWidget()Toggle widget visibility

Event Listeners ​

Event ListenerDescription
onToolChange(callback)Listen for tool state changes
onVisibilityChange(callback)Listen for widget visibility changes
onLanguageChange(callback)Listen for language changes
onInit(callback)Listen for widget initialization

Native DOM Events ​

In addition to callback-based events, the widget also dispatches native DOM events:

Event NameDescription
browseaid:toolChangeTool state changed
browseaid:visibilityChangeWidget visibility changed
browseaid:languageChangeLanguage changed
browseaid:initWidget initialized

Error Handling ​

All API methods include proper error handling:

javascript
try {
  api.enableTool('non-existent-tool');
} catch (error) {
  console.error('Tool not found:', error.message);
}

Next Steps ​

BrowseAid Documentation