Skip to content

Commit

Permalink
feature(jsonloader): updated callback parameter behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyTheTank committed Jan 21, 2016
1 parent 687bc79 commit 23cabc1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apiNG",
"version": "1.0.2",
"version": "1.0.3",
"homepage": "https://github.com/JohnnyTheTank/apiNG",
"authors": [
"Jonathan Hornung <[email protected]>"
Expand Down
29 changes: 19 additions & 10 deletions dist/aping.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
@name: aping
@version: 1.0.2 (20-01-2016)
@version: 1.0.3 (21-01-2016)
@author: Jonathan Hornung <[email protected]>
@url: https://github.com/JohnnyTheTank/apiNG
@license: MIT
Expand Down Expand Up @@ -677,24 +677,26 @@ angular.module("jtt_aping_jsonloader", [])
requestObject.format = "jsonp";
}

if (request.callback && request.format === "jsonp") {
if (request.callback) {
requestObject.callback = request.callback;
} else {
}

if (request.format === "jsonp" && !request.callback) {
requestObject.callback = 'JSON_CALLBACK';
}

if(angular.isDefined(request.items)) {
if (angular.isDefined(request.items)) {
requestObject.count = request.items;
} else {
requestObject.count = appSettings.items;
}

if(requestObject.count === 0 || requestObject.count === '0') {
if (requestObject.count === 0 || requestObject.count === '0') {
return false;
}

// -1 is "no explicit limit". same for NaN value
if(requestObject.count < 0 || isNaN(requestObject.count)) {
if (requestObject.count < 0 || isNaN(requestObject.count)) {
requestObject.count = undefined;
}

Expand All @@ -706,14 +708,14 @@ angular.module("jtt_aping_jsonloader", [])

var results = _data.data;

if(angular.isDefined(request.resultProperty)) {
if (angular.isDefined(request.resultProperty)) {
results = _data.data[request.resultProperty];
}

if (_data.data.constructor !== Array) {
resultArray.push(results);
} else {
if (request.items < 0 || angular.isDefined(request.items) ) {
if (request.items < 0 || angular.isDefined(request.items)) {
resultArray = results;
} else {
angular.forEach(results, function (value, key) {
Expand All @@ -735,20 +737,27 @@ angular.module("jtt_aping_jsonloader", [])
var jsonloaderFactory = {};

jsonloaderFactory.getJsonData = function (_requestObject) {
var params = {};
if (angular.isDefined(_requestObject.callback)) {
params[_requestObject.callback] = 'JSON_CALLBACK';
}


if (_requestObject.format === "jsonp") {

return $http.jsonp(
_requestObject.path,
{
method: 'GET',
params: {callback: _requestObject.callback},
params: params,
}
);

} else {
return $http({
method: 'GET',
url: _requestObject.path
url: _requestObject.path,
params: params
});
}
};
Expand Down
Loading

0 comments on commit 23cabc1

Please sign in to comment.