Labs/Contacts/ContentAPI: Difference between revisions

Line 5: Line 5:
In a Firefox web browser which has installed the Contacts addon, the following new method becomes available to web content:
In a Firefox web browser which has installed the Contacts addon, the following new method becomes available to web content:


<tt>window.navigator.people.find( filter, fields, successCallback, failureCallback) </tt>
<tt>window.navigator.service.contacts(fields, successCallback, failureCallback, options) </tt>


The arguments are interpreted as follows:
The arguments are interpreted as follows:
* <tt>filter</tt> is an object that expresses a set of substring matches that must be met by contacts to be included in the result set.  The attributes of the object are the fields that will be searched, and the values are the substrings that must be found. 
For example, a filter of <tt>{ emails: "@mozilla.com" }</tt> will include only contacts whose <tt>emails</tt> list contains at least one object that contains the substring "@mozilla.com".


* <tt>fields</tt> is an array of strings that express which fields of the contact will be made available to the web page.  The strings should be drawn from the set of known properties described in "Contact Schema", below.  The user will be asked to confirm each of the fields, and may choose to deny access to some fields, in which case the web page will receive a subset of what was requested.
* <tt>fields</tt> is an array of strings that express which fields of the contact will be made available to the web page.  The strings should be drawn from the set of known properties described in "Contact Schema", below.  The user will be asked to confirm each of the fields, and may choose to deny access to some fields, in which case the web page will receive a subset of what was requested.
Line 34: Line 30:
   $("errorMsg").innerHTML = "Unable to load contacts: " + error;
   $("errorMsg").innerHTML = "Unable to load contacts: " + error;
  }
  }
* <tt>options</tt> is an object that expresses a set of substring matches that must be met by contacts to be included in the result set.  The attributes of the object are the fields that will be searched, and the values are the substrings that must be found. 
For example, a filter of <tt>{ emails: "@mozilla.com" }</tt> will include only contacts whose <tt>emails</tt> list contains at least one object that contains the substring "@mozilla.com".


== Contact Schema ==
== Contact Schema ==
11

edits