From 241d675798e4ead77651f2dc5d668724ef11bd7b Mon Sep 17 00:00:00 2001 From: Asaf David Date: Sun, 27 Apr 2014 12:37:15 +0300 Subject: [PATCH] Support promises #19 --- build/ng-csv.js | 9 ++------- build/ng-csv.min.js | 2 +- src/ng-csv/directives/ng-csv.js | 9 ++------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/build/ng-csv.js b/build/ng-csv.js index 54c2f15..4f97fca 100644 --- a/build/ng-csv.js +++ b/build/ng-csv.js @@ -82,10 +82,7 @@ angular.module('ngCsv.directives', []). { var csvContent = "data:text/csv;charset=utf-8,"; - var deferred = $q.defer(); - var promise = deferred.promise; - - promise.then(function () + $q.when(data).then(function () { // Check if there's a provided header array if (angular.isDefined($attrs.csvHeader)) @@ -141,12 +138,10 @@ angular.module('ngCsv.directives', []). $scope.csv = encodeURI(csvContent); - }).then(function () - { + }).then(function() { callback(); }); - deferred.resolve(); }; $scope.getFilename = function () diff --git a/build/ng-csv.min.js b/build/ng-csv.min.js index 8ce1e67..423b417 100644 --- a/build/ng-csv.min.js +++ b/build/ng-csv.min.js @@ -1,2 +1,2 @@ /*! ngcsv 27-04-2014 */ -!function(){angular.module("ngCsv.config",[]).value("ngCsv.config",{debug:!0}).config(["$compileProvider",function(a){angular.isDefined(a.urlSanitizationWhitelist)?a.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|data):/):a.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|data):/)}]),angular.module("ngCsv.directives",[]),angular.module("ngCsv",["ngCsv.config","ngCsv.directives","ngSanitize"]),angular.module("ngCsv.directives",[]).directive("ngCsv",["$parse","$q",function(a,b){return{restrict:"AC",replace:!0,transclude:!0,scope:{data:"&ngCsv",filename:"@filename",header:"&csvHeader",txtDelim:"@textDelimiter",fieldSep:"@fieldSeparator",lazyLoad:"@lazyLoad",ngClick:"&"},controller:["$scope","$element","$attrs","$transclude",function(a,c,d){var e=function(b){return"string"==typeof b?(b=b.replace(/"/g,'""'),a.txtDelim&&(b=a.txtDelim+b+a.txtDelim),b):"boolean"==typeof b?b?"TRUE":"FALSE":b};a.csv="",angular.isDefined(a.lazyLoad)&&"true"==a.lazyLoad||angular.isArray(a.data)&&a.$watch("data",function(){a.buildCsv(a.data(),function(){})},!0),a.buildCsv=function(c,f){var g="data:text/csv;charset=utf-8,",h=b.defer(),i=h.promise;i.then(function(){if(angular.isDefined(d.csvHeader)){var b,f,h=a.$eval(a.header);angular.isArray(h)?b=h:(b=[],angular.forEach(h,function(a){this.push(e(a))},b)),f=b.join(a.fieldSep?a.fieldSep:","),g+=f+"\n"}var i;i=angular.isArray(c)?c:c(),angular.forEach(i,function(b,c){var d,f;angular.isArray(b)?f=b:(f=[],angular.forEach(b,function(a){this.push(e(a))},f)),d=f.join(a.fieldSep?a.fieldSep:","),g+=c
',link:function(a,b){function c(){e[0].href="",e[0].click(),e[0].href=a.csv,e[0].click()}var d=angular.element(b.children()[0]),e=angular.element(b.children()[1]);d.bind("click",function(){a.buildCsv(a.data(),function(){c()}),a.ngClick&&a.ngClick()})}}}])}(window,document); \ No newline at end of file +!function(){angular.module("ngCsv.config",[]).value("ngCsv.config",{debug:!0}).config(["$compileProvider",function(a){angular.isDefined(a.urlSanitizationWhitelist)?a.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|data):/):a.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|data):/)}]),angular.module("ngCsv.directives",[]),angular.module("ngCsv",["ngCsv.config","ngCsv.directives","ngSanitize"]),angular.module("ngCsv.directives",[]).directive("ngCsv",["$parse","$q",function(a,b){return{restrict:"AC",replace:!0,transclude:!0,scope:{data:"&ngCsv",filename:"@filename",header:"&csvHeader",txtDelim:"@textDelimiter",fieldSep:"@fieldSeparator",lazyLoad:"@lazyLoad",ngClick:"&"},controller:["$scope","$element","$attrs","$transclude",function(a,c,d){var e=function(b){return"string"==typeof b?(b=b.replace(/"/g,'""'),a.txtDelim&&(b=a.txtDelim+b+a.txtDelim),b):"boolean"==typeof b?b?"TRUE":"FALSE":b};a.csv="",angular.isDefined(a.lazyLoad)&&"true"==a.lazyLoad||angular.isArray(a.data)&&a.$watch("data",function(){a.buildCsv(a.data(),function(){})},!0),a.buildCsv=function(c,f){var g="data:text/csv;charset=utf-8,";b.when(c).then(function(){if(angular.isDefined(d.csvHeader)){var b,f,h=a.$eval(a.header);angular.isArray(h)?b=h:(b=[],angular.forEach(h,function(a){this.push(e(a))},b)),f=b.join(a.fieldSep?a.fieldSep:","),g+=f+"\n"}var i;i=angular.isArray(c)?c:c(),angular.forEach(i,function(b,c){var d,f;angular.isArray(b)?f=b:(f=[],angular.forEach(b,function(a){this.push(e(a))},f)),d=f.join(a.fieldSep?a.fieldSep:","),g+=c
',link:function(a,b){function c(){e[0].href="",e[0].click(),e[0].href=a.csv,e[0].click()}var d=angular.element(b.children()[0]),e=angular.element(b.children()[1]);d.bind("click",function(){a.buildCsv(a.data(),function(){c()}),a.ngClick&&a.ngClick()})}}}])}(window,document); \ No newline at end of file diff --git a/src/ng-csv/directives/ng-csv.js b/src/ng-csv/directives/ng-csv.js index b1070b4..cd62fa6 100644 --- a/src/ng-csv/directives/ng-csv.js +++ b/src/ng-csv/directives/ng-csv.js @@ -55,10 +55,7 @@ angular.module('ngCsv.directives', []). { var csvContent = "data:text/csv;charset=utf-8,"; - var deferred = $q.defer(); - var promise = deferred.promise; - - promise.then(function () + $q.when(data).then(function () { // Check if there's a provided header array if (angular.isDefined($attrs.csvHeader)) @@ -114,12 +111,10 @@ angular.module('ngCsv.directives', []). $scope.csv = encodeURI(csvContent); - }).then(function () - { + }).then(function() { callback(); }); - deferred.resolve(); }; $scope.getFilename = function ()