ARIAMetadata.js 1.2 KB

123456789101112
  1. export default class ARIAMetadata{constructor(config){this._attributes=new Map();if(config){this._initialize(config);}}
  2. _initialize(config){const attributes=config['attributes'];const booleanEnum=['true','false'];for(const attributeConfig of attributes){if(attributeConfig.type==='boolean'){attributeConfig.enum=booleanEnum;}
  3. this._attributes.set(attributeConfig.name,new Accessibility.ARIAMetadata.Attribute(attributeConfig));}
  4. this._roleNames=config['roles'].map(roleConfig=>roleConfig.name);}
  5. valuesForProperty(property){if(this._attributes.has(property)){return this._attributes.get(property).getEnum();}
  6. if(property==='role'){return this._roleNames;}
  7. return[];}}
  8. export function ariaMetadata(){if(!Accessibility.ARIAMetadata._instance){Accessibility.ARIAMetadata._instance=new Accessibility.ARIAMetadata(Accessibility.ARIAMetadata._config||null);}
  9. return Accessibility.ARIAMetadata._instance;}
  10. export class Attribute{constructor(config){this._enum=[];if('enum'in config){this._enum=config.enum;}}
  11. getEnum(){return this._enum;}}
  12. self.Accessibility=self.Accessibility||{};Accessibility=Accessibility||{};Accessibility.ARIAMetadata=ARIAMetadata;Accessibility.ARIAMetadata.Attribute=Attribute;Accessibility.ariaMetadata=ariaMetadata;