mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Output: Add output_savePlugin
option & update download code
This commit is contained in:
parent
b0cae87010
commit
39430d5773
@ -3,6 +3,7 @@
|
|||||||
* Modified from:
|
* Modified from:
|
||||||
* HTML Table to CSV: http://www.kunalbabre.com/projects/table2CSV.php (License unknown?)
|
* HTML Table to CSV: http://www.kunalbabre.com/projects/table2CSV.php (License unknown?)
|
||||||
* Download-File-JS: https://github.com/PixelsCommander/Download-File-JS (http://www.apache.org/licenses/LICENSE-2.0)
|
* Download-File-JS: https://github.com/PixelsCommander/Download-File-JS (http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
* FileSaver.js: https://github.com/eligrey/FileSaver.js (MIT)
|
||||||
*/
|
*/
|
||||||
/*jshint browser:true, jquery:true, unused:false */
|
/*jshint browser:true, jquery:true, unused:false */
|
||||||
/*global jQuery:false, alert:false */
|
/*global jQuery:false, alert:false */
|
||||||
@ -203,7 +204,7 @@
|
|||||||
if ( /p/i.test( wo.output_delivery || '' ) ) {
|
if ( /p/i.test( wo.output_delivery || '' ) ) {
|
||||||
output.popup(mydata, wo.output_popupStyle, outputJSON || outputArray);
|
output.popup(mydata, wo.output_popupStyle, outputJSON || outputArray);
|
||||||
} else {
|
} else {
|
||||||
output.download(wo, mydata);
|
output.download(c, wo, mydata);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, // end process
|
}, // end process
|
||||||
@ -294,13 +295,18 @@
|
|||||||
|
|
||||||
// modified from https://github.com/PixelsCommander/Download-File-JS
|
// modified from https://github.com/PixelsCommander/Download-File-JS
|
||||||
// & http://html5-demos.appspot.com/static/a.download.html
|
// & http://html5-demos.appspot.com/static/a.download.html
|
||||||
download : function (wo, data){
|
download : function (c, wo, data) {
|
||||||
|
|
||||||
var e, blob, gotBlob,
|
if (typeof wo.output_savePlugin === "function") {
|
||||||
|
return wo.output_savePlugin(c, wo, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
var e, blob, gotBlob, bom,
|
||||||
nav = window.navigator,
|
nav = window.navigator,
|
||||||
link = document.createElement('a');
|
link = document.createElement('a');
|
||||||
|
|
||||||
// iOS devices do not support downloading. We have to inform user about this.
|
// iOS devices do not support downloading. We have to inform user about
|
||||||
|
// this limitation.
|
||||||
if (/(iP)/g.test(nav.userAgent)) {
|
if (/(iP)/g.test(nav.userAgent)) {
|
||||||
alert(output.message);
|
alert(output.message);
|
||||||
return false;
|
return false;
|
||||||
@ -317,8 +323,12 @@
|
|||||||
if ( gotBlob ) {
|
if ( gotBlob ) {
|
||||||
|
|
||||||
window.URL = window.URL || window.webkitURL;
|
window.URL = window.URL || window.webkitURL;
|
||||||
// prepend BOM for utf-8 encoding - see https://github.com/eligrey/FileSaver.js/blob/master/FileSaver.js#L140
|
// prepend BOM for UTF-8 XML and text/* types (including HTML)
|
||||||
blob = new Blob( [ '\ufeff', data ], { type: wo.output_encoding } );
|
// note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
|
||||||
|
// see https://github.com/eligrey/FileSaver.js/blob/master/FileSaver.js#L68
|
||||||
|
bom = (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(wo.output_encoding)) ?
|
||||||
|
[ '\ufeff', data ] : [ data ]
|
||||||
|
blob = new Blob( bom, { type: wo.output_encoding } );
|
||||||
|
|
||||||
if (nav.msSaveBlob) {
|
if (nav.msSaveBlob) {
|
||||||
// IE 10+
|
// IE 10+
|
||||||
@ -379,7 +389,15 @@
|
|||||||
// JSON callback executed when a colspan is encountered in the header
|
// JSON callback executed when a colspan is encountered in the header
|
||||||
output_callbackJSON : function($cell, txt, cellIndex) { return txt + '(' + (cellIndex) + ')'; },
|
output_callbackJSON : function($cell, txt, cellIndex) { return txt + '(' + (cellIndex) + ')'; },
|
||||||
// the need to modify this for Excel no longer exists
|
// the need to modify this for Excel no longer exists
|
||||||
output_encoding : 'data:application/octet-stream;charset=utf8,'
|
output_encoding : 'data:application/octet-stream;charset=utf8,',
|
||||||
|
/* override internal save file code and use an external plugin such as
|
||||||
|
* https://github.com/eligrey/FileSaver.js (example)
|
||||||
|
* output_savePlugin: function(config, widgetOptions, data) {
|
||||||
|
* var blob = new Blob([data], {type: wo.output_encoding});
|
||||||
|
* saveAs(blob, wo.output_saveFileName);
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
output_savePlugin : null
|
||||||
},
|
},
|
||||||
init: function(table, thisWidget, c) {
|
init: function(table, thisWidget, c) {
|
||||||
output.init(c);
|
output.init(c);
|
||||||
|
Loading…
Reference in New Issue
Block a user