forked from NicBright/ng-table-export
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathng-table-export.js
4 lines (3 loc) · 1.91 KB
/
ng-table-export.js
1
2
3
4
/*! ngTableExport v0.1.0 by Vitalii Savchuk([email protected]) - https://github.com/esvit/ng-table-export - New BSD License */
angular.module("ngTableExport",[]).config(["$compileProvider",function(a){a.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|data):/)}]).directive("exportCsv",["$parse",function(a){return{restrict:"A",scope:!1,link:function(b,c,d){function e(){console.error("ng table export: invalid encoding requested. only 'UTF-8' and 'ISO-8859-1' are supported")}function f(){var a=k?k:d.exportCsvEncoding;return a?a.match(/utf/)?"UTF-8":"ISO-8859-1":"UTF-8"}function g(){for(var a=j,b=new ArrayBuffer(a.length),c=new Uint8Array(b),d=0;d<c.length;d++){var e=a[d].charCodeAt(0);e>256&&(e=182),c[d]=e}var f=new Blob([c]);return f}function h(){return new Blob([j])}var i={stringify:function(a){return'"'+a.replace(/^\s\s*/,"").replace(/\s*\s$/,"").replace(/"/g,'""')+'"'},extractData:function(){j="";var a=c.find("tr");angular.forEach(a,function(a,b){var c=angular.element(a),d=c.find("th"),e="";c.hasClass("ng-table-filters")||(0==d.length&&(d=c.find("td")),1!=b&&(angular.forEach(d,function(a){e+=i.stringify(angular.element(a).text())+";"}),e=e.slice(0,e.length-1)),j+=e+"\n")})},generate:function(a,b){k=b,i.extractData(),i.generateIE(a)},generateIE:function(a){if(window.navigator.msSaveOrOpenBlob){var b,c,d=f();"UTF-8"===d?b=h():"ISO-8859-1"===d?b=g():e(),a&&a.preventDefault?(c=a.target.attributes.download.value,window.navigator.msSaveOrOpenBlob(b,c),a.preventDefault()):console.warn('ng table export: you should pass over the $event in your expression for proper IE support, e.g. via ng-click="csv.generate($event)" --- otherwise the href will be followed')}},link:function(){var a=f();return"UTF-8"===a?"data:text/csv;charset=UTF-8,"+encodeURIComponent(j):"ISO-8859-1"===a?"data:text/csv;charset=ISO-8859-1,"+escape(j):void e()}};a(d.exportCsv).assign(b.$parent,i);var j="",k=""}}}]);
//# sourceMappingURL=ng-table-export.map