diff --git a/bower.json b/bower.json index 45523d1..51472bf 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "apiNG", - "version": "1.0.4", + "version": "1.0.5", "homepage": "https://github.com/JohnnyTheTank/apiNG", "authors": [ "Jonathan Hornung " diff --git a/demo/index.html b/demo/index.html index a0c5852..3b6eba3 100644 --- a/demo/index.html +++ b/demo/index.html @@ -20,15 +20,15 @@ @@ -36,16 +36,15 @@

Unstyled, one result

- + +
{{results | json}}

Styled, but two results

+ template-url="template.html" + aping-jsonloader="[{ 'path': 'https://randomuser.me/api/' }, { 'path': 'https://randomuser.me/api/' }]">

diff --git a/demo/unstyled_template.html b/demo/unstyled_template.html deleted file mode 100644 index aec03b6..0000000 --- a/demo/unstyled_template.html +++ /dev/null @@ -1,3 +0,0 @@ -
-
{{results | json}}
-
\ No newline at end of file diff --git a/dist/aping.js b/dist/aping.js index 2482e30..89a483e 100644 --- a/dist/aping.js +++ b/dist/aping.js @@ -1,6 +1,6 @@ /** @name: aping - @version: 1.0.4 (23-01-2016) + @version: 1.0.5 (24-01-2016) @author: Jonathan Hornung @url: https://github.com/JohnnyTheTank/apiNG @license: MIT @@ -36,11 +36,28 @@ angular.module('jtt_aping') valueName: '@' }, link: function (scope, element, attrs) { - $templateRequest(scope.templateUrl || apingDefaultSettings.templateUrl).then(function (html) { - var template = angular.element(html); - element.append(template); - $compile(template)(scope); - }); + + var templatePath = scope.templateUrl || undefined; + if (angular.isUndefined(templatePath)) { + if (angular.isDefined(apingDefaultSettings.templateUrl)) { + templatePath = apingDefaultSettings.templateUrl; + } + } + + if (angular.isDefined(templatePath) && templatePath !== "$NONE") { + $templateRequest(templatePath).then(function (html) { + var template = angular.element(html); + element.append(template); + $compile(template)(scope); + }); + } else { + var html = element.html(); + html = html.replace(/\[\[(\w+)\]\]/g, function (_, text) { + return ''; + }); + element.html(html); + $compile(element.contents())(scope); + } }, controller: ['$scope', function ($scope) { $scope.results = []; @@ -170,7 +187,7 @@ angular.module('jtt_aping') $scope.results = $scope.results.splice(0, appSettings.maxItems); } - if(angular.isDefined(appSettings.valueName)) { + if (angular.isDefined(appSettings.valueName)) { apingResults[appSettings.valueName] = $scope.results; } diff --git a/dist/aping.min.js b/dist/aping.min.js index 37b5bf4..e1f6e27 100644 --- a/dist/aping.min.js +++ b/dist/aping.min.js @@ -1,8 +1,8 @@ /** @name: aping - @version: 1.0.4 (23-01-2016) + @version: 1.0.5 (24-01-2016) @author: Jonathan Hornung @url: https://github.com/JohnnyTheTank/apiNG @license: MIT */ -"use strict";angular.module("jtt_aping",["jtt_aping_jsonloader","jtt_aping_ng_array"]),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",replace:"false",scope:{model:"@",getNativeData:"@",items:"@",maxItems:"@",orderBy:"@",orderReverse:"@",templateUrl:"@",payloadJson:"@",removeDoubles:"@",valueName:"@"},link:function(a,c,f){d(a.templateUrl||b.templateUrl).then(function(b){var d=angular.element(b);c.append(d),e(d)(a)})},controller:["$scope",function(d){d.results=[],d.payload=d.payloadJson?c.replaceSingleQuotesAndParseJson(d.payloadJson):{},this.getAppSettings=function(){var a,c,e,f,g,h,i;return i=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,{model:d.model||b.model||"native",getNativeData:e,items:a,maxItems:c,orderBy:g,orderReverse:f,removeDoubles:h,valueName:i}},this.concatToResults=function(b){d.results=d.results.concat(b);var e=this.getAppSettings();(e.removeDoubles===!0||"true"===e.removeDoubles)&&(d.results=c.removeDuplicateObjectsFromArray(d.results,e.orderBy===!1||"false"===e.orderBy||"$NONE"===e.orderBy)),angular.isDefined(e.orderBy)&&e.orderBy!==!1&&"false"!==e.orderBy&&"$NONE"!==e.orderBy&&("$RANDOM"===e.orderBy?d.results=c.shuffleArray(d.results):(d.results.sort(c.sortArrayByProperty(e.orderBy)),(e.orderReverse===!0||"true"===e.orderReverse)&&d.results.reverse())),e.maxItems>-1&&d.results.length>e.maxItems&&(d.results=d.results.splice(0,e.maxItems)),angular.isDefined(e.valueName)&&(a[e.valueName]=d.results),d.$broadcast("apiNG.resultMerged")},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.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 $.parseJSON(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.removeDuplicateObjectsFromArray=function(a,b){var c=[],d="apingStringified",e="apingTempOrder";if(1===a.length)return a;$.each(a,function(a,f){f.$$hashKey=void 0,f[d]=JSON.stringify(f),b===!0&&(f[e]=a),c.push(f)}),c.sort(this.sortArrayByProperty(d));var f,g=[];return $.each(c,function(a,b){angular.isDefined(f)?angular.isDefined(b[d])&&b[d]!==f&&g.push(b):g.push(b),f=b[d],b[d]=void 0}),b===!0&&(c.sort(this.sortArrayByProperty(e)),$.each(c,function(a,b){b[e]=void 0})),g},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}}]),angular.module("jtt_aping").service("apingInputObjects",["apingDefaultSettings",function(a){this.getNew=function(b,c){var d={};switch(b){case"request":d=$.extend(!0,{model:a.model,items:a.items},c)}return d}}]),angular.module("jtt_aping").service("apingModels",[function(){this.getNew=function(a,b){var c={};switch(a){case"social":c={platform:b,blog_name:void 0,blog_id:void 0,blog_link:void 0,type:void 0,timestamp:void 0,date_time:void 0,post_url:void 0,intern_id:void 0,text:void 0,caption:void 0,img_url:void 0,source:void 0,likes:void 0,shares:void 0,comments:void 0,position:void 0};break;case"video":c={platform:void 0,blog_name:void 0,blog_id:void 0,blog_link:void 0,timestamp:void 0,date_time:void 0,post_url:void 0,intern_id:void 0,caption:void 0,text:void 0,img_url:void 0,source:void 0,markup:void 0,duration:void 0,width:void 0,height:void 0,comments:void 0,likes:void 0,shares:void 0,position:void 0};break;case"image":c={platform:b,blog_name:void 0,blog_id:void 0,blog_link:void 0,timestamp:void 0,date_time:void 0,post_url:void 0,intern_id:void 0,text:void 0,caption:void 0,thumb_url:void 0,thumb_width:void 0,thumb_height:void 0,img_url:void 0,img_width:void 0,img_height:void 0,native_url:void 0,native_width:void 0,native_height:void 0,source:void 0,likes:void 0,shares:void 0,comments:void 0,position:void 0};break;case"event":c={platform:b,artist_name:void 0,artist_id:void 0,artist_link:void 0,start_timestamp:void 0,start_date_time:void 0,end_timestamp:void 0,end_date_time:void 0,event_url:void 0,ticket_url:void 0,sold_out:void 0,intern_id:void 0,text:void 0,caption:void 0,img_url:void 0,place_name:void 0,city:void 0,country:void 0,latitude:void 0,longitude:void 0,street:void 0,zip:void 0,source:void 0};break;case"repo":c={platform:b,owner_name:void 0,owner_id:void 0,owner_link:void 0,owner_img_url:void 0,name:void 0,id:void 0,fullname:void 0,description:void 0,url:void 0,homepage:void 0,language:void 0,clone_url:void 0,git_url:void 0,ssh_url:void 0,svn_url:void 0,isFork:void 0,openIssues:void 0,watchers:void 0,stargazers:void 0,forks:void 0,created_timestamp:void 0,created_date_time:void 0,updated_timestamp:void 0,updated_date_time:void 0,pushed_timestamp:void 0,pushed_date_time:void 0};break;case"activity":c={platform:b,body:void 0,actor_name:void 0,actor_id:void 0,actor_url:void 0,actor_img_url:void 0,actor_type:void 0,action_name:void 0,action_message:void 0,action_id:void 0,action_url:void 0,action_img:void 0,action_type:void 0,object_name:void 0,object_id:void 0,object_img:void 0,object_url:void 0,object_type:void 0,context:void 0,timestamp:void 0,date_time:void 0};break;case"weather":c={platform:b,weather_code:void 0,weather_caption:void 0,weather_text:void 0,weather_icon_name:void 0,weather_icon_url:void 0,temp:void 0,pressure:void 0,humidity:void 0,temp_min:void 0,temp_max:void 0,sea_level:void 0,grnd_level:void 0,wind_speed:void 0,wind_deg:void 0,rain_duration:void 0,rain_volume:void 0,clouds:void 0,timestamp:void 0,date_time:void 0,sunrise_timestamp:void 0,sunrise_date_time:void 0,sunset_timestamp:void 0,sunset_date_time:void 0,loc_city:void 0,loc_city_id:void 0,loc_country:void 0,loc_lat:void 0,loc_lng:void 0,loc_zip:void 0}}return c}}]),angular.module("jtt_aping_jsonloader",[]),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(a){if(a.path){var c={path:a.path};if(a.format&&"jsonp"===a.format.toLowerCase()?c.format="jsonp":c.format="json",a.callback&&(c.callback=a.callback),"jsonp"!==a.format||a.callback||(c.callback="JSON_CALLBACK"),angular.isDefined(a.items)?c.count=a.items:c.count=g.items,0===c.count||"0"===c.count)return!1;(c.count<0||isNaN(c.count))&&(c.count=void 0),b.getJsonData(c).then(function(b){var c=[];if(b.data){var d=b.data;angular.isDefined(a.resultProperty)&&(d=b.data[a.resultProperty]),b.data.constructor!==Array?c.push(d):a.items<0||angular.isDefined(a.items)?c=d:angular.forEach(d,function(b,d){d0&&e.concatToResults(d)}})}}}]); \ No newline at end of file +"use strict";angular.module("jtt_aping",["jtt_aping_jsonloader","jtt_aping_ng_array"]),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",replace:"false",scope:{model:"@",getNativeData:"@",items:"@",maxItems:"@",orderBy:"@",orderReverse:"@",templateUrl:"@",payloadJson:"@",removeDoubles:"@",valueName:"@"},link:function(a,c,f){var g=a.templateUrl||void 0;if(angular.isUndefined(g)&&angular.isDefined(b.templateUrl)&&(g=b.templateUrl),angular.isDefined(g)&&"$NONE"!==g)d(g).then(function(b){var d=angular.element(b);c.append(d),e(d)(a)});else{var h=c.html();h=h.replace(/\[\[(\w+)\]\]/g,function(a,b){return''}),c.html(h),e(c.contents())(a)}},controller:["$scope",function(d){d.results=[],d.payload=d.payloadJson?c.replaceSingleQuotesAndParseJson(d.payloadJson):{},this.getAppSettings=function(){var a,c,e,f,g,h,i;return i=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,{model:d.model||b.model||"native",getNativeData:e,items:a,maxItems:c,orderBy:g,orderReverse:f,removeDoubles:h,valueName:i}},this.concatToResults=function(b){d.results=d.results.concat(b);var e=this.getAppSettings();(e.removeDoubles===!0||"true"===e.removeDoubles)&&(d.results=c.removeDuplicateObjectsFromArray(d.results,e.orderBy===!1||"false"===e.orderBy||"$NONE"===e.orderBy)),angular.isDefined(e.orderBy)&&e.orderBy!==!1&&"false"!==e.orderBy&&"$NONE"!==e.orderBy&&("$RANDOM"===e.orderBy?d.results=c.shuffleArray(d.results):(d.results.sort(c.sortArrayByProperty(e.orderBy)),(e.orderReverse===!0||"true"===e.orderReverse)&&d.results.reverse())),e.maxItems>-1&&d.results.length>e.maxItems&&(d.results=d.results.splice(0,e.maxItems)),angular.isDefined(e.valueName)&&(a[e.valueName]=d.results),d.$broadcast("apiNG.resultMerged")},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.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 $.parseJSON(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.removeDuplicateObjectsFromArray=function(a,b){var c=[],d="apingStringified",e="apingTempOrder";if(1===a.length)return a;$.each(a,function(a,f){f.$$hashKey=void 0,f[d]=JSON.stringify(f),b===!0&&(f[e]=a),c.push(f)}),c.sort(this.sortArrayByProperty(d));var f,g=[];return $.each(c,function(a,b){angular.isDefined(f)?angular.isDefined(b[d])&&b[d]!==f&&g.push(b):g.push(b),f=b[d],b[d]=void 0}),b===!0&&(c.sort(this.sortArrayByProperty(e)),$.each(c,function(a,b){b[e]=void 0})),g},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}}]),angular.module("jtt_aping").service("apingInputObjects",["apingDefaultSettings",function(a){this.getNew=function(b,c){var d={};switch(b){case"request":d=$.extend(!0,{model:a.model,items:a.items},c)}return d}}]),angular.module("jtt_aping").service("apingModels",[function(){this.getNew=function(a,b){var c={};switch(a){case"social":c={platform:b,blog_name:void 0,blog_id:void 0,blog_link:void 0,type:void 0,timestamp:void 0,date_time:void 0,post_url:void 0,intern_id:void 0,text:void 0,caption:void 0,img_url:void 0,source:void 0,likes:void 0,shares:void 0,comments:void 0,position:void 0};break;case"video":c={platform:void 0,blog_name:void 0,blog_id:void 0,blog_link:void 0,timestamp:void 0,date_time:void 0,post_url:void 0,intern_id:void 0,caption:void 0,text:void 0,img_url:void 0,source:void 0,markup:void 0,duration:void 0,width:void 0,height:void 0,comments:void 0,likes:void 0,shares:void 0,position:void 0};break;case"image":c={platform:b,blog_name:void 0,blog_id:void 0,blog_link:void 0,timestamp:void 0,date_time:void 0,post_url:void 0,intern_id:void 0,text:void 0,caption:void 0,thumb_url:void 0,thumb_width:void 0,thumb_height:void 0,img_url:void 0,img_width:void 0,img_height:void 0,native_url:void 0,native_width:void 0,native_height:void 0,source:void 0,likes:void 0,shares:void 0,comments:void 0,position:void 0};break;case"event":c={platform:b,artist_name:void 0,artist_id:void 0,artist_link:void 0,start_timestamp:void 0,start_date_time:void 0,end_timestamp:void 0,end_date_time:void 0,event_url:void 0,ticket_url:void 0,sold_out:void 0,intern_id:void 0,text:void 0,caption:void 0,img_url:void 0,place_name:void 0,city:void 0,country:void 0,latitude:void 0,longitude:void 0,street:void 0,zip:void 0,source:void 0};break;case"repo":c={platform:b,owner_name:void 0,owner_id:void 0,owner_link:void 0,owner_img_url:void 0,name:void 0,id:void 0,fullname:void 0,description:void 0,url:void 0,homepage:void 0,language:void 0,clone_url:void 0,git_url:void 0,ssh_url:void 0,svn_url:void 0,isFork:void 0,openIssues:void 0,watchers:void 0,stargazers:void 0,forks:void 0,created_timestamp:void 0,created_date_time:void 0,updated_timestamp:void 0,updated_date_time:void 0,pushed_timestamp:void 0,pushed_date_time:void 0};break;case"activity":c={platform:b,body:void 0,actor_name:void 0,actor_id:void 0,actor_url:void 0,actor_img_url:void 0,actor_type:void 0,action_name:void 0,action_message:void 0,action_id:void 0,action_url:void 0,action_img:void 0,action_type:void 0,object_name:void 0,object_id:void 0,object_img:void 0,object_url:void 0,object_type:void 0,context:void 0,timestamp:void 0,date_time:void 0};break;case"weather":c={platform:b,weather_code:void 0,weather_caption:void 0,weather_text:void 0,weather_icon_name:void 0,weather_icon_url:void 0,temp:void 0,pressure:void 0,humidity:void 0,temp_min:void 0,temp_max:void 0,sea_level:void 0,grnd_level:void 0,wind_speed:void 0,wind_deg:void 0,rain_duration:void 0,rain_volume:void 0,clouds:void 0,timestamp:void 0,date_time:void 0,sunrise_timestamp:void 0,sunrise_date_time:void 0,sunset_timestamp:void 0,sunset_date_time:void 0,loc_city:void 0,loc_city_id:void 0,loc_country:void 0,loc_lat:void 0,loc_lng:void 0,loc_zip:void 0}}return c}}]),angular.module("jtt_aping_jsonloader",[]),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(a){if(a.path){var c={path:a.path};if(a.format&&"jsonp"===a.format.toLowerCase()?c.format="jsonp":c.format="json",a.callback&&(c.callback=a.callback),"jsonp"!==a.format||a.callback||(c.callback="JSON_CALLBACK"),angular.isDefined(a.items)?c.count=a.items:c.count=g.items,0===c.count||"0"===c.count)return!1;(c.count<0||isNaN(c.count))&&(c.count=void 0),b.getJsonData(c).then(function(b){var c=[];if(b.data){var d=b.data;angular.isDefined(a.resultProperty)&&(d=b.data[a.resultProperty]),b.data.constructor!==Array?c.push(d):a.items<0||angular.isDefined(a.items)?c=d:angular.forEach(d,function(b,d){d0&&e.concatToResults(d)}})}}}]); \ No newline at end of file diff --git a/package.json b/package.json index 92c2eb9..701f58d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aping", - "version": "1.0.4", + "version": "1.0.5", "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": { diff --git a/src/aping-directive.js b/src/aping-directive.js index 08ae12a..da7b0a3 100644 --- a/src/aping-directive.js +++ b/src/aping-directive.js @@ -26,11 +26,28 @@ angular.module('jtt_aping') valueName: '@' }, link: function (scope, element, attrs) { - $templateRequest(scope.templateUrl || apingDefaultSettings.templateUrl).then(function (html) { - var template = angular.element(html); - element.append(template); - $compile(template)(scope); - }); + + var templatePath = scope.templateUrl || undefined; + if (angular.isUndefined(templatePath)) { + if (angular.isDefined(apingDefaultSettings.templateUrl)) { + templatePath = apingDefaultSettings.templateUrl; + } + } + + if (angular.isDefined(templatePath) && templatePath !== "$NONE") { + $templateRequest(templatePath).then(function (html) { + var template = angular.element(html); + element.append(template); + $compile(template)(scope); + }); + } else { + var html = element.html(); + html = html.replace(/\[\[(\w+)\]\]/g, function (_, text) { + return ''; + }); + element.html(html); + $compile(element.contents())(scope); + } }, controller: ['$scope', function ($scope) { $scope.results = []; @@ -160,7 +177,7 @@ angular.module('jtt_aping') $scope.results = $scope.results.splice(0, appSettings.maxItems); } - if(angular.isDefined(appSettings.valueName)) { + if (angular.isDefined(appSettings.valueName)) { apingResults[appSettings.valueName] = $scope.results; }