From 2925fa8bfcf70d258fffb13962232345102c9940 Mon Sep 17 00:00:00 2001 From: Alexander Do Date: Sun, 8 Apr 2018 22:36:55 +0000 Subject: [PATCH] Requested Changes, IE Download fix only --- js/privatebin.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index dffa4a2a..f9fe5f9a 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1925,12 +1925,22 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { { 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:[][;base64], + + // position in data URI string of where data begins var base64Start = attachmentData.indexOf(',') + 1; + // position in data URI string of where contentType ends var contentTypeEnd = attachmentData.indexOf(';'); + // extract contentType var contentType = attachmentData.substring(5, contentTypeEnd); + // extract data and convert to binary var buf = Base64.atob(attachmentData.substring(base64Start)); + + // Transform into a Blob var bufLength = buf.length; var array = new Uint8Array(bufLength); @@ -1940,15 +1950,9 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { var file = new window.Blob([ array ], { type: contentType }); - if (navigator.msSaveBlob) { - $attachmentLink.bind('click', function () { - navigator.msSaveBlob(file, fileName); - }); - } else if (window.URL && window.URL.createObjectURL) { - $attachmentLink.attr('href', window.URL.createObjectURL(file)); - } else { - $attachmentLink.attr('href', attachmentData); - } + $attachmentLink.bind('click', function () { + navigator.msSaveBlob(file, fileName); + }); } else { $attachmentLink.attr('href', attachmentData); }