Changes

Jump to: navigation, search

Labs/Ubiquity/Locked-Down Feed Tutorial

1,182 bytes added, 17:42, 17 March 2009
added section on DOs and modifiers
<pre>
<link rel="locked-down-commands" href="http://path-to-js" name="Title Goes Here" />
</pre>
 
== Direct Objects and Modifiers ==
 
Commands in LD Feeds can use direct objects and modifiers, but they can only be specified using regular expressions: the noun types available in regular feeds aren't available here.
 
For instance, here's a "replace" command that allows the user to perform a find-replace operation on their selection via Ubiquity:
 
<pre>
/* This is a template command. */
CmdUtils.CreateCommand({
name: "replace",
takes: {"input": /.*/},
modifiers: {"with": /.*/, "in": /.*/},
preview: function(pblock, input, mods) {
var stuff = mods['in'].text;
var regExp = new RegExp(input.text, "g");
var replacer = mods['with'].text;
if (!replacer || !stuff || !input.text) {
pblock.innerHTML = ("Replaces the given text in the given " +
"selection with something different.");
} else {
var newText = stuff.replace(regExp, replacer);
pblock.innerHTML = newText;
}
},
execute: function(input, mods) {
var stuff = mods['in'].text;
var regExp = new RegExp(input.text, "g");
var replacer = mods['with'].text;
 
CmdUtils.setSelection(stuff.replace(regExp, replacer));
}
});
</pre>
874
edits

Navigation menu