From 5d758a81ae00481b0dfda135be483b22636e5a65 Mon Sep 17 00:00:00 2001 From: Andrei Cacio Date: Wed, 12 Nov 2014 14:03:31 +0200 Subject: [PATCH] Added comments --- src/adapters/XHRJson.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/adapters/XHRJson.js b/src/adapters/XHRJson.js index 47aac71..25a2b0e 100644 --- a/src/adapters/XHRJson.js +++ b/src/adapters/XHRJson.js @@ -14,6 +14,11 @@ this.fail = null; } + /** + * Check if an URL starts and ends with / + * @param {String} string URL + * @return {String} The fixed URL string + */ function checkURL(string) { if (typeof string !== 'string') { return '/'; @@ -29,6 +34,10 @@ return string; } + /** + * Constructor + * @param {String} url The API URL + */ XHRJson.prototype.init = function(url) { var self = this; @@ -50,22 +59,43 @@ }; }; + /** + * URL getter + * @return {String} URL string + */ XHRJson.prototype.getAPIURL = function() { return this.apiUrl; }; + /** + * Callback which is if the request is done + * @param {Function} callback Callback function + * @return {Object} Mjs + */ XHRJson.prototype.onDone = function(callback) { this.done = callback; return this; }; + /** + * Callback which is if the request failed + * @param {Function} callback Callback function + * @return {Object} Mjs + */ XHRJson.prototype.onFail = function(callback) { this.fail = callback; return this; }; + /** + * Perform an AJAX request + * @param {String} method HTTP method + * @param {String} url URL string + * @param {Boolean} async + * @param {Object} data POST/PUT data + */ XHRJson.prototype.ajax = function(method, url, async, data) { method = method.toUpperCase(); this.xhr.open(method, this.apiUrl + url, async);