From bbcbb2910bc6c12b5e06a3b52b5013ba64c6ad8b Mon Sep 17 00:00:00 2001 From: Jonathan Hornung Date: Sat, 12 Mar 2016 11:11:34 +0100 Subject: [PATCH] chore: bump version --- bower.json | 2 +- dist/aping.js | 45 ++++++++++++++++++++++++++++++++------------- dist/aping.min.js | 4 ++-- package.json | 2 +- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/bower.json b/bower.json index 8abc549..03b271f 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "apiNG", - "version": "1.3.0", + "version": "1.3.1", "homepage": "https://github.com/JohnnyTheTank/apiNG", "authors": [ "Jonathan Hornung " diff --git a/dist/aping.js b/dist/aping.js index 6c1a34f..0f1ff47 100644 --- a/dist/aping.js +++ b/dist/aping.js @@ -1,6 +1,6 @@ /** @name: aping - @version: 1.3.0 (09-03-2016) + @version: 1.3.1 (12-03-2016) @author: Jonathan Hornung @url: https://github.com/JohnnyTheTank/apiNG @license: MIT @@ -12,7 +12,6 @@ angular.module('jtt_aping', [ 'jtt_aping_local_storage', ]);;"use strict"; angular.module('jtt_aping') - .config(['$provide', function ($provide) { $provide.value("apingDefaultSettings", { apingApiKeys: {} @@ -36,8 +35,10 @@ angular.module('jtt_aping') removeDoubles: '@', mergeDoubles: '@', idBy: '@', - resultProperty: '@', - valueName: '@' + resultProperty: '@', // legacy + resultName: '@', + valueName: '@', + protocol: '@' }, link: function (scope, element, attrs, controller, transcludeFn) { @@ -73,11 +74,15 @@ angular.module('jtt_aping') }, controller: ['$scope', function ($scope) { - if (angular.isUndefined($scope.resultProperty)) { - $scope.resultProperty = "results"; + if(angular.isUndefined($scope.resultName)) { + if (angular.isUndefined($scope.resultProperty)) { + $scope.resultName = "results"; + } else { + $scope.resultName = $scope.resultProperty; + } } - $scope[$scope.resultProperty] = []; + $scope[$scope.resultName] = []; $scope.payload = $scope.payloadJson ? apingUtilityHelper.replaceSingleQuotesAndParseJson($scope.payloadJson) : {}; /** @@ -95,6 +100,7 @@ angular.module('jtt_aping') var mergeDoubles; var valueName; var idBy; + var protocol; if (angular.isDefined($scope.valueName)) { @@ -175,6 +181,14 @@ angular.module('jtt_aping') idBy = undefined; } + if (angular.isDefined($scope.protocol)) { + protocol = $scope.protocol; + } else if (angular.isDefined(apingDefaultSettings.protocol)) { + protocol = apingDefaultSettings.protocol; + } else { + protocol = undefined; + } + return { model: $scope.model || apingDefaultSettings.model || "native", getNativeData: getNativeData, @@ -185,7 +199,8 @@ angular.module('jtt_aping') removeDoubles: removeDoubles, mergeDoubles: mergeDoubles, idBy: idBy, - valueName: valueName + valueName: valueName, + protocol: protocol }; }; @@ -195,11 +210,15 @@ angular.module('jtt_aping') * @param _array */ this.concatToResults = function (_array) { - if (angular.isUndefined($scope.resultProperty)) { - $scope.resultProperty = "results"; + if(angular.isUndefined($scope.resultName)) { + if (angular.isUndefined($scope.resultProperty)) { + $scope.resultName = "results"; + } else { + $scope.resultName = $scope.resultProperty; + } } - var tempArray = $scope[$scope.resultProperty].concat(_array); + var tempArray = $scope[$scope.resultName].concat(_array); var appSettings = this.getAppSettings(); @@ -250,9 +269,9 @@ angular.module('jtt_aping') apingResults[appSettings.valueName] = tempArray; } - $scope[$scope.resultProperty] = tempArray; + $scope[$scope.resultName] = tempArray; - $scope.$broadcast('apiNG.resultMerged', {'resultProperty': $scope.resultProperty}); + $scope.$broadcast('apiNG.resultMerged', {'resultName': $scope.resultName}); }; this.apply = function () { $scope.$apply(); diff --git a/dist/aping.min.js b/dist/aping.min.js index 500ed23..d6aa564 100644 --- a/dist/aping.min.js +++ b/dist/aping.min.js @@ -1,8 +1,8 @@ /** @name: aping - @version: 1.3.0 (09-03-2016) + @version: 1.3.1 (12-03-2016) @author: Jonathan Hornung @url: https://github.com/JohnnyTheTank/apiNG @license: MIT */ -"use strict";angular.module("jtt_aping",["jtt_aping_jsonloader","jtt_aping_xml","jtt_aping_ng_array","jtt_aping_local_storage"]),angular.module("jtt_aping").config(["$provide",function(a){a.value("apingDefaultSettings",{apingApiKeys:{}})}]).value("apingResults",{}).directive("aping",["apingResults","apingDefaultSettings","apingUtilityHelper","$templateRequest","$compile",function(a,b,c,d,e){return{restrict:"E",transclude:!0,template:"",scope:{model:"@",getNativeData:"@",items:"@",maxItems:"@",orderBy:"@",orderReverse:"@",templateUrl:"@",payloadJson:"@",removeDoubles:"@",mergeDoubles:"@",idBy:"@",resultProperty:"@",valueName:"@"},link:function(a,c,f,g,h){function i(b){angular.isDefined(b)&&"$NONE"!==b?d(b).then(function(b){var d=angular.element(b);c.empty().append(d),e(d)(a)}):h(a,function(a,b){c.html(""),c.append(a),e(a)(b)}),a.$broadcast("apiNG.templateRendered")}var j=a.templateUrl;a.$watch("templateUrl",function(){i(a.templateUrl)}),angular.isUndefined(j)&&angular.isDefined(b.templateUrl)&&(j=b.templateUrl,i(j))},controller:["$scope",function(d){angular.isUndefined(d.resultProperty)&&(d.resultProperty="results"),d[d.resultProperty]=[],d.payload=d.payloadJson?c.replaceSingleQuotesAndParseJson(d.payloadJson):{},this.getAppSettings=function(){var a,c,e,f,g,h,i,j,k;return j=angular.isDefined(d.valueName)?d.valueName:void 0,a=angular.isDefined(d.items)?d.items:angular.isDefined(b.items)?b.items:void 0,c=angular.isDefined(d.maxItems)?d.maxItems:angular.isDefined(b.maxItems)?b.maxItems:void 0,e=angular.isDefined(d.getNativeData)?d.getNativeData:angular.isDefined(b.getNativeData)?b.getNativeData:!1,c=angular.isDefined(d.maxItems)?d.maxItems:angular.isDefined(b.maxItems)?b.maxItems:void 0,g=angular.isDefined(d.orderBy)?d.orderBy:angular.isDefined(b.orderBy)?b.orderBy:void 0,f=angular.isDefined(d.orderReverse)?d.orderReverse:angular.isDefined(b.orderReverse)?b.orderReverse:!1,h=angular.isDefined(d.removeDoubles)?d.removeDoubles:angular.isDefined(b.removeDoubles)?b.removeDoubles:!1,i=angular.isDefined(d.mergeDoubles)?d.mergeDoubles:angular.isDefined(b.mergeDoubles)?b.mergeDoubles:!1,k=angular.isDefined(d.idBy)?d.idBy:angular.isDefined(b.idBy)?b.idBy:void 0,{model:d.model||b.model||"native",getNativeData:e,items:a,maxItems:c,orderBy:g,orderReverse:f,removeDoubles:h,mergeDoubles:i,idBy:k,valueName:j}},this.concatToResults=function(b){angular.isUndefined(d.resultProperty)&&(d.resultProperty="results");var e=d[d.resultProperty].concat(b),f=this.getAppSettings();angular.isDefined(f.idBy)&&(e=c.createIdByPropertiesForArray(e,f.idBy),f.mergeDoubles!==!0&&"true"!==f.mergeDoubles||(e=c.mergeDuplicateObjectsFromArray(e,f.orderBy===!1||"false"===f.orderBy||"$NONE"===f.orderBy))),f.removeDoubles!==!0&&"true"!==f.removeDoubles||f.mergeDoubles!==!0&&"true"!==f.mergeDoubles&&(e=c.removeDuplicateObjectsFromArray(e,f.orderBy===!1||"false"===f.orderBy||"$NONE"===f.orderBy,angular.isDefined(f.idBy))),angular.isDefined(f.orderBy)&&f.orderBy!==!1&&"false"!==f.orderBy&&"$NONE"!==f.orderBy&&("$RANDOM"===f.orderBy?e=c.shuffleArray(e):e.sort(c.sortArrayByProperty(f.orderBy))),f.orderReverse!==!0&&"true"!==f.orderReverse||"$RANDOM"===f.orderBy||e.reverse(),f.maxItems>-1&&e.length>f.maxItems&&(e=e.splice(0,f.maxItems)),angular.isDefined(f.valueName)&&(a[f.valueName]=e),d[d.resultProperty]=e,d.$broadcast("apiNG.resultMerged",{resultProperty:d.resultProperty})},this.apply=function(){d.$apply()}}]}}]),angular.module("jtt_aping").service("apingTimeHelper",function(){this.getTimestampFromDateString=function(a,b,c){if((angular.isUndefined(b)||isNaN(b))&&(b=1),(angular.isUndefined(c)||isNaN(c))&&(c=0),"string"==typeof a){var d=a.split(/[^0-9]/);try{return parseInt(Math.round(new Date(d[0],d[1]-1,d[2],d[3],d[4],d[5])/1e3*b)+c,10)}catch(e){return 0}}return 0}}).service("apingUtilityHelper",["apingInputObjects","apingDefaultSettings",function(a,b){this.getApiCredentials=function(a,c){return b.apingApiKeys&&b.apingApiKeys[a]?b.apingApiKeys[a][Math.floor(Math.random()*b.apingApiKeys[a].length)][c]:!1},this.parseJsonFromAttributes=function(a,b,c){return this.parseRequestsFromAttributes(a,b,c)},this.getDifference=function(a,b){return a>b?a-b:b-a},this.parseRequestsFromAttributes=function(b,c,d){if("string"!=typeof b||!b)return[];var e=[],f=this.replaceSingleQuotesAndParseJson(b);return angular.forEach(f,function(b,f){b.platform=c,d&&(angular.isUndefined(b.items)&&angular.isDefined(d.items)&&(b.items=d.items),angular.isUndefined(b.model)&&angular.isDefined(d.model)&&(b.model=d.model));var g=a.getNew("request",b);e.push(g)}),e},this.replaceSingleQuotesAndParseJson=function(a){return angular.fromJson(a.replace(/'/g,'"'))},this.sortArrayByProperty=function(a){var b=1;return"-"===a[0]&&(b=-1,a=a.substr(1)),function(c,d){var e=c[a]d[a]?1:0;return e*b}},this.shuffleArray=function(a){for(var b=a.length-1;b>0;b--){var c=Math.floor(Math.random()*(b+1)),d=a[b];a[b]=a[c],a[c]=d}return a},this.removeNullIn=function(a,b){var c=b[a];if(null===c||void 0===c)delete b[a];else if("object"==typeof c)for(var d in c)this.removeNullIn(d,c)},this.removeNull=function(a){for(var b in a)this.removeNullIn(b,a)},this.removeDuplicateObjectsFromArray=function(a,b,c){var d,e=[];d=c?"aping_id":"apingStringified";var f="apingTempOrder";if(1===a.length)return a;angular.forEach(a,function(a,g){c||(a.$$hashKey=void 0,a[d]=JSON.stringify(a)),b===!0&&(a[f]=g),e.push(a)}),e.sort(this.sortArrayByProperty(d));var g,h=[];return angular.forEach(e,function(a,b){angular.isDefined(g)?angular.isDefined(a[d])&&a[d]!==g&&h.push(a):h.push(a),g=a[d],c||(a[d]=void 0)}),b===!0&&(h.sort(this.sortArrayByProperty(f)),angular.forEach(h,function(a,b){a[f]=void 0})),h},this.mergeDuplicateObjectsFromArray=function(a,b){var c=this,d=[],e="aping_id",f="apingTempOrder";if(1===a.length)return a;angular.forEach(a,function(a,c){b===!0&&(a[f]=c),d.push(a)}),d.sort(this.sortArrayByProperty(e));var g,h=[];return angular.forEach(d,function(a,b){c.removeNull(a),angular.isDefined(g)?angular.isDefined(a[e])&&a[e]!==g?h.push(a):h[h.length-1]=angular.merge(h[h.length-1],h[h.length-1],a):h.push(a),g=a[e]}),b===!0&&(h.sort(this.sortArrayByProperty(f)),angular.forEach(h,function(a,b){a[f]=void 0})),h},this.getTextFromHtml=function(a){return a=a.replace(/<br ?\/\>|<br ?\/&rt;|\
/g," "),a=a.replace(/<(?:.|\n)*?>/gm,"")},this.getFirstImageFromHtml=function(a){var b=/]+src="([^">]+)/g;return b.exec(a)},this.parseParametersFromUrl=function(a){var b={};return"string"==typeof a&&(b=JSON.parse('{"'+decodeURI(a.replace(/&/g,'","').replace(/=/g,'":"'))+'"}')),b},this.createIdByPropertiesForArray=function(a,b,c){var d=this;return!angular.isUndefined(c)&&angular.isString(c)||(c="aping_id"),angular.isDefined(a)&&angular.isArray(a)&&angular.forEach(a,function(a,e){a[c]=d.getIdByPropertiesForObject(a,b)}),a},this.getIdByPropertiesForObject=function(a,b){var c=this,d="";if(angular.isDefined(a)&&angular.isObject(a)){var e=[];"["===b.substr(0,1)?e=this.replaceSingleQuotesAndParseJson(b):e.push(b),angular.forEach(e,function(b,e){d+=c.getValueFromObjectByPropertyString(a,b)})}return d},this.getValueFromObjectByPropertyString=function(a,b,c){var d="";if(angular.isDefined(a)&&angular.isObject(a)){var e=b.split("."),f=a;angular.forEach(e,function(a,b){angular.isDefined(f[a])&&(f=f[a])}),angular.isDefined(f)&&(d=c&&angular.isObject(f)?JSON.stringify(f):f)}return d}}]),angular.module("jtt_aping").service("apingInputObjects",["apingDefaultSettings",function(a){this.getNew=function(b,c){var d={};switch(b){case"request":d=angular.extend({model:a.model},c)}return d}}]),angular.module("jtt_aping").service("apingModels",[function(){this.getNew=function(a,b){var c={};switch(a){case"social":c={platform:b};break;case"video":c={platform:b};break;case"image":c={platform:b};break;case"event":c={platform:b};break;case"repo":c={platform:b};break;case"weather":c={platform:b}}return c}}]),angular.module("jtt_aping_jsonloader",[]).directive("apingJsonloader",["apingUtilityHelper","jsonloaderFactory",function(a,b){return{require:"?aping",restrict:"A",replace:"false",link:function(c,d,e,f){var g=f.getAppSettings(),h=a.parseJsonFromAttributes(e.apingJsonloader,"jsonloader",g);h.forEach(function(c){if(c.path){var d={path:c.path};if(c.format&&"jsonp"===c.format.toLowerCase()?d.format="jsonp":d.format="json",angular.isUndefined(c.items)&&(c.items=g.items),0===c.items||"0"===c.items)return!1;(c.items<0||isNaN(c.items))&&(c.items=void 0),angular.isDefined(c.orderBy)&&!angular.isString(c.orderBy)&&(c.orderBy=void 0),!angular.isDefined(c.orderReverse)||c.orderReverse!==!0&&"true"!==c.orderReverse||(c.orderReverse=!0),b.getJsonData(d).then(function(b){var d=[];if(b.data){var e=b.data;angular.isDefined(c.resultProperty)&&(e=a.getValueFromObjectByPropertyString(e,c.resultProperty,!1)),e.constructor!==Array?d.push(e):(angular.extend(d,e),angular.isDefined(c.orderBy)&&("$RANDOM"===c.orderBy?d=a.shuffleArray(d):d.sort(a.sortArrayByProperty(c.orderBy))),angular.isDefined(c.orderReverse)&&c.orderReverse===!0&&"$RANDOM"!==c.orderBy&&d.reverse(),angular.isUndefined(c.items)?d=e:c.items>0&&d.length>c.items&&(d=d.splice(0,c.items)))}f.concatToResults(d)})}})}}}]).factory("jsonloaderFactory",["$http",function(a){var b={};return b.getJsonData=function(b){var c={};return"jsonp"===b.format?a.jsonp(b.path,{method:"GET",params:{callback:"JSON_CALLBACK"}}):a({method:"GET",url:b.path,params:c})},b}]),angular.module("jtt_aping_ng_array",[]).directive("apingNgArray",["apingUtilityHelper",function(a){return{require:"?aping",restrict:"A",replace:"false",link:function(b,c,d,e){var f=e.getAppSettings(),g=a.parseJsonFromAttributes(d.apingNgArray,"ngArray",f);g.forEach(function(c){if(c.name&&b[c.name]){if(angular.isUndefined(c.items)&&(c.items=f.items),0===c.items||"0"===c.items)return!1;(c.items<0||isNaN(c.items))&&(c.items=void 0);var d=[];b[c.name].constructor===Array?(d=b[c.name],angular.isDefined(c.orderBy)&&("$RANDOM"===c.orderBy?d=a.shuffleArray(d):d.sort(a.sortArrayByProperty(c.orderBy))),angular.isDefined(c.orderReverse)&&c.orderReverse===!0&&"$RANDOM"!==c.orderBy&&d.reverse(),angular.isDefined(c.items)&&c.items>0&&d.length>c.items&&(d=d.splice(0,c.items))):"object"==typeof b[c.name]&&null!==b[c.name]&&d.push(b[c.name]),d.length>0&&e.concatToResults(d)}})}}}]),angular.module("jtt_aping_local_storage",[]).directive("apingLocalStorage",["apingUtilityHelper","apingLocalStorage",function(a,b){return{require:"?aping",restrict:"A",replace:"false",link:function(c,d,e,f){var g=f.getAppSettings(),h=a.parseJsonFromAttributes(e.apingLocalStorage,"localStorage",g);h.forEach(function(c){if(c.key){if(angular.isUndefined(c.items)&&(c.items=g.items),0===c.items||"0"===c.items)return!1;(c.items<0||isNaN(c.items))&&(c.items=void 0),angular.isDefined(c.orderBy)&&!angular.isString(c.orderBy)&&(c.orderBy=void 0),!angular.isDefined(c.orderReverse)||c.orderReverse!==!0&&"true"!==c.orderReverse||(c.orderReverse=!0),b.get(c.key).then(function(b){var d=[];if(b){var e=b;angular.isDefined(c.resultProperty)&&(e=a.getValueFromObjectByPropertyString(b,c.resultProperty,!1)),angular.isArray(b)?(d=e,angular.isDefined(c.orderBy)&&("$RANDOM"===c.orderBy?d=a.shuffleArray(d):d.sort(a.sortArrayByProperty(c.orderBy))),angular.isDefined(c.orderReverse)&&c.orderReverse===!0&&"$RANDOM"!==c.orderBy&&d.reverse(),angular.isUndefined(c.items)?d=e:c.items>0&&d.length>c.items&&(d=d.splice(0,c.items))):d.push(e)}f.concatToResults(d)})}})}}}]).factory("apingLocalStorage",["$window","$q",function(a,b){var c=function(c,d){var e=b.defer();return e.resolve(a.localStorage&&a.localStorage.setItem(c,angular.toJson(d))),e.promise},d=function(c){var d=b.defer();return d.resolve(a.localStorage&&angular.fromJson(a.localStorage.getItem(c))),d.promise};return{set:c,get:d}}]),angular.module("jtt_aping_xml",[]).directive("apingXml",["apingUtilityHelper","xmlFactory","xmlService",function(a,b,c){return{require:"?aping",restrict:"A",replace:"false",link:function(d,e,f,g){var h=g.getAppSettings(),i=a.parseJsonFromAttributes(f.apingXml,"xml",h);i.forEach(function(d){if(d.path){var e={path:d.path};if(angular.isUndefined(d.items)&&(d.items=h.items),0===d.items||"0"===d.items)return!1;(d.items<0||isNaN(d.items))&&(d.items=void 0),angular.isDefined(d.orderBy)&&!angular.isString(d.orderBy)&&(d.orderBy=void 0),!angular.isDefined(d.orderReverse)||d.orderReverse!==!0&&"true"!==d.orderReverse||(d.orderReverse=!0),b.getData(e).then(function(b){var e=[];if(b.data){var f=c.xml2json(b.data);angular.isDefined(d.resultProperty)&&(f=a.getValueFromObjectByPropertyString(f,d.resultProperty,!1)),f.constructor!==Array?e.push(f):(angular.extend(e,f),angular.isDefined(d.orderBy)&&("$RANDOM"===d.orderBy?e=a.shuffleArray(e):e.sort(a.sortArrayByProperty(d.orderBy))),angular.isDefined(d.orderReverse)&&d.orderReverse===!0&&"$RANDOM"!==d.orderBy&&e.reverse(),angular.isUndefined(d.items)?e=f:d.items>0&&e.length>d.items&&(e=e.splice(0,d.items)))}g.concatToResults(e)})}})}}}]).factory("xmlFactory",["$http",function(a){var b={};return b.getData=function(b){var c={};return a({method:"GET",url:b.path,params:c})},b}]).service("xmlService",function(){var a=this;this.cleanXML=function(b){return b=b.replace(/\n|\t|\r/g,""),b=b.replace(/ {1,}<|\t{1,} {1,}|>\t{1,}/g,">"),b=b.replace(/<\?[^>]*\?>/g,""),b=a.replaceSelfClosingTags(b),b=a.replaceAloneValues(b),b=a.replaceAttributes(b)},this.replaceSelfClosingTags=function(a){var b=a.match(/<[^\/][^>]*\/>/g);if(b)for(var c=0;c";var f=d.match(/[^<][\w+$]*/)[0],g="",h="<"+f+">",i=e.match(/(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?/g);if(i)for(var j=0;j"+m+""}h+=g,a=a.replace(d,h)}return a},this.replaceAloneValues=function(a){var b=a.match(/<[^\/][^>][^<]+\s+.[^<]+[=][^<]+>{1}([^<]+)/g);if(b)for(var c=0;c")+1),f=d.substring(d.indexOf(">")+1),g=e+"<_@ttribute>"+f+"";a=a.replace(d,g)}return a},this.replaceAttributes=function(a){var b=a.match(/<[^\/][^>][^<]+\s+.[^<]+[=][^<]+>/g);if(b)for(var c=0;c",g=d.match(/(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?/g);if(g)for(var h=0;h"+k+""}a=a.replace(d,f)}return a},this.xml2json=function(b){b=this.cleanXML(b);for(var c,d,e,f,g,h={};b.match(/<[^\/][^>]*>/);)g=b.match(/<[^\/][^>]*>/)[0],c=g.substring(1,g.length-1),d=b.indexOf(g.replace("<","]*>/)?a.xml2json(e):e,void 0===h[c]?h[c]=f:Array.isArray(h[c])?h[c].push(f):h[c]=[h[c],f],b=b.substring(2*g.length+1+e.length);return h}}); \ No newline at end of file +"use strict";angular.module("jtt_aping",["jtt_aping_jsonloader","jtt_aping_xml","jtt_aping_ng_array","jtt_aping_local_storage"]),angular.module("jtt_aping").config(["$provide",function(a){a.value("apingDefaultSettings",{apingApiKeys:{}})}]).value("apingResults",{}).directive("aping",["apingResults","apingDefaultSettings","apingUtilityHelper","$templateRequest","$compile",function(a,b,c,d,e){return{restrict:"E",transclude:!0,template:"",scope:{model:"@",getNativeData:"@",items:"@",maxItems:"@",orderBy:"@",orderReverse:"@",templateUrl:"@",payloadJson:"@",removeDoubles:"@",mergeDoubles:"@",idBy:"@",resultProperty:"@",resultName:"@",valueName:"@",protocol:"@"},link:function(a,c,f,g,h){function i(b){angular.isDefined(b)&&"$NONE"!==b?d(b).then(function(b){var d=angular.element(b);c.empty().append(d),e(d)(a)}):h(a,function(a,b){c.html(""),c.append(a),e(a)(b)}),a.$broadcast("apiNG.templateRendered")}var j=a.templateUrl;a.$watch("templateUrl",function(){i(a.templateUrl)}),angular.isUndefined(j)&&angular.isDefined(b.templateUrl)&&(j=b.templateUrl,i(j))},controller:["$scope",function(d){angular.isUndefined(d.resultName)&&(angular.isUndefined(d.resultProperty)?d.resultName="results":d.resultName=d.resultProperty),d[d.resultName]=[],d.payload=d.payloadJson?c.replaceSingleQuotesAndParseJson(d.payloadJson):{},this.getAppSettings=function(){var a,c,e,f,g,h,i,j,k,l;return j=angular.isDefined(d.valueName)?d.valueName:void 0,a=angular.isDefined(d.items)?d.items:angular.isDefined(b.items)?b.items:void 0,c=angular.isDefined(d.maxItems)?d.maxItems:angular.isDefined(b.maxItems)?b.maxItems:void 0,e=angular.isDefined(d.getNativeData)?d.getNativeData:angular.isDefined(b.getNativeData)?b.getNativeData:!1,c=angular.isDefined(d.maxItems)?d.maxItems:angular.isDefined(b.maxItems)?b.maxItems:void 0,g=angular.isDefined(d.orderBy)?d.orderBy:angular.isDefined(b.orderBy)?b.orderBy:void 0,f=angular.isDefined(d.orderReverse)?d.orderReverse:angular.isDefined(b.orderReverse)?b.orderReverse:!1,h=angular.isDefined(d.removeDoubles)?d.removeDoubles:angular.isDefined(b.removeDoubles)?b.removeDoubles:!1,i=angular.isDefined(d.mergeDoubles)?d.mergeDoubles:angular.isDefined(b.mergeDoubles)?b.mergeDoubles:!1,k=angular.isDefined(d.idBy)?d.idBy:angular.isDefined(b.idBy)?b.idBy:void 0,l=angular.isDefined(d.protocol)?d.protocol:angular.isDefined(b.protocol)?b.protocol:void 0,{model:d.model||b.model||"native",getNativeData:e,items:a,maxItems:c,orderBy:g,orderReverse:f,removeDoubles:h,mergeDoubles:i,idBy:k,valueName:j,protocol:l}},this.concatToResults=function(b){angular.isUndefined(d.resultName)&&(angular.isUndefined(d.resultProperty)?d.resultName="results":d.resultName=d.resultProperty);var e=d[d.resultName].concat(b),f=this.getAppSettings();angular.isDefined(f.idBy)&&(e=c.createIdByPropertiesForArray(e,f.idBy),f.mergeDoubles!==!0&&"true"!==f.mergeDoubles||(e=c.mergeDuplicateObjectsFromArray(e,f.orderBy===!1||"false"===f.orderBy||"$NONE"===f.orderBy))),f.removeDoubles!==!0&&"true"!==f.removeDoubles||f.mergeDoubles!==!0&&"true"!==f.mergeDoubles&&(e=c.removeDuplicateObjectsFromArray(e,f.orderBy===!1||"false"===f.orderBy||"$NONE"===f.orderBy,angular.isDefined(f.idBy))),angular.isDefined(f.orderBy)&&f.orderBy!==!1&&"false"!==f.orderBy&&"$NONE"!==f.orderBy&&("$RANDOM"===f.orderBy?e=c.shuffleArray(e):e.sort(c.sortArrayByProperty(f.orderBy))),f.orderReverse!==!0&&"true"!==f.orderReverse||"$RANDOM"===f.orderBy||e.reverse(),f.maxItems>-1&&e.length>f.maxItems&&(e=e.splice(0,f.maxItems)),angular.isDefined(f.valueName)&&(a[f.valueName]=e),d[d.resultName]=e,d.$broadcast("apiNG.resultMerged",{resultName:d.resultName})},this.apply=function(){d.$apply()}}]}}]),angular.module("jtt_aping").service("apingTimeHelper",function(){this.getTimestampFromDateString=function(a,b,c){if((angular.isUndefined(b)||isNaN(b))&&(b=1),(angular.isUndefined(c)||isNaN(c))&&(c=0),"string"==typeof a){var d=a.split(/[^0-9]/);try{return parseInt(Math.round(new Date(d[0],d[1]-1,d[2],d[3],d[4],d[5])/1e3*b)+c,10)}catch(e){return 0}}return 0}}).service("apingUtilityHelper",["apingInputObjects","apingDefaultSettings",function(a,b){this.getApiCredentials=function(a,c){return b.apingApiKeys&&b.apingApiKeys[a]?b.apingApiKeys[a][Math.floor(Math.random()*b.apingApiKeys[a].length)][c]:!1},this.parseJsonFromAttributes=function(a,b,c){return this.parseRequestsFromAttributes(a,b,c)},this.getDifference=function(a,b){return a>b?a-b:b-a},this.parseRequestsFromAttributes=function(b,c,d){if("string"!=typeof b||!b)return[];var e=[],f=this.replaceSingleQuotesAndParseJson(b);return angular.forEach(f,function(b,f){b.platform=c,d&&(angular.isUndefined(b.items)&&angular.isDefined(d.items)&&(b.items=d.items),angular.isUndefined(b.model)&&angular.isDefined(d.model)&&(b.model=d.model));var g=a.getNew("request",b);e.push(g)}),e},this.replaceSingleQuotesAndParseJson=function(a){return angular.fromJson(a.replace(/'/g,'"'))},this.sortArrayByProperty=function(a){var b=1;return"-"===a[0]&&(b=-1,a=a.substr(1)),function(c,d){var e=c[a]d[a]?1:0;return e*b}},this.shuffleArray=function(a){for(var b=a.length-1;b>0;b--){var c=Math.floor(Math.random()*(b+1)),d=a[b];a[b]=a[c],a[c]=d}return a},this.removeNullIn=function(a,b){var c=b[a];if(null===c||void 0===c)delete b[a];else if("object"==typeof c)for(var d in c)this.removeNullIn(d,c)},this.removeNull=function(a){for(var b in a)this.removeNullIn(b,a)},this.removeDuplicateObjectsFromArray=function(a,b,c){var d,e=[];d=c?"aping_id":"apingStringified";var f="apingTempOrder";if(1===a.length)return a;angular.forEach(a,function(a,g){c||(a.$$hashKey=void 0,a[d]=JSON.stringify(a)),b===!0&&(a[f]=g),e.push(a)}),e.sort(this.sortArrayByProperty(d));var g,h=[];return angular.forEach(e,function(a,b){angular.isDefined(g)?angular.isDefined(a[d])&&a[d]!==g&&h.push(a):h.push(a),g=a[d],c||(a[d]=void 0)}),b===!0&&(h.sort(this.sortArrayByProperty(f)),angular.forEach(h,function(a,b){a[f]=void 0})),h},this.mergeDuplicateObjectsFromArray=function(a,b){var c=this,d=[],e="aping_id",f="apingTempOrder";if(1===a.length)return a;angular.forEach(a,function(a,c){b===!0&&(a[f]=c),d.push(a)}),d.sort(this.sortArrayByProperty(e));var g,h=[];return angular.forEach(d,function(a,b){c.removeNull(a),angular.isDefined(g)?angular.isDefined(a[e])&&a[e]!==g?h.push(a):h[h.length-1]=angular.merge(h[h.length-1],h[h.length-1],a):h.push(a),g=a[e]}),b===!0&&(h.sort(this.sortArrayByProperty(f)),angular.forEach(h,function(a,b){a[f]=void 0})),h},this.getTextFromHtml=function(a){return a=a.replace(/<br ?\/\>|<br ?\/&rt;|\
/g," "),a=a.replace(/<(?:.|\n)*?>/gm,"")},this.getFirstImageFromHtml=function(a){var b=/]+src="([^">]+)/g;return b.exec(a)},this.parseParametersFromUrl=function(a){var b={};return"string"==typeof a&&(b=JSON.parse('{"'+decodeURI(a.replace(/&/g,'","').replace(/=/g,'":"'))+'"}')),b},this.createIdByPropertiesForArray=function(a,b,c){var d=this;return!angular.isUndefined(c)&&angular.isString(c)||(c="aping_id"),angular.isDefined(a)&&angular.isArray(a)&&angular.forEach(a,function(a,e){a[c]=d.getIdByPropertiesForObject(a,b)}),a},this.getIdByPropertiesForObject=function(a,b){var c=this,d="";if(angular.isDefined(a)&&angular.isObject(a)){var e=[];"["===b.substr(0,1)?e=this.replaceSingleQuotesAndParseJson(b):e.push(b),angular.forEach(e,function(b,e){d+=c.getValueFromObjectByPropertyString(a,b)})}return d},this.getValueFromObjectByPropertyString=function(a,b,c){var d="";if(angular.isDefined(a)&&angular.isObject(a)){var e=b.split("."),f=a;angular.forEach(e,function(a,b){angular.isDefined(f[a])&&(f=f[a])}),angular.isDefined(f)&&(d=c&&angular.isObject(f)?JSON.stringify(f):f)}return d}}]),angular.module("jtt_aping").service("apingInputObjects",["apingDefaultSettings",function(a){this.getNew=function(b,c){var d={};switch(b){case"request":d=angular.extend({model:a.model},c)}return d}}]),angular.module("jtt_aping").service("apingModels",[function(){this.getNew=function(a,b){var c={};switch(a){case"social":c={platform:b};break;case"video":c={platform:b};break;case"image":c={platform:b};break;case"event":c={platform:b};break;case"repo":c={platform:b};break;case"weather":c={platform:b}}return c}}]),angular.module("jtt_aping_jsonloader",[]).directive("apingJsonloader",["apingUtilityHelper","jsonloaderFactory",function(a,b){return{require:"?aping",restrict:"A",replace:"false",link:function(c,d,e,f){var g=f.getAppSettings(),h=a.parseJsonFromAttributes(e.apingJsonloader,"jsonloader",g);h.forEach(function(c){if(c.path){var d={path:c.path};if(c.format&&"jsonp"===c.format.toLowerCase()?d.format="jsonp":d.format="json",angular.isUndefined(c.items)&&(c.items=g.items),0===c.items||"0"===c.items)return!1;(c.items<0||isNaN(c.items))&&(c.items=void 0),angular.isDefined(c.orderBy)&&!angular.isString(c.orderBy)&&(c.orderBy=void 0),!angular.isDefined(c.orderReverse)||c.orderReverse!==!0&&"true"!==c.orderReverse||(c.orderReverse=!0),b.getJsonData(d).then(function(b){var d=[];if(b.data){var e=b.data;angular.isDefined(c.resultProperty)&&(e=a.getValueFromObjectByPropertyString(e,c.resultProperty,!1)),e.constructor!==Array?d.push(e):(angular.extend(d,e),angular.isDefined(c.orderBy)&&("$RANDOM"===c.orderBy?d=a.shuffleArray(d):d.sort(a.sortArrayByProperty(c.orderBy))),angular.isDefined(c.orderReverse)&&c.orderReverse===!0&&"$RANDOM"!==c.orderBy&&d.reverse(),angular.isUndefined(c.items)?d=e:c.items>0&&d.length>c.items&&(d=d.splice(0,c.items)))}f.concatToResults(d)})}})}}}]).factory("jsonloaderFactory",["$http",function(a){var b={};return b.getJsonData=function(b){var c={};return"jsonp"===b.format?a.jsonp(b.path,{method:"GET",params:{callback:"JSON_CALLBACK"}}):a({method:"GET",url:b.path,params:c})},b}]),angular.module("jtt_aping_ng_array",[]).directive("apingNgArray",["apingUtilityHelper",function(a){return{require:"?aping",restrict:"A",replace:"false",link:function(b,c,d,e){var f=e.getAppSettings(),g=a.parseJsonFromAttributes(d.apingNgArray,"ngArray",f);g.forEach(function(c){if(c.name&&b[c.name]){if(angular.isUndefined(c.items)&&(c.items=f.items),0===c.items||"0"===c.items)return!1;(c.items<0||isNaN(c.items))&&(c.items=void 0);var d=[];b[c.name].constructor===Array?(d=b[c.name],angular.isDefined(c.orderBy)&&("$RANDOM"===c.orderBy?d=a.shuffleArray(d):d.sort(a.sortArrayByProperty(c.orderBy))),angular.isDefined(c.orderReverse)&&c.orderReverse===!0&&"$RANDOM"!==c.orderBy&&d.reverse(),angular.isDefined(c.items)&&c.items>0&&d.length>c.items&&(d=d.splice(0,c.items))):"object"==typeof b[c.name]&&null!==b[c.name]&&d.push(b[c.name]),d.length>0&&e.concatToResults(d)}})}}}]),angular.module("jtt_aping_local_storage",[]).directive("apingLocalStorage",["apingUtilityHelper","apingLocalStorage",function(a,b){return{require:"?aping",restrict:"A",replace:"false",link:function(c,d,e,f){var g=f.getAppSettings(),h=a.parseJsonFromAttributes(e.apingLocalStorage,"localStorage",g);h.forEach(function(c){if(c.key){if(angular.isUndefined(c.items)&&(c.items=g.items),0===c.items||"0"===c.items)return!1;(c.items<0||isNaN(c.items))&&(c.items=void 0),angular.isDefined(c.orderBy)&&!angular.isString(c.orderBy)&&(c.orderBy=void 0),!angular.isDefined(c.orderReverse)||c.orderReverse!==!0&&"true"!==c.orderReverse||(c.orderReverse=!0),b.get(c.key).then(function(b){var d=[];if(b){var e=b;angular.isDefined(c.resultProperty)&&(e=a.getValueFromObjectByPropertyString(b,c.resultProperty,!1)),angular.isArray(b)?(d=e,angular.isDefined(c.orderBy)&&("$RANDOM"===c.orderBy?d=a.shuffleArray(d):d.sort(a.sortArrayByProperty(c.orderBy))),angular.isDefined(c.orderReverse)&&c.orderReverse===!0&&"$RANDOM"!==c.orderBy&&d.reverse(),angular.isUndefined(c.items)?d=e:c.items>0&&d.length>c.items&&(d=d.splice(0,c.items))):d.push(e)}f.concatToResults(d)})}})}}}]).factory("apingLocalStorage",["$window","$q",function(a,b){var c=function(c,d){var e=b.defer();return e.resolve(a.localStorage&&a.localStorage.setItem(c,angular.toJson(d))),e.promise},d=function(c){var d=b.defer();return d.resolve(a.localStorage&&angular.fromJson(a.localStorage.getItem(c))),d.promise};return{set:c,get:d}}]),angular.module("jtt_aping_xml",[]).directive("apingXml",["apingUtilityHelper","xmlFactory","xmlService",function(a,b,c){return{require:"?aping",restrict:"A",replace:"false",link:function(d,e,f,g){var h=g.getAppSettings(),i=a.parseJsonFromAttributes(f.apingXml,"xml",h);i.forEach(function(d){if(d.path){var e={path:d.path};if(angular.isUndefined(d.items)&&(d.items=h.items),0===d.items||"0"===d.items)return!1;(d.items<0||isNaN(d.items))&&(d.items=void 0),angular.isDefined(d.orderBy)&&!angular.isString(d.orderBy)&&(d.orderBy=void 0),!angular.isDefined(d.orderReverse)||d.orderReverse!==!0&&"true"!==d.orderReverse||(d.orderReverse=!0),b.getData(e).then(function(b){var e=[];if(b.data){var f=c.xml2json(b.data);angular.isDefined(d.resultProperty)&&(f=a.getValueFromObjectByPropertyString(f,d.resultProperty,!1)),f.constructor!==Array?e.push(f):(angular.extend(e,f),angular.isDefined(d.orderBy)&&("$RANDOM"===d.orderBy?e=a.shuffleArray(e):e.sort(a.sortArrayByProperty(d.orderBy))),angular.isDefined(d.orderReverse)&&d.orderReverse===!0&&"$RANDOM"!==d.orderBy&&e.reverse(),angular.isUndefined(d.items)?e=f:d.items>0&&e.length>d.items&&(e=e.splice(0,d.items)))}g.concatToResults(e)})}})}}}]).factory("xmlFactory",["$http",function(a){var b={};return b.getData=function(b){var c={};return a({method:"GET",url:b.path,params:c})},b}]).service("xmlService",function(){var a=this;this.cleanXML=function(b){return b=b.replace(/\n|\t|\r/g,""),b=b.replace(/ {1,}<|\t{1,} {1,}|>\t{1,}/g,">"),b=b.replace(/<\?[^>]*\?>/g,""),b=a.replaceSelfClosingTags(b),b=a.replaceAloneValues(b),b=a.replaceAttributes(b)},this.replaceSelfClosingTags=function(a){var b=a.match(/<[^\/][^>]*\/>/g);if(b)for(var c=0;c";var f=d.match(/[^<][\w+$]*/)[0],g="",h="<"+f+">",i=e.match(/(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?/g);if(i)for(var j=0;j"+m+""}h+=g,a=a.replace(d,h)}return a},this.replaceAloneValues=function(a){var b=a.match(/<[^\/][^>][^<]+\s+.[^<]+[=][^<]+>{1}([^<]+)/g);if(b)for(var c=0;c")+1),f=d.substring(d.indexOf(">")+1),g=e+"<_@ttribute>"+f+"";a=a.replace(d,g)}return a},this.replaceAttributes=function(a){var b=a.match(/<[^\/][^>][^<]+\s+.[^<]+[=][^<]+>/g);if(b)for(var c=0;c",g=d.match(/(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?/g);if(g)for(var h=0;h"+k+""}a=a.replace(d,f)}return a},this.xml2json=function(b){b=this.cleanXML(b);for(var c,d,e,f,g,h={};b.match(/<[^\/][^>]*>/);)g=b.match(/<[^\/][^>]*>/)[0],c=g.substring(1,g.length-1),d=b.indexOf(g.replace("<","]*>/)?a.xml2json(e):e,void 0===h[c]?h[c]=f:Array.isArray(h[c])?h[c].push(f):h[c]=[h[c],f],b=b.substring(2*g.length+1+e.length);return h}}); \ No newline at end of file diff --git a/package.json b/package.json index 3832103..9b74136 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aping", - "version": "1.3.0", + "version": "1.3.1", "description": "apiNG is an AngularJS directive that enables you to receive, aggregate, limit, order and display data from one or more sources. The complete setup is dead simple, just by adding data-attributes to your html", "main": "dist/aping.min.js", "scripts": {