Merge branch 'otaku-blob'

This commit is contained in:
El RIDO 2018-04-29 10:29:25 +02:00
commit 939a62ab2c
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
3 changed files with 34 additions and 3 deletions

View file

@ -1925,7 +1925,37 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) {
{ {
var imagePrefix = 'data:image/'; var imagePrefix = 'data:image/';
$attachmentLink.attr('href', attachmentData); // 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) {
$attachmentLink.off('click').on('click', function () {
// data URI format: data:[<mediaType>][;base64],<data>
// position in data URI string of where data begins
var base64Start = attachmentData.indexOf(',') + 1;
// position in data URI string of where mediaType ends
var mediaTypeEnd = attachmentData.indexOf(';');
// extract mediaType
var mediaType = attachmentData.substring(5, mediaTypeEnd);
// extract data and convert to binary
var decodedData = Base64.atob(attachmentData.substring(base64Start));
// Transform into a Blob
var decodedDataLength = decodedData.length;
var buf = new Uint8Array(decodedDataLength);
for (var i = 0; i < decodedDataLength; i++) {
buf[i] = decodedData.charCodeAt(i);
}
var blob = new window.Blob([ buf ], { type: mediaType });
navigator.msSaveBlob(blob, fileName);
});
} else {
$attachmentLink.attr('href', attachmentData);
}
if (typeof fileName !== 'undefined') { if (typeof fileName !== 'undefined') {
$attachmentLink.attr('download', fileName); $attachmentLink.attr('download', fileName);
} }
@ -1971,6 +2001,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) {
me.hideAttachmentPreview(); me.hideAttachmentPreview();
$attachmentLink.prop('href', ''); $attachmentLink.prop('href', '');
$attachmentLink.prop('download', ''); $attachmentLink.prop('download', '');
$attachmentLink.off('click');
$attachmentPreview.html(''); $attachmentPreview.html('');
}; };

View file

@ -75,7 +75,7 @@ if ($MARKDOWN):
<?php <?php
endif; endif;
?> ?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-mfJhWCkoSbEobT+YpbhF2rN0cyEV27Z3ecHWgCSzl3CMywcRrd4oP/efgOfWXknJJpoqe8341j2hoXD7cSlQEQ==" crossorigin="anonymous"></script> <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-fJAdh2DQpns2TMhDmiohfNCQXpjX+f/KpRCiRnWI6hq0lOT/RRFc11+qJzGK5zNFjDvDhCMbMADKn4D03p9Uag==" crossorigin="anonymous"></script>
<!--[if lt IE 10]> <!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style> <style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]--> <![endif]-->

View file

@ -54,7 +54,7 @@ if ($QRCODE):
<?php <?php
endif; endif;
?> ?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-mfJhWCkoSbEobT+YpbhF2rN0cyEV27Z3ecHWgCSzl3CMywcRrd4oP/efgOfWXknJJpoqe8341j2hoXD7cSlQEQ==" crossorigin="anonymous"></script> <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-fJAdh2DQpns2TMhDmiohfNCQXpjX+f/KpRCiRnWI6hq0lOT/RRFc11+qJzGK5zNFjDvDhCMbMADKn4D03p9Uag==" crossorigin="anonymous"></script>
<!--[if lt IE 10]> <!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style> <style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]--> <![endif]-->