Changes

Jump to: navigation, search

Labs/Ubiquity/Ubiquity Source Tip Author Tutorial

426 bytes added, 06:16, 22 June 2009
Switching: Writing your own Noun-Types
== Switching: Writing your own Noun-Types ==
A noun-type needs to only have two things: A name <code>label</code> and a <code>suggest ()</code> function. Soon, we'll probably move to having It can optionally also have a convenience <code>CmdUtils.CreateNounTypedefault()</code>, which will simplify things even morefunction.
The name label is what shows up when the command prompts for input. Suggest returns a list of input objects, each one containing the name of a matching tab. We're using [http://developer.mozilla.org/en/docs/FUEL FUEL] to interact with the browser, which is where the "Application" variable comes from.
<pre>
var noun_type_tab = {
_namelabel: "tab name",
// Returns all tabs from all windows.
},
suggest: function( text, html , callback ) {
var suggestions = [];
The suggest method of a noun type always gets passed both text and html. If the input is coming from a part of a web page that the user has selected, these
values can be different: they are both strings, but the html value contains markup tags while the text value does not. The Tab noun type only cares about the plain text of the tab name, so we ignore the value of html.
 
The callback argument is for use by nountypes that need to run asynchronously, i.e. becaus they need to do network calls to generate suggestions. The callback is a function; instead of returning a list of suggestions right away, an asynchronous noun type can call the callback with each suggestion it generates. More on this later; the tab noun type generates all its suggestions right away, so it just returns them instead of using the callback.
We use the convenience function <code>CmdUtils.makeSugg()</code> to generate an
1,007
edits

Navigation menu