Browse files

Update Jquery Client

  • Loading branch information...
1 parent 5ba3966 commit 92f8ac5a46e853f8ca9be5ee5949c00cff764030 @tedeh committed Jun 30, 2012
Showing with 26 additions and 8 deletions.
  1. +26 −8 lib/client/jquery.js
View
34 lib/client/jquery.js
@@ -1,7 +1,13 @@
;(function($, undefined) {
- var ClientJquery = function(options) {
- if(!(this instanceof ClientJquery)) return new ClientJquery(options);
+ /**
+ * Constructor for a Jayson Jquery Client
+ * @class Jayson JSON-RPC Jquery Client
+ * @param {Object} options Settings for the ajax request
+ * @return {JqueryClient}
+ */
+ var JqueryClient = function(options) {
+ if(!(this instanceof JqueryClient)) return new JqueryClient(options);
var defaults = {
dataType: 'json',
@@ -13,9 +19,15 @@
this.options = $.extend(defaults, options || {});
};
- window.Jayson = ClientJquery;
+ window.Jayson = JqueryClient;
- ClientJquery.prototype.request = function(method, params, id, callback) {
+ /**
+ * Sends a request to the server
+ * @see Utils.request
+ * @return {void}
+ * @api public
+ */
+ JqueryClient.prototype.request = function(method, params, id, callback) {
// wrap around the error and success callbacks for post-processing
var options = $.extend({}, this.options, {
error: function(xhr, status, error) { callback($.makeArray(arguments)); },
@@ -33,7 +45,7 @@
// Expose the client as a jQuery extension
$.fn.jayson = function(options) {
options = options || {};
- var client = new ClientJquery(options);
+ var client = new JqueryClient(options);
client.request(options.method, options.params, options.id, function(err, data) {
if(err) {
if($.isFunction(options.error)) {
@@ -56,7 +68,10 @@
return this;
};
- // Generates a JSON-RPC 2.0 request (see jayson.utils.request)
+ /**
+ * Generates a JSON-RPC 2.0 request
+ * @see Utils.request
+ */
function generateRequest(method, params, id) {
if($.type(method) !== 'string') {
throw new TypeError(method + ' must be a string');
@@ -82,15 +97,18 @@
return request;
}
- // Generates a request ID (see jayson.utils.generateId)
+ /**
+ * Generates a request ID
+ * @see Utils.generateId
+ */
function generateId() {
return Math.round(Math.random() * Math.pow(2, 24));
}
// Expose the client via AMD if available
if(typeof(define) === 'function') {
define('jayson', [], function() {
- return ClientJquery;
+ return JqueryClient;
});
}
})(jQuery);

0 comments on commit 92f8ac5

Please sign in to comment.