Sha256: 3c8b8f9f28d3fd4f54c830013b9b5d98d67fe87c4c44b7a1be3c1828dff9e4d2

Contents?: true

Size: 881 Bytes

Versions: 1

Compression:

Stored size: 881 Bytes

Contents

// Javascript shorty client. Brad Gessler (c) 2009.
(function($){
  $.extend({
    shorty: {
      shorten: function(url, key, options){
        var location;
        var type = (key === 'undefined') ? 'POST' : 'PUT';
        var endpoint = (key === 'undefined') ? '/' : '/' + key;
        
        $.ajax({
          data: url,
          type: type,
          url: endpoint,
          complete: function(xhr){
            if(xhr.status === 201 && options.success){
              var location = xhr.getResponseHeader('location');
              options.success(location);
            }
          },
          error: function(xhr){
            if (options.success) { options.error(xhr.responseText); }
          }
        });
      },
      getKey: function(callback){
        $.get('/key/random', function(key){
          callback(key);
        });
      }
    }
  });  
})(jQuery);

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shorty_server-0.5.0 lib/shorty/ui/public/jquery.shorty.js