Requested Changes, IE Download fix only

This commit is contained in:
Alexander Do 2018-04-08 22:36:55 +00:00
parent d3b8ef44ed
commit 2925fa8bfc
1 changed files with 14 additions and 10 deletions

View File

@ -1925,12 +1925,22 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) {
{ {
var imagePrefix = 'data:image/'; var imagePrefix = 'data:image/';
if (window.Blob) { // IE does not support setting a data URI on an a element
// Convert dataURI to a Blob and use msSaveBlob to download
if (window.Blob && navigator.msSaveBlob) {
// data URI format: data:[<contentType>][;base64],<data>
// position in data URI string of where data begins
var base64Start = attachmentData.indexOf(',') + 1; var base64Start = attachmentData.indexOf(',') + 1;
// position in data URI string of where contentType ends
var contentTypeEnd = attachmentData.indexOf(';'); var contentTypeEnd = attachmentData.indexOf(';');
// extract contentType
var contentType = attachmentData.substring(5, contentTypeEnd); var contentType = attachmentData.substring(5, contentTypeEnd);
// extract data and convert to binary
var buf = Base64.atob(attachmentData.substring(base64Start)); var buf = Base64.atob(attachmentData.substring(base64Start));
// Transform into a Blob
var bufLength = buf.length; var bufLength = buf.length;
var array = new Uint8Array(bufLength); var array = new Uint8Array(bufLength);
@ -1940,15 +1950,9 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) {
var file = new window.Blob([ array ], { type: contentType }); var file = new window.Blob([ array ], { type: contentType });
if (navigator.msSaveBlob) { $attachmentLink.bind('click', function () {
$attachmentLink.bind('click', function () { navigator.msSaveBlob(file, fileName);
navigator.msSaveBlob(file, fileName); });
});
} else if (window.URL && window.URL.createObjectURL) {
$attachmentLink.attr('href', window.URL.createObjectURL(file));
} else {
$attachmentLink.attr('href', attachmentData);
}
} else { } else {
$attachmentLink.attr('href', attachmentData); $attachmentLink.attr('href', attachmentData);
} }