Changes

Jump to: navigation, search

Labs/Ubiquity/Ubiquity Source Tip Author Tutorial

314 bytes added, 04:50, 22 June 2009
TinyURL: Network Calls and jQuery
</blockquote>
== TinyURL: Network Calls and jQuery (and the URL noun type)==
Often while writing emails, I'll discover that I've pasted in a URL long enough to be used for unfortunate analogies. I'd like to be able to quickly turn that into a [http://en.wikipedia.org/wiki/Tinyurl TinyURL]&mdash;but the process of making a TinyURL involves lots of fiddly steps. Ubiquity to the rescue.
<pre>
CmdUtils.CreateCommand({
namenames: ["tinyurl"], takesarguments: [{role: "object", nountype: noun_type_url, label: "url to shorten": noun_type_url},
preview: "Replaces the selected URL with a TinyUrl.",
execute: function( urlToShorten arguments ) {
var baseUrl = "http://tinyurl.com/api-create.php";
var params = {url: urlToShortenarguments.object.text};
jQuery.get( baseUrl, params, function( tinyUrl ) {
CmdUtils.setSelection( tinyUrl );
})
</pre>
 
<code>noun_type_url</code> is a useful nountype because it defaults to the URL of the page that you are currently on. If that is in fact the URL that the user wants, then they don't have to type it or even select it.
jQuery is a powerful tool. With it, you can fairly effortlessly cherry-pick the data you need from RSS feeds, XML, and all sorts of other data formats. It also makes doing in-preview animations a breeze.
1,007
edits

Navigation menu