874
edits
(→A Lot Like Regular Feeds: minor rewording) |
(added section on DOs and modifiers) |
||
| Line 49: | Line 49: | ||
<pre> | <pre> | ||
<link rel="locked-down-commands" href="http://path-to-js" name="Title Goes Here" /> | <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> | </pre> | ||
edits