Comparing version 0.2.1 to 0.2.2
78
jymin.js
/** | ||
* _ _ ___ ____ ___ | ||
* | |_ _ _ __ ___ (_)_ __ __ __/ _ \ |___ \ / _ \ | ||
* _ | | | | | '_ ` _ \| | '_ \ \ \ / / | | | __) || | | | | ||
* | |_| | |_| | | | | | | | | | | \ V /| |_| | / __/ | |_| | | ||
* \___/ \__, |_| |_| |_|_|_| |_| \_/ \___(_)_____(_)___/ | ||
* _ _ ___ ____ ____ | ||
* | |_ _ _ __ ___ (_)_ __ __ __/ _ \ |___ \ |___ \ | ||
* _ | | | | | '_ ` _ \| | '_ \ \ \ / / | | | __) | __) | | ||
* | |_| | |_| | | | | | | | | | | \ V /| |_| | / __/ _ / __/ | ||
* \___/ \__, |_| |_| |_|_|_| |_| \_/ \___(_)_____(_)_____| | ||
* |___/ | ||
@@ -33,3 +33,3 @@ * | ||
this.jymin = {version: '0.2.0'}; | ||
this.jymin = {version: '0.2.2'}; | ||
@@ -48,4 +48,4 @@ /** | ||
var getResponse = function ( | ||
url, // string: The URL to request data from. | ||
data, // object|: Data to post. The method is automagically "POST" if data is truey, otherwise "GET". | ||
url, // string: The URL to request a response from. | ||
body, // object|: Data to post. The method is automagically "POST" if body is truey, otherwise "GET". | ||
onSuccess, // function|: Callback to run on success. `onSuccess(response, request)`. | ||
@@ -55,8 +55,8 @@ onFailure, // function|: Callback to run on failure. `onFailure(response, request)`. | ||
) { | ||
// If the optional data argument is omitted, shuffle it out. | ||
if (isFunction(data)) { | ||
// If the optional body argument is omitted, shuffle it out. | ||
if (isFunction(body)) { | ||
evalJson = onFailure; | ||
onFailure = onSuccess; | ||
onSuccess = data; | ||
data = 0; | ||
onSuccess = body; | ||
body = 0; | ||
} | ||
@@ -75,3 +75,4 @@ var request; | ||
--getResponse._WAITING; | ||
var isSuccess = (request.status == 200); | ||
var status = request.status; | ||
var isSuccess = (status == 200); | ||
var callback = isSuccess ? | ||
@@ -83,14 +84,20 @@ onSuccess || globalResponseSuccessHandler : | ||
var object; | ||
try { | ||
// Trick Uglify into thinking there's no eval. | ||
var e = window.eval; | ||
e('eval.J=' + response); | ||
object = e.J; | ||
if (status) { | ||
try { | ||
// Trick Uglify into thinking there's no eval. | ||
var e = window.eval; | ||
e('eval.J=' + response); | ||
object = e.J; | ||
} | ||
catch (e) { | ||
//+env:dev | ||
error('Could not parse JSON: "' + response + '"'); | ||
//-env:dev | ||
object = {_ERROR: '_BAD_JSON', _TEXT: response}; | ||
} | ||
} | ||
catch (e) { | ||
//+env:dev | ||
error('Could not parse JSON: "' + response + '"'); | ||
//-env:dev | ||
object = {_ERROR: 'Invalid JSON', _TEXT: response}; | ||
else { | ||
object = {_ERROR: '_OFFLINE'}; | ||
} | ||
object._STATUS = status; | ||
object.request = request; | ||
@@ -102,9 +109,22 @@ response = object; | ||
}; | ||
request.open(data ? 'POST' : 'GET', url, true); | ||
request.open(body ? 'POST' : 'GET', url, true); | ||
request.setRequestHeader('x-requested-with', 'XMLHttpRequest'); | ||
if (data) { | ||
if (body) { | ||
request.setRequestHeader('content-type', 'application/x-www-form-urlencoded'); | ||
} | ||
getResponse._WAITING = (getResponse._WAITING || 0) + 1; | ||
request.send(data || null); | ||
// Record the original request URL. | ||
request.url = url; | ||
// TODO: Populate request.query with URL query params. | ||
// If it's a post, record the post body. | ||
if (body) { | ||
request.body = body; | ||
} | ||
// | ||
request._TIME = new Date(); | ||
request.send(body || null); | ||
} | ||
@@ -119,8 +139,8 @@ return true; | ||
var getJson = function ( | ||
url, // string: The URL to request data from. | ||
data, // object|: Data to post. The method is automagically "POST" if data is truey, otherwise "GET". | ||
url, // string: The URL to request a response from. | ||
body, // object|: Data to post. The method is automagically "POST" if body is truey, otherwise "GET". | ||
onSuccess, // function|: Callback to run on success. `onSuccess(response, request)`. | ||
onFailure // function|: Callback to run on failure. `onFailure(response, request)`. | ||
) { | ||
return getResponse(url, data, onSuccess, onFailure, true); | ||
return getResponse(url, body, onSuccess, onFailure, true); | ||
}; | ||
@@ -127,0 +147,0 @@ var DEFAULT_ANIMATION_FRAME_COUNT = 40; |
@@ -15,3 +15,3 @@ { | ||
], | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"main": "chug/chug.js", | ||
@@ -18,0 +18,0 @@ "homepage": "http://lighter.io/jymin", |
@@ -13,4 +13,4 @@ /** | ||
var getResponse = function ( | ||
url, // string: The URL to request data from. | ||
data, // object|: Data to post. The method is automagically "POST" if data is truey, otherwise "GET". | ||
url, // string: The URL to request a response from. | ||
body, // object|: Data to post. The method is automagically "POST" if body is truey, otherwise "GET". | ||
onSuccess, // function|: Callback to run on success. `onSuccess(response, request)`. | ||
@@ -20,8 +20,8 @@ onFailure, // function|: Callback to run on failure. `onFailure(response, request)`. | ||
) { | ||
// If the optional data argument is omitted, shuffle it out. | ||
if (isFunction(data)) { | ||
// If the optional body argument is omitted, shuffle it out. | ||
if (isFunction(body)) { | ||
evalJson = onFailure; | ||
onFailure = onSuccess; | ||
onSuccess = data; | ||
data = 0; | ||
onSuccess = body; | ||
body = 0; | ||
} | ||
@@ -40,3 +40,4 @@ var request; | ||
--getResponse._WAITING; | ||
var isSuccess = (request.status == 200); | ||
var status = request.status; | ||
var isSuccess = (status == 200); | ||
var callback = isSuccess ? | ||
@@ -48,14 +49,20 @@ onSuccess || globalResponseSuccessHandler : | ||
var object; | ||
try { | ||
// Trick Uglify into thinking there's no eval. | ||
var e = window.eval; | ||
e('eval.J=' + response); | ||
object = e.J; | ||
if (status) { | ||
try { | ||
// Trick Uglify into thinking there's no eval. | ||
var e = window.eval; | ||
e('eval.J=' + response); | ||
object = e.J; | ||
} | ||
catch (e) { | ||
//+env:dev | ||
error('Could not parse JSON: "' + response + '"'); | ||
//-env:dev | ||
object = {_ERROR: '_BAD_JSON', _TEXT: response}; | ||
} | ||
} | ||
catch (e) { | ||
//+env:dev | ||
error('Could not parse JSON: "' + response + '"'); | ||
//-env:dev | ||
object = {_ERROR: 'Invalid JSON', _TEXT: response}; | ||
else { | ||
object = {_ERROR: '_OFFLINE'}; | ||
} | ||
object._STATUS = status; | ||
object.request = request; | ||
@@ -67,9 +74,22 @@ response = object; | ||
}; | ||
request.open(data ? 'POST' : 'GET', url, true); | ||
request.open(body ? 'POST' : 'GET', url, true); | ||
request.setRequestHeader('x-requested-with', 'XMLHttpRequest'); | ||
if (data) { | ||
if (body) { | ||
request.setRequestHeader('content-type', 'application/x-www-form-urlencoded'); | ||
} | ||
getResponse._WAITING = (getResponse._WAITING || 0) + 1; | ||
request.send(data || null); | ||
// Record the original request URL. | ||
request.url = url; | ||
// TODO: Populate request.query with URL query params. | ||
// If it's a post, record the post body. | ||
if (body) { | ||
request.body = body; | ||
} | ||
// | ||
request._TIME = new Date(); | ||
request.send(body || null); | ||
} | ||
@@ -84,8 +104,8 @@ return true; | ||
var getJson = function ( | ||
url, // string: The URL to request data from. | ||
data, // object|: Data to post. The method is automagically "POST" if data is truey, otherwise "GET". | ||
url, // string: The URL to request a response from. | ||
body, // object|: Data to post. The method is automagically "POST" if body is truey, otherwise "GET". | ||
onSuccess, // function|: Callback to run on success. `onSuccess(response, request)`. | ||
onFailure // function|: Callback to run on failure. `onFailure(response, request)`. | ||
) { | ||
return getResponse(url, data, onSuccess, onFailure, true); | ||
return getResponse(url, body, onSuccess, onFailure, true); | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90994
3316