Code review

This commit is contained in:
thororm 2017-05-20 16:04:10 +02:00
parent a8aacce04d
commit 39717707b3
3 changed files with 44 additions and 42 deletions

View File

@ -1984,13 +1984,13 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
var AttachmentViewer = (function (window, document) { var AttachmentViewer = (function (window, document) {
var me = {}; var me = {};
var $attachmentLink = undefined; var $attachmentLink;
var $attachmentPreview = undefined; var $attachmentPreview;
var $attachment = undefined; var $attachment;
var attachmentData = undefined; var attachmentData;
var file = undefined; var file;
var $fileInput = undefined; var $fileInput;
var $dragAndDropFileName = undefined; var $dragAndDropFileName;
var attachmentHasPreview = false; var attachmentHasPreview = false;
/** /**
@ -2144,11 +2144,11 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* Read file data as dataURL using the FileReader API. * Read file data as dataURL using the FileReader API.
* @param {type} aFile The loaded file. * @param {object} loadedFile The loaded file.
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader#readAsDataURL()} * @see {@link https://d function (aFileeveloper.mozilla.org/en-US/docs/Web/API/FileReader#readAsDataURL()}
* @returns {undefined} * @returns {undefined}
*/ */
me.readFileData = function (aFile) { me.readFileData = function (loadedFile) {
if (typeof FileReader === 'undefined') { if (typeof FileReader === 'undefined') {
// revert loading status… // revert loading status…
me.hideAttachment(); me.hideAttachment();
@ -2158,14 +2158,14 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
} }
var fileReader = new FileReader(); var fileReader = new FileReader();
if (aFile === undefined) { if (loadedFile === undefined) {
aFile = $fileInput[0].files[0]; loadedFile = $fileInput[0].files[0];
$($dragAndDropFileName).text(''); $dragAndDropFileName.text('');
} else { } else {
$($dragAndDropFileName).text(aFile.name); $dragAndDropFileName.text(loadedFile.name);
} }
file = aFile; file = loadedFile;
fileReader.onload = function (event) { fileReader.onload = function (event) {
var dataURL = event.target.result; var dataURL = event.target.result;
@ -2175,12 +2175,12 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
me.handleAttachmentPreview($attachmentPreview, dataURL); me.handleAttachmentPreview($attachmentPreview, dataURL);
} }
}; };
fileReader.readAsDataURL(aFile); fileReader.readAsDataURL(loadedFile);
}; };
/** /**
* Handle the preview of files that can either be an image, video, audio or pdf element. * Handle the preview of files that can either be an image, video, audio or pdf element.
* @argument {DOM Element} $targetElement where the preview should be appended. * @argument {jQuery} $targetElement where the preview should be appended.
* @argument {File Data} data of the file to be displayed. * @argument {File Data} data of the file to be displayed.
*/ */
me.handleAttachmentPreview = function ($targetElement, data) { me.handleAttachmentPreview = function ($targetElement, data) {
@ -2202,9 +2202,9 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* Get Mime Type from a DataURL * Get Mime Type from a DataURL
* *
* @param {type} dataURL * @param {string} dataURL
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader#readAsDataURL()} * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader#readAsDataURL()}
* @returns Mime Type from a dataURL as obtained for a file using the FileReader API * @returns {string} Mime Type from a dataURL as obtained for a file using the FileReader API
*/ */
me.getMimeTypeFromDataURL = function (dataURL) { me.getMimeTypeFromDataURL = function (dataURL) {
return dataURL.slice(dataURL.indexOf('data:') + 5, dataURL.indexOf(';base64,')); return dataURL.slice(dataURL.indexOf('data:') + 5, dataURL.indexOf(';base64,'));
@ -2212,8 +2212,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* Displays an image attachment within the $targetElement. * Displays an image attachment within the $targetElement.
* @param {type} $targetElement jQuery reference to the element, where the image should be displayed. * @param {jQuery} $targetElement jQuery reference to the element, where the image should be displayed.
* @param {type} image The image to display. * @param {string} image The image to display.
*/ */
me.showImagePreview = function ($targetElement, image) { me.showImagePreview = function ($targetElement, image) {
$targetElement.html( $targetElement.html(
@ -2226,9 +2226,9 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* Displays a video with the HTML5 video tag. * Displays a video with the HTML5 video tag.
* @param {type} $targetElement jQuery reference to the element, where the image should be displayed. * @param {jQuery} $targetElement jQuery reference to the element, where the image should be displayed.
* @param {type} video The video file. * @param {string} video The video file.
* @param {type} mimeType The mimeType of the video, as returned by getMimeTypeFromDataURL. * @param {string} mimeType The mimeType of the video, as returned by getMimeTypeFromDataURL.
*/ */
me.showVideoPreview = function ($targetElement, video, mimeType) { me.showVideoPreview = function ($targetElement, video, mimeType) {
var $videoPlayer = $(document.createElement('video')) var $videoPlayer = $(document.createElement('video'))
@ -2245,9 +2245,9 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* Play audio with the HTML5 audio tag. * Play audio with the HTML5 audio tag.
* @param {type} $targetElement jQuery reference to the element, where the image should be displayed. * @param {jQuery} $targetElement jQuery reference to the element, where the image should be displayed.
* @param {type} audio The audio file. * @param {string} audio The audio file.
* @param {type} mimeType The mimeType of the audio file, as returned by getMimeTypeFromDataURL. * @param {string} mimeType The mimeType of the audio file, as returned by getMimeTypeFromDataURL.
*/ */
me.showAudioPreview = function ($targetElement, audio, mimeType) { me.showAudioPreview = function ($targetElement, audio, mimeType) {
var $audioPlayer = $(document.createElement('audio')) var $audioPlayer = $(document.createElement('audio'))
@ -2273,17 +2273,17 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
return; return;
} }
//Fallback for browsers, that don't support the vh unit //Fallback for browsers, that don't support the vh unit
var clientHeight = $(window).height(); var clientHeight = $(window).height();
$targetElement.html( $targetElement.html(
$(document.createElement('embed')) $(document.createElement('embed'))
.attr('src', pdf) .attr('src', pdf)
.attr('type', 'application/pdf') .attr('type', 'application/pdf')
.attr('class', 'pdfPreview') .attr('class', 'pdfPreview')
.css('height', clientHeight) .css('height', clientHeight)
); );
$targetElement.removeClass('hidden'); $targetElement.removeClass('hidden');
}; };
/** /**
@ -2334,9 +2334,11 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
function (event) { function (event) {
var items = (event.clipboardData || event.originalEvent.clipboardData).items; var items = (event.clipboardData || event.originalEvent.clipboardData).items;
for (var i in items) { for (var i in items) {
var item = items[i]; if ({}.hasOwnProperty.call(items, i)) {
if (item.kind === 'file') { var item = items[i];
me.readFileData(item.getAsFile()); if (item.kind === 'file') {
me.readFileData(item.getAsFile());
}
} }
} }
}); });

View File

@ -69,7 +69,7 @@ if ($MARKDOWN):
<?php <?php
endif; endif;
?> ?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-bPnxglPsTLVc/s99MgzFi+rfER4B+Pp8/1l0n39CbhGg3QXZSn+yDmJoUEKGSaak4wtFPv8LZ5gWH+TmpYueuA==" crossorigin="anonymous"></script> <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-v1nSavJqL5gvqQtfrH0cndbvFal942oTf++lgBxx/u0EYCRp2v1Oj0hcQkRYpTFdDsmXJgj06WoDdk6FvbMalw==" 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

@ -47,7 +47,7 @@ if ($MARKDOWN):
<?php <?php
endif; endif;
?> ?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-bPnxglPsTLVc/s99MgzFi+rfER4B+Pp8/1l0n39CbhGg3QXZSn+yDmJoUEKGSaak4wtFPv8LZ5gWH+TmpYueuA==" crossorigin="anonymous"></script> <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-v1nSavJqL5gvqQtfrH0cndbvFal942oTf++lgBxx/u0EYCRp2v1Oj0hcQkRYpTFdDsmXJgj06WoDdk6FvbMalw==" 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]-->