8 lines
11 KiB
JavaScript
8 lines
11 KiB
JavaScript
|
/*!
|
||
|
* HTML5 export buttons for Buttons and DataTables.
|
||
|
* 2015 SpryMedia Ltd - datatables.net/license
|
||
|
*
|
||
|
* FileSaver.js (2015-05-07.2) - MIT license
|
||
|
* Copyright © 2015 Eli Grey - http://eligrey.com
|
||
|
*/
|
||
|
!function(a){"function"==typeof define&&define.amd?define(["jquery","datatables.net","datatables.net-buttons"],function(b){return a(b,window,document)}):"object"==typeof exports?module.exports=function(b,c){return b||(b=window),c&&c.fn.dataTable||(c=require("datatables.net")(b,c).$),c.fn.dataTable.Buttons||require("datatables.net-buttons")(b,c),a(c,b,b.document)}:a(jQuery,window,document)}(function(a,b,c,d){"use strict";var e=a.fn.dataTable,f=function(a){if("undefined"==typeof navigator||!/MSIE [1-9]\./.test(navigator.userAgent)){var b=a.document,c=function(){return a.URL||a.webkitURL||a},e=b.createElementNS("http://www.w3.org/1999/xhtml","a"),f="download"in e,g=function(c){var d=b.createEvent("MouseEvents");d.initMouseEvent("click",!0,!1,a,0,0,0,0,0,!1,!1,!1,!1,0,null),c.dispatchEvent(d)},h=a.webkitRequestFileSystem,i=a.requestFileSystem||h||a.mozRequestFileSystem,j=function(b){(a.setImmediate||a.setTimeout)(function(){throw b},0)},k="application/octet-stream",l=0,m=500,n=function(b){var d=function(){"string"==typeof b?c().revokeObjectURL(b):b.remove()};a.chrome?d():setTimeout(d,m)},o=function(a,b,c){b=[].concat(b);for(var d=b.length;d--;){var e=a["on"+b[d]];if("function"==typeof e)try{e.call(a,c||a)}catch(f){j(f)}}},p=function(a){return/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(a.type)?new Blob(["\ufeff",a],{type:a.type}):a},q=function(b,j){b=p(b);var m,q,r,s=this,t=b.type,u=!1,v=function(){o(s,"writestart progress write writeend".split(" "))},w=function(){if(!u&&m||(m=c().createObjectURL(b)),q)q.location.href=m;else{var e=a.open(m,"_blank");e===d&&"undefined"!=typeof safari&&(a.location.href=m)}s.readyState=s.DONE,v(),n(m)},x=function(a){return function(){return s.readyState!==s.DONE?a.apply(this,arguments):void 0}},y={create:!0,exclusive:!1};return s.readyState=s.INIT,j||(j="download"),f?(m=c().createObjectURL(b),e.href=m,e.download=j,g(e),s.readyState=s.DONE,v(),void n(m)):(a.chrome&&t&&t!==k&&(r=b.slice||b.webkitSlice,b=r.call(b,0,b.size,k),u=!0),h&&"download"!==j&&(j+=".download"),(t===k||h)&&(q=a),i?(l+=b.size,void i(a.TEMPORARY,l,x(function(a){a.root.getDirectory("saved",y,x(function(a){var c=function(){a.getFile(j,y,x(function(a){a.createWriter(x(function(c){c.onwriteend=function(b){q.location.href=a.toURL(),s.readyState=s.DONE,o(s,"writeend",b),n(a)},c.onerror=function(){var a=c.error;a.code!==a.ABORT_ERR&&w()},"writestart progress write abort".split(" ").forEach(function(a){c["on"+a]=s["on"+a]}),c.write(b),s.abort=function(){c.abort(),s.readyState=s.DONE},s.readyState=s.WRITING}),w)}),w)};a.getFile(j,{create:!1},x(function(a){a.remove(),c()}),x(function(a){a.code===a.NOT_FOUND_ERR?c():w()}))}),w)}),w)):void w())},r=q.prototype,s=function(a,b){return new q(a,b)};return"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?function(a,b){return navigator.msSaveOrOpenBlob(p(a),b)}:(r.abort=function(){var a=this;a.readyState=a.DONE,o(a,"abort")},r.readyState=r.INIT=0,r.WRITING=1,r.DONE=2,r.error=r.onwritestart=r.onprogress=r.onwrite=r.onabort=r.onerror=r.onwriteend=null,s)}}(b),g=function(b,c){var e="*"===b.filename&&"*"!==b.title&&b.title!==d?b.title:b.filename;return"function"==typeof e&&(e=e()),-1!==e.indexOf("*")&&(e=e.replace("*",a("title").text())),e=e.replace(/[^a-zA-Z0-9_\u00A1-\uFFFF\.,\-_ !\(\)]/g,""),c===d||c===!0?e+b.extension:e},h=function(a){var b="Sheet1";return a.sheetName&&(b=a.sheetName.replace(/[\[\]\*\/\\\?\:]/g,"")),b},i=function(b){var c=b.title;return"function"==typeof c&&(c=c()),-1!==c.indexOf("*")?c.replace("*",a("title").text()):c},j=function(a){return a.newline?a.newline:navigator.userAgent.match(/Windows/)?"\r\n":"\n"},k=function(a,b){for(var c=j(b),e=a.buttons.exportData(b.exportOptions),f=b.fieldBoundary,g=b.fieldSeparator,h=new RegExp(f,"g"),i=b.escapeChar!==d?b.escapeChar:"\\",k=function(a){for(var b="",c=0,d=a.length;d>c;c++)c>0&&(b+=g),b+=f?f+(""+a[c]).replace(h,i+f)+f:a[c];return b},l=b.header?k(e.header)+c:"",m=b.footer&&e.footer?c+k(e.footer):"",n=[],o=0,p=e.body.length;p>o;o++)n.push(k(e.body[o]));return{str:l+n.join(c)+m,rows:n.lengt
|