Accessibility/WebAccessibilityAPI: Difference between revisions

Line 159: Line 159:
<code>
<code>
AttributeSet .''hasAnyOf''
AttributeSet .''hasAnyOf''
::Return true if any of the given object properties and its non null value matches a { name, value } pair from the map. If a null value property value matches a map name then value is ignored and is not part of the match.
::Return true if any of the object properties matches to the object attributes.


AttributeSet .''hasAllOf''
AttributeSet .''hasAllOf''
::Return true if all properties of the given object and their values match name/value pairs from the map. If matched property value is null then value is ignored and is not part of the match.
::Return true if all of the object properties matches to the object attributes.
</code>
</code>


Each property of the object is a string or an array of strings. If array of strings is given then the object attribute is expected to have any of given values, empty array means the attribute value doesn't matter for match. String value and null values are treated as single element array or empty array correspondingly.


Example of a script processing list autocomplete.
<b>Example #1.</b>


<pre>
<pre>
var accElm = document.getElementById("foo").accessibleElement;
var attrs = {
var autocomplete = accElm.attributes.get("autocomplete");
  live: [ "assertive", "polite" ],
  relevant: "show",
  busy: null
};
 
var matched = accEl.hasAllOf(attrs);
// Matches if the ccessible element has "live" object attribute of
// "assertive" or "polite" values, has "relevant" object attribute of
// "show" value, and it has "busy" attribute.
</pre>
 
 
<b>Example #2. Process autocomplete.</b>
 
<pre>
var accEl = document.getElementById("foo").a11ement;
 
var checkObj = { autocomplete: [ "list", "both" ] };
if (accEl.attributes.hasAllOf(checkObj)) {
  doAutocomplete();
}
 
// Alternatively you can do
var autocomplete = accEl.attributes.get("autocomplete");
if (["list", "both"].indexOf(autocomplete) != -1) {
if (["list", "both"].indexOf(autocomplete) != -1) {
   processListAutocomplete();
   doAutocomplete();
}
}
</pre>
</pre>
Confirmed users
1,396

edits