From acb3adbb69dd3e1a659f03545a9d34626850ba5c Mon Sep 17 00:00:00 2001 From: juanf <juanf> Date: Fri, 4 Mar 2016 15:27:44 +0000 Subject: [PATCH] SSDM-3295 : Exports for browsers that don't support TextEncoder. SVN: 35809 --- .../webapps/eln-lims/html/lib/grid/js/Grid.js | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.js index 0f207d18e54..a8bc475d038 100644 --- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.js +++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.js @@ -179,14 +179,27 @@ $.extend(Grid.prototype, { var tsvWithoutNumbers = tsv.substring(indexOfFirstLine + 1); // - var csvContentEncoded = (new TextEncoder("utf-16le")).encode([tsvWithoutNumbers]); - var bom = new Uint8Array([0xFF, 0xFE]); - var out = new Uint8Array( bom.byteLength + csvContentEncoded.byteLength ); - out.set( bom , 0 ); - out.set( csvContentEncoded, bom.byteLength ); + var csvContentEncoded = null; + var out = null; + var charType = null; + try { //USE UTF-16 if available + csvContentEncoded = (new TextEncoder("utf-16le")).encode([tsvWithoutNumbers]); + var bom = new Uint8Array([0xFF, 0xFE]); + out = new Uint8Array( bom.byteLength + csvContentEncoded.byteLength ); + out.set( bom , 0 ); + out.set( csvContentEncoded, bom.byteLength ); + charType = 'text/tsv;charset=UTF-16LE;'; + } catch(error) { //USE UTF-8 + csvContentEncoded = tsvWithoutNumbers; + out = new Uint8Array(csvContentEncoded.length); + for(var ii = 0,jj = csvContentEncoded.length; ii < jj; ++ii){ + out[ii] = csvContentEncoded.charCodeAt(ii); + } + charType = 'text/tsv;charset=UTF-8;'; + } // - var blob = new Blob([out], {type: 'text/tsv;charset=UTF-16LE;'}); + var blob = new Blob([out], {type: charType}); saveAs(blob,'exportedTable' + namePrefix + '.tsv'); } -- GitLab