jQuery longUrl: Uniform Resource Elongator

Version: 1.0, Last updated: 1/23/2010

Project Homehttp://benalman.com/projects/jquery-longurl-plugin/
GitHubhttp://github.com/cowboy/jquery-longurl/
Sourcehttp://github.com/cowboy/jquery-longurl/raw/master/jquery.ba-longurl.js
(Minified)http://github.com/cowboy/jquery-longurl/raw/master/jquery.ba-longurl.min.js (1.2kb)
Summary
jQuery longUrl: Uniform Resource ElongatorVersion: 1.0, Last updated: 1/23/2010
LicenseCopyright © 2010 “Cowboy” Ben Alman, Dual licensed under the MIT and GPL licenses.
ExamplesThese working examples, complete with fully commented code, illustrate a few ways in which this plugin can be used.
Support and TestingInformation about what version or versions of jQuery this plugin has been tested with, what browsers it has been tested in, and where the unit tests reside (so you can test it yourself).
Release History
Functions
jQuery.longUrlLengthen one or more “short URLs” using a third-party lengthening service (defaults to longurlplease.com).
jQuery.longUrlOverride the default lengthening service options with custom settings.
jQuery.fn.longUrlLengthen one or more “short URLs” in A elements, using a third-party lengthening service (defaults to longurlplease.com).

License

Copyright © 2010 “Cowboy” Ben Alman, Dual licensed under the MIT and GPL licenses.  http://benalman.com/about/license/

Examples

These working examples, complete with fully commented code, illustrate a few ways in which this plugin can be used.

longurlhttp://benalman.com/code/projects/jquery-longurl/examples/longurl/

Support and Testing

Information about what version or versions of jQuery this plugin has been tested with, what browsers it has been tested in, and where the unit tests reside (so you can test it yourself).

jQuery Versions1.3.2, 1.4.1
Browsers TestedInternet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome, Opera 9.6-10.1.
Unit Testshttp://benalman.com/code/projects/jquery-longurl/unit/

Release History

1.0(1/23/2010) Initial release

Functions

jQuery.longUrl

Lengthen one or more “short URLs” using a third-party lengthening service (defaults to longurlplease.com).  Note that only absolute URLs will be lengthened.

Usage

jQuery.longUrl( urls, callback );

Arguments

urls(String) A single “short URL” to lengthen.
urls(Array) An array of “short URLs” to lengthen.
callback(Function) This function, invoked after all passed URLs have either been fetched from the internal cache or lengthening service, is passed a single argument: an object containing short URL keys to long URL values.

Returns

Nothing.

jQuery.longUrl

Override the default lengthening service options with custom settings.

Usage

jQuery.longUrl( options );

Arguments

options(Object) An object containing lengthening service options.

Options

fetch(Function) This function is invoked for each set of `batch` URLs to be lengthened, receiving two arguments: an array of URLs (no longer than `batch` in length), and a callback that, upon fetch success, shall be called with one argument: an object containing short URL keys to long URL values.
batch(Number) The maximum number of URLs that can be lengthened per request.  While the longurlplease.com API allows 10 URLs per request, different services may vary.

Returns

Nothing.

jQuery.fn.longUrl

Lengthen one or more “short URLs” in A elements, using a third-party lengthening service (defaults to longurlplease.com).  Note that only absolute URLs will be lengthened.

Usage

jQuery('selector').longUrl( [ options ] );

Arguments

options(Object) An optional configuration object.

Options

callback(Function) This function, called after all passed URLs have either been fetched from the internal cache or lengthening service, is called once for each element (or group of elements sharing the same short URL), and passed two arguments: the original short URL, followed by the long URL.  Because multiple elements sharing the same short URL href will be operated on together, for efficiency, `this` refers to a jQuery object containing references to one or more A elements.  If not specified, the default behavior is to set the title and href attributes of each link to their retrieved long URL.  This can be set to `false` to disable any per-element callback.  Note that, since changing A elements’ href attribute in IE may also change their innerHTML, in the default callback, the old value is stored and tested after the href is updated.  A user-specified callback should take this into consideration.  See this for more information: http://stackoverflow.com/questions/1790698/
complete(Function) This optional function, called after all `callback` executions, is passed a single argument: an object containing short URL keys to long URL values.  In this function, `this` refers to the initial jQuery collection of elements.

Returns

(jQuery) The initial jQuery collection of elements.

Close