From f719a5ec890da9c1fa3ac8162ef7646482808ced Mon Sep 17 00:00:00 2001 From: Jonathan Hornung Date: Wed, 20 Jan 2016 11:46:12 +0100 Subject: [PATCH] feature: change template behaviour to allow angular expressions as template-url (close #67) --- bower.json | 2 +- dist/aping.js | 18 ++++++++++-------- dist/aping.min.js | 4 ++-- package.json | 2 +- src/aping-directive.js | 16 +++++++++------- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/bower.json b/bower.json index 4c7a762..86a0eca 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "apiNG", - "version": "1.0.1", + "version": "1.0.2", "homepage": "https://github.com/JohnnyTheTank/apiNG", "authors": [ "Jonathan Hornung " diff --git a/dist/aping.js b/dist/aping.js index 15397b6..d59f31e 100644 --- a/dist/aping.js +++ b/dist/aping.js @@ -1,6 +1,6 @@ /** @name: aping - @version: 1.0.1 (18-01-2016) + @version: 1.0.2 (20-01-2016) @author: Jonathan Hornung @url: https://github.com/JohnnyTheTank/apiNG @license: MIT @@ -14,9 +14,8 @@ var apingApp = angular.module('jtt_aping', ['jtt_aping_jsonloader', 'jtt_aping_n apingApiKeys: {} }); - }]) - .directive('aping', ['apingDefaultSettings', 'apingUtilityHelper', function (apingDefaultSettings, apingUtilityHelper) { + .directive('aping', ['apingDefaultSettings', 'apingUtilityHelper', '$templateRequest', '$compile', function (apingDefaultSettings, apingUtilityHelper, $templateRequest, $compile) { return { restrict: 'E', replace: 'false', @@ -31,6 +30,13 @@ var apingApp = angular.module('jtt_aping', ['jtt_aping_jsonloader', 'jtt_aping_n payloadJson: '@', removeDoubles: '@' }, + link: function (scope, element, attrs) { + $templateRequest(scope.templateUrl || apingDefaultSettings.templateUrl).then(function (html) { + var template = angular.element(html); + element.append(template); + $compile(template)(scope); + }); + }, controller: ['$scope', function ($scope) { $scope.results = []; $scope.payload = $scope.payloadJson ? apingUtilityHelper.replaceSingleQuotesAndParseJson($scope.payloadJson) : {}; @@ -147,13 +153,9 @@ var apingApp = angular.module('jtt_aping', ['jtt_aping_jsonloader', 'jtt_aping_n this.apply = function () { $scope.$apply(); }; - }], - templateUrl: function (elem, scope) { - return scope.templateUrl || apingDefaultSettings.templateUrl; - } + }] }; }]); - ;"use strict"; angular.module('jtt_aping').service('apingTimeHelper', function () { diff --git a/dist/aping.min.js b/dist/aping.min.js index e826c5b..8d2347f 100644 --- a/dist/aping.min.js +++ b/dist/aping.min.js @@ -1,8 +1,8 @@ /** @name: aping - @version: 1.0.1 (18-01-2016) + @version: 1.0.2 (20-01-2016) @author: Jonathan Hornung @url: https://github.com/JohnnyTheTank/apiNG @license: MIT */ -"use strict";var apingApp=angular.module("jtt_aping",["jtt_aping_jsonloader","jtt_aping_ng_array"]).config(["$provide",function(a){a.value("apingDefaultSettings",{apingApiKeys:{}})}]).directive("aping",["apingDefaultSettings","apingUtilityHelper",function(a,b){return{restrict:"E",replace:"false",scope:{model:"@",getNativeData:"@",items:"@",maxItems:"@",orderBy:"@",orderReverse:"@",templateUrl:"@",payloadJson:"@",removeDoubles:"@"},controller:["$scope",function(c){c.results=[],c.payload=c.payloadJson?b.replaceSingleQuotesAndParseJson(c.payloadJson):{},this.getAppSettings=function(){var b,d,e,f,g,h;return b="undefined"!=typeof c.items?c.items:"undefined"!=typeof a.items?a.items:void 0,d="undefined"!=typeof c.maxItems?c.maxItems:"undefined"!=typeof a.maxItems?a.maxItems:void 0,e="undefined"!=typeof c.getNativeData?c.getNativeData:"undefined"!=typeof a.getNativeData?a.getNativeData:!1,d="undefined"!=typeof c.maxItems?c.maxItems:"undefined"!=typeof a.maxItems?a.maxItems:void 0,g="undefined"!=typeof c.orderBy?c.orderBy:"undefined"!=typeof a.orderBy?a.orderBy:"undefined",f="undefined"!=typeof c.orderReverse?c.orderReverse:"undefined"!=typeof a.orderReverse?a.orderReverse:!1,h="undefined"!=typeof c.removeDoubles?c.removeDoubles:"undefined"!=typeof a.removeDoubles?a.removeDoubles:!1,{model:c.model||a.model||"native",getNativeData:e,items:b,maxItems:d,orderBy:g,orderReverse:f,removeDoubles:h}},this.concatToResults=function(a){c.results=c.results.concat(a);var d=this.getAppSettings();(d.removeDoubles===!0||"true"===d.removeDoubles)&&(c.results=b.removeDuplicateObjectsFromArray(c.results,d.orderBy===!1||"false"===d.orderBy||"$NONE"===d.orderBy)),"undefined"!==d.orderBy&&d.orderBy!==!1&&"false"!==d.orderBy&&"$NONE"!==d.orderBy&&("$RANDOM"===d.orderBy?c.results=b.shuffleArray(c.results):(c.results.sort(b.sortArrayByProperty(d.orderBy)),(d.orderReverse===!0||"true"===d.orderReverse)&&c.results.reverse())),d.maxItems>-1&&c.results.length>d.maxItems&&(c.results=c.results.splice(0,d.maxItems)),c.$broadcast("apiNG.resultMerged")},this.apply=function(){c.$apply()}}],templateUrl:function(b,c){return c.templateUrl||a.templateUrl}}}]);angular.module("jtt_aping").service("apingTimeHelper",function(){this.getTimestampFromDateString=function(a,b,c){if(("undefined"==typeof b||isNaN(b))&&(b=1),("undefined"==typeof 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&&("undefined"==typeof b.items&&"undefined"!=typeof d.items&&(b.items=d.items),"undefined"==typeof b.model&&"undefined"!=typeof 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){"undefined"!=typeof f?"undefined"!=typeof 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",[]).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&&"jsonp"===a.format?c.callback=a.callback:c.callback="JSON_CALLBACK","undefined"!=typeof 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;"undefined"!=typeof a.resultProperty&&(d=b.data[a.resultProperty]),b.data.constructor!==Array?c.push(d):a.items<0||"undefined"==typeof a.items?c=d:angular.forEach(d,function(b,d){d0&&e.concatToResults(d)}})}}}]); \ No newline at end of file +"use strict";var apingApp=angular.module("jtt_aping",["jtt_aping_jsonloader","jtt_aping_ng_array"]).config(["$provide",function(a){a.value("apingDefaultSettings",{apingApiKeys:{}})}]).directive("aping",["apingDefaultSettings","apingUtilityHelper","$templateRequest","$compile",function(a,b,c,d){return{restrict:"E",replace:"false",scope:{model:"@",getNativeData:"@",items:"@",maxItems:"@",orderBy:"@",orderReverse:"@",templateUrl:"@",payloadJson:"@",removeDoubles:"@"},link:function(b,e,f){c(b.templateUrl||a.templateUrl).then(function(a){var c=angular.element(a);e.append(c),d(c)(b)})},controller:["$scope",function(c){c.results=[],c.payload=c.payloadJson?b.replaceSingleQuotesAndParseJson(c.payloadJson):{},this.getAppSettings=function(){var b,d,e,f,g,h;return b="undefined"!=typeof c.items?c.items:"undefined"!=typeof a.items?a.items:void 0,d="undefined"!=typeof c.maxItems?c.maxItems:"undefined"!=typeof a.maxItems?a.maxItems:void 0,e="undefined"!=typeof c.getNativeData?c.getNativeData:"undefined"!=typeof a.getNativeData?a.getNativeData:!1,d="undefined"!=typeof c.maxItems?c.maxItems:"undefined"!=typeof a.maxItems?a.maxItems:void 0,g="undefined"!=typeof c.orderBy?c.orderBy:"undefined"!=typeof a.orderBy?a.orderBy:"undefined",f="undefined"!=typeof c.orderReverse?c.orderReverse:"undefined"!=typeof a.orderReverse?a.orderReverse:!1,h="undefined"!=typeof c.removeDoubles?c.removeDoubles:"undefined"!=typeof a.removeDoubles?a.removeDoubles:!1,{model:c.model||a.model||"native",getNativeData:e,items:b,maxItems:d,orderBy:g,orderReverse:f,removeDoubles:h}},this.concatToResults=function(a){c.results=c.results.concat(a);var d=this.getAppSettings();(d.removeDoubles===!0||"true"===d.removeDoubles)&&(c.results=b.removeDuplicateObjectsFromArray(c.results,d.orderBy===!1||"false"===d.orderBy||"$NONE"===d.orderBy)),"undefined"!==d.orderBy&&d.orderBy!==!1&&"false"!==d.orderBy&&"$NONE"!==d.orderBy&&("$RANDOM"===d.orderBy?c.results=b.shuffleArray(c.results):(c.results.sort(b.sortArrayByProperty(d.orderBy)),(d.orderReverse===!0||"true"===d.orderReverse)&&c.results.reverse())),d.maxItems>-1&&c.results.length>d.maxItems&&(c.results=c.results.splice(0,d.maxItems)),c.$broadcast("apiNG.resultMerged")},this.apply=function(){c.$apply()}}]}}]);angular.module("jtt_aping").service("apingTimeHelper",function(){this.getTimestampFromDateString=function(a,b,c){if(("undefined"==typeof b||isNaN(b))&&(b=1),("undefined"==typeof 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&&("undefined"==typeof b.items&&"undefined"!=typeof d.items&&(b.items=d.items),"undefined"==typeof b.model&&"undefined"!=typeof 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){"undefined"!=typeof f?"undefined"!=typeof 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",[]).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&&"jsonp"===a.format?c.callback=a.callback:c.callback="JSON_CALLBACK","undefined"!=typeof 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;"undefined"!=typeof a.resultProperty&&(d=b.data[a.resultProperty]),b.data.constructor!==Array?c.push(d):a.items<0||"undefined"==typeof 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 0160bb3..368193e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aping", - "version": "1.0.1", + "version": "1.0.2", "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 3bfbbda..b848ee9 100644 --- a/src/aping-directive.js +++ b/src/aping-directive.js @@ -7,9 +7,8 @@ var apingApp = angular.module('jtt_aping', ['jtt_aping_jsonloader', 'jtt_aping_n apingApiKeys: {} }); - }]) - .directive('aping', ['apingDefaultSettings', 'apingUtilityHelper', function (apingDefaultSettings, apingUtilityHelper) { + .directive('aping', ['apingDefaultSettings', 'apingUtilityHelper', '$templateRequest', '$compile', function (apingDefaultSettings, apingUtilityHelper, $templateRequest, $compile) { return { restrict: 'E', replace: 'false', @@ -24,6 +23,13 @@ var apingApp = angular.module('jtt_aping', ['jtt_aping_jsonloader', 'jtt_aping_n payloadJson: '@', removeDoubles: '@' }, + link: function (scope, element, attrs) { + $templateRequest(scope.templateUrl || apingDefaultSettings.templateUrl).then(function (html) { + var template = angular.element(html); + element.append(template); + $compile(template)(scope); + }); + }, controller: ['$scope', function ($scope) { $scope.results = []; $scope.payload = $scope.payloadJson ? apingUtilityHelper.replaceSingleQuotesAndParseJson($scope.payloadJson) : {}; @@ -140,10 +146,6 @@ var apingApp = angular.module('jtt_aping', ['jtt_aping_jsonloader', 'jtt_aping_n this.apply = function () { $scope.$apply(); }; - }], - templateUrl: function (elem, scope) { - return scope.templateUrl || apingDefaultSettings.templateUrl; - } + }] }; }]); -