jQuery Long Url uses the longurlplease.com short URL lengthening API to expand short URLs from at least 80 services, including bit.ly, is.gd, tinyurl.com and more!

And not only has jQuery Long Url been written to take advantage of the longurlplease.com API "batch" ability, where up to ten URLs can be lengthened per request, but it can optionally use any lengthening service, supporting any URL-per-request "batch" limitations, which minimizes the number of external requests made for faster performance.

Link info

 

The code

$(function(){
  
  // Select some A elements.
  $('#test a')
    
    // Set a default title attribute for these links.
    .attr( 'data-title', 'Not processed!' )
    
    // By default, $('a').longUrl(); will updated the href and title attributes
    // for each selected A element, as long as its href was a short URL that
    // could be lengthened. In this example, we get a little more custom, in
    // order to show how flexible the plugin can be...
    .longUrl({
      
      // Set the data-title HTML5 attribute as well as a class for each element
      // or group of elements that share the same href.
      callback: function( href, long_url ) {
        if ( long_url ) {
          this.attr({ 'data-title': 'Lengthened: ' + long_url }).addClass( 'expanded' );
        } else {
          this.attr({ 'data-title': 'Not lengthened: ' + href }).addClass( 'not-expanded' );
        }
      },
      
      // When all fetching and processing is done, set the '#info' text to
      // something interesting.
      complete: function( result ) {
        var num_elements = this.length,
          num_unique = 0,
          num_lengthened = 0,
          num_not_lengthened = 0,
          text;
        
        $.each( result, function( href, long_url ){
          num_unique++;
          long_url ? num_lengthened++ : num_not_lengthened++;
        });
        
        text = 'Of ' + num_elements + ' elements, there were ' + num_unique
          + ' unique absolute links, ' + num_lengthened
          + ' of which could be lengthened, and ' + num_not_lengthened
          + ' of which could not.';
        
        $('#info').text( text );
      }
    })
    
    // Show the title attribute on hover.
    .live( 'mouseover', function(e){
      var title = $(this).attr( 'data-title' );
      $('#info').text( title );
    });
});