Code review results and further improvements

Added english default for new translations
This commit is contained in:
thororm 2017-05-15 22:05:52 +02:00
parent 24aea957b3
commit 2c17c35b85
13 changed files with 168 additions and 114 deletions

View File

@ -132,6 +132,7 @@
"Cloned: '%s'": "Clonado: '%s'.", "Cloned: '%s'": "Clonado: '%s'.",
"The cloned file '%s' was attached to this paste.": "The cloned file '%s' was attached to this paste.", "The cloned file '%s' was attached to this paste.": "The cloned file '%s' was attached to this paste.",
"Attach a file": "Adjuntar archivo", "Attach a file": "Adjuntar archivo",
"alternatively drag & drop a file or paste an image from the clipboard": "alternatively drag & drop a file or paste an image from the clipboard",
"Remove attachment": "Remover adjunto", "Remove attachment": "Remover adjunto",
"Your browser does not support uploading encrypted files. Please use a newer browser.": "Your browser does not support uploading encrypted files. Please use a newer browser.":
"Tu navegador no admite la carga de archivos cifrados. Utilice un navegador más reciente.", "Tu navegador no admite la carga de archivos cifrados. Utilice un navegador más reciente.",

View File

@ -141,6 +141,7 @@
"Cloned: '%s'": "Cloner '%s'", "Cloned: '%s'": "Cloner '%s'",
"The cloned file '%s' was attached to this paste.": "The cloned file '%s' was attached to this paste.", "The cloned file '%s' was attached to this paste.": "The cloned file '%s' was attached to this paste.",
"Attach a file": "Attacher un fichier ", "Attach a file": "Attacher un fichier ",
"alternatively drag & drop a file or paste an image from the clipboard": "alternatively drag & drop a file or paste an image from the clipboard",
"Remove attachment": "Enlever l'attachement", "Remove attachment": "Enlever l'attachement",
"Your browser does not support uploading encrypted files. Please use a newer browser.": "Your browser does not support uploading encrypted files. Please use a newer browser.":
"Votre navigateur ne supporte pas l'envoi de fichiers chiffrés. Merci d'utiliser un navigateur plus récent.", "Votre navigateur ne supporte pas l'envoi de fichiers chiffrés. Merci d'utiliser un navigateur plus récent.",

View File

@ -132,6 +132,7 @@
"Cloned: '%s'": "Clonato: '%s'", "Cloned: '%s'": "Clonato: '%s'",
"The cloned file '%s' was attached to this paste.": "Il file clonato '%s' era allegato a questo messaggio.", "The cloned file '%s' was attached to this paste.": "Il file clonato '%s' era allegato a questo messaggio.",
"Attach a file": "Allega un file", "Attach a file": "Allega un file",
"alternatively drag & drop a file or paste an image from the clipboard": "alternatively drag & drop a file or paste an image from the clipboard",
"Remove attachment": "Rimuovi allegato", "Remove attachment": "Rimuovi allegato",
"Your browser does not support uploading encrypted files. Please use a newer browser.": "Your browser does not support uploading encrypted files. Please use a newer browser.":
"Il tuo browser non supporta l'invio di file cifrati. Utilizza un browser più recente.", "Il tuo browser non supporta l'invio di file cifrati. Utilizza un browser più recente.",

View File

@ -132,6 +132,7 @@
"Cloned: '%s'": "Kopiert: '%s'", "Cloned: '%s'": "Kopiert: '%s'",
"The cloned file '%s' was attached to this paste.": "The cloned file '%s' was attached to this paste.", "The cloned file '%s' was attached to this paste.": "The cloned file '%s' was attached to this paste.",
"Attach a file": "Legg til fil", "Attach a file": "Legg til fil",
"alternatively drag & drop a file or paste an image from the clipboard": "alternatively drag & drop a file or paste an image from the clipboard",
"Remove attachment": "Slett vedlegg", "Remove attachment": "Slett vedlegg",
"Your browser does not support uploading encrypted files. Please use a newer browser.": "Your browser does not support uploading encrypted files. Please use a newer browser.":
"Nettleseren din støtter ikke å laste opp krypterte filer. Vennligst bruk en nyere nettleser.", "Nettleseren din støtter ikke å laste opp krypterte filer. Vennligst bruk en nyere nettleser.",

View File

@ -141,6 +141,7 @@
"Cloned: '%s'": "Clonar: '%s'", "Cloned: '%s'": "Clonar: '%s'",
"The cloned file '%s' was attached to this paste.": "The cloned file '%s' was attached to this paste.", "The cloned file '%s' was attached to this paste.": "The cloned file '%s' was attached to this paste.",
"Attach a file": "Juntar un fichièr ", "Attach a file": "Juntar un fichièr ",
"alternatively drag & drop a file or paste an image from the clipboard": "alternatively drag & drop a file or paste an image from the clipboard",
"Remove attachment": "Levar la pèca junta", "Remove attachment": "Levar la pèca junta",
"Your browser does not support uploading encrypted files. Please use a newer browser.": "Your browser does not support uploading encrypted files. Please use a newer browser.":
"Vòstre navigator es pas compatible amb lo mandadís de fichièrs chifrats. Mercés d'emplegar un navigator mai recent.", "Vòstre navigator es pas compatible amb lo mandadís de fichièrs chifrats. Mercés d'emplegar un navigator mai recent.",

View File

@ -132,6 +132,7 @@
"Cloned: '%s'": "Sklonowano: '%s'", "Cloned: '%s'": "Sklonowano: '%s'",
"The cloned file '%s' was attached to this paste.": "The cloned file '%s' was attached to this paste.", "The cloned file '%s' was attached to this paste.": "The cloned file '%s' was attached to this paste.",
"Attach a file": "Załącz plik", "Attach a file": "Załącz plik",
"alternatively drag & drop a file or paste an image from the clipboard": "alternatively drag & drop a file or paste an image from the clipboard",
"Remove attachment": "Usuń załącznik", "Remove attachment": "Usuń załącznik",
"Your browser does not support uploading encrypted files. Please use a newer browser.": "Your browser does not support uploading encrypted files. Please use a newer browser.":
"Twoja przeglądarka nie wspiera wysyłania zaszyfrowanych plików. Użyj nowszej przeglądarki.", "Twoja przeglądarka nie wspiera wysyłania zaszyfrowanych plików. Użyj nowszej przeglądarki.",

View File

@ -132,6 +132,7 @@
"Cloned: '%s'": "Clonado: '%s'", "Cloned: '%s'": "Clonado: '%s'",
"The cloned file '%s' was attached to this paste.": "O arquivo clonado '%s' foi anexado a essa cópia.", "The cloned file '%s' was attached to this paste.": "O arquivo clonado '%s' foi anexado a essa cópia.",
"Attach a file": "Anexar um arquivo", "Attach a file": "Anexar um arquivo",
"alternatively drag & drop a file or paste an image from the clipboard": "alternatively drag & drop a file or paste an image from the clipboard",
"Remove attachment": "Remover anexo", "Remove attachment": "Remover anexo",
"Your browser does not support uploading encrypted files. Please use a newer browser.": "Your browser does not support uploading encrypted files. Please use a newer browser.":
"Seu navegador não permite subir arquivos cifrados. Por favor, utilize um navegador mais recente.", "Seu navegador não permite subir arquivos cifrados. Por favor, utilize um navegador mais recente.",

View File

@ -142,6 +142,7 @@
"The cloned file '%s' was attached to this paste.": "The cloned file '%s' was attached to this paste.":
"Дубликат файла '%s' был прикреплен к этой записи.", "Дубликат файла '%s' был прикреплен к этой записи.",
"Attach a file": "Прикрепить файл", "Attach a file": "Прикрепить файл",
"alternatively drag & drop a file or paste an image from the clipboard": "alternatively drag & drop a file or paste an image from the clipboard",
"Remove attachment": "Удалить вложение", "Remove attachment": "Удалить вложение",
"Your browser does not support uploading encrypted files. Please use a newer browser.": "Your browser does not support uploading encrypted files. Please use a newer browser.":
"Ваш браузер не поддерживает отправку зашифрованных файлов. Используйте более новый браузер.", "Ваш браузер не поддерживает отправку зашифрованных файлов. Используйте более новый браузер.",

View File

@ -141,6 +141,7 @@
"Cloned: '%s'": "'%s' klonirana", "Cloned: '%s'": "'%s' klonirana",
"The cloned file '%s' was attached to this paste.": "The cloned file '%s' was attached to this paste.", "The cloned file '%s' was attached to this paste.": "The cloned file '%s' was attached to this paste.",
"Attach a file": "Pripni datoteko", "Attach a file": "Pripni datoteko",
"alternatively drag & drop a file or paste an image from the clipboard": "alternatively drag & drop a file or paste an image from the clipboard",
"Remove attachment": "Odstrani priponko", "Remove attachment": "Odstrani priponko",
"Your browser does not support uploading encrypted files. Please use a newer browser.": "Your browser does not support uploading encrypted files. Please use a newer browser.":
"Tvoj brskalnik ne omogoča nalaganje zakodiranih datotek. Prosim uporabi novejši brskalnik.", "Tvoj brskalnik ne omogoča nalaganje zakodiranih datotek. Prosim uporabi novejši brskalnik.",

View File

@ -132,6 +132,7 @@
"Cloned: '%s'": "克隆: '%s'", "Cloned: '%s'": "克隆: '%s'",
"The cloned file '%s' was attached to this paste.": "克隆文件 '%s' 已附加到此粘贴。", "The cloned file '%s' was attached to this paste.": "克隆文件 '%s' 已附加到此粘贴。",
"Attach a file": "添加一个附件", "Attach a file": "添加一个附件",
"alternatively drag & drop a file or paste an image from the clipboard": "alternatively drag & drop a file or paste an image from the clipboard",
"Remove attachment": "移除附件", "Remove attachment": "移除附件",
"Your browser does not support uploading encrypted files. Please use a newer browser.": "Your browser does not support uploading encrypted files. Please use a newer browser.":
"您的浏览器不支持上传加密的文件,请使用更新的浏览器。", "您的浏览器不支持上传加密的文件,请使用更新的浏览器。",

View File

@ -1594,9 +1594,9 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
// show preview // show preview
PasteViewer.setText($message.val()); PasteViewer.setText($message.val());
if (AttachmentViewer.$attachment.length) { if (AttachmentViewer.hasAttachmentData()) {
var attachmentData = AttachmentViewer.attachmentData || AttachmentViewer.$attachmentLink.attr('href'); var attachmentData = AttachmentViewer.getAttachmentData() || AttachmentViewer.getAttachmentLink().attr('href');
AttachmentViewer.handleAttachmentPreview(AttachmentViewer.$attachmentPreview, attachmentData); AttachmentViewer.handleAttachmentPreview(AttachmentViewer.getAttachmentPreview(), attachmentData);
} }
PasteViewer.run(); PasteViewer.run();
@ -1984,13 +1984,13 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
var AttachmentViewer = (function (window, document) { var AttachmentViewer = (function (window, document) {
var me = {}; var me = {};
me.$attachmentLink = undefined; var $attachmentLink = undefined;
me.$attachmentPreview = undefined; var $attachmentPreview = undefined;
me.$attachment = undefined; var $attachment = undefined;
me.attachmentData = undefined; var attachmentData = undefined;
me.file = undefined; var file = undefined;
me.$fileInput = undefined; var $fileInput = undefined;
var $dragAndDropFileName = undefined;
var attachmentHasPreview = false; var attachmentHasPreview = false;
/** /**
@ -2003,15 +2003,14 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
*/ */
me.setAttachment = function(attachmentData, fileName) me.setAttachment = function(attachmentData, fileName)
{ {
me.$attachmentLink.attr('href', attachmentData); $attachmentLink.attr('href', attachmentData);
if (typeof fileName !== 'undefined') { if (typeof fileName !== 'undefined') {
me.$attachmentLink.attr('download', fileName); $attachmentLink.attr('download', fileName);
} }
AttachmentViewer.handleAttachmentPreview(AttachmentViewer.$attachmentPreview, attachmentData); me.handleAttachmentPreview($attachmentPreview, attachmentData);
attachmentHasPreview = true; attachmentHasPreview = true;
};
}
/** /**
* displays the attachment * displays the attachment
@ -2021,12 +2020,12 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
*/ */
me.showAttachment = function() me.showAttachment = function()
{ {
me.$attachment.removeClass('hidden'); $attachment.removeClass('hidden');
if (attachmentHasPreview) { if (attachmentHasPreview) {
me.$attachmentPreview.removeClass('hidden'); $attachmentPreview.removeClass('hidden');
} }
} };
/** /**
* removes the attachment * removes the attachment
@ -2039,18 +2038,18 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
*/ */
me.removeAttachment = function() me.removeAttachment = function()
{ {
if (!me.$attachment.length) { if (!$attachment.length) {
return; return;
} }
me.hideAttachment(); me.hideAttachment();
me.hideAttachmentPreview(); me.hideAttachmentPreview();
me.$attachmentLink.prop('href', ''); $attachmentLink.prop('href', '');
me.$attachmentLink.prop('download', ''); $attachmentLink.prop('download', '');
me.$attachmentPreview.html(''); $attachmentPreview.html('');
AttachmentViewer.file = undefined; file = undefined;
AttachmentViewer.attachmentData = undefined; attachmentData = undefined;
} };
/** /**
* hides the attachment * hides the attachment
@ -2064,8 +2063,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
*/ */
me.hideAttachment = function() me.hideAttachment = function()
{ {
me.$attachment.addClass('hidden'); $attachment.addClass('hidden');
} };
/** /**
* hides the attachment preview * hides the attachment preview
@ -2075,10 +2074,10 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
*/ */
me.hideAttachmentPreview = function() me.hideAttachmentPreview = function()
{ {
if(me.$attachmentPreview){ if ($attachmentPreview) {
me.$attachmentPreview.addClass('hidden'); $attachmentPreview.addClass('hidden');
} }
} };
/** /**
* checks if there is an attachment * checks if there is an attachment
@ -2088,12 +2087,26 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
*/ */
me.hasAttachment = function() me.hasAttachment = function()
{ {
if (!AttachmentViewer.$attachment.length) { if (!$attachment.length) {
return false; return false;
} }
var link = me.$attachmentLink.prop('href'); var link = $attachmentLink.prop('href');
return (typeof link !== 'undefined' && link !== '') return (typeof link !== 'undefined' && link !== '');
} };
/**
* checks if there is attachment data available
*
* @name AttachmentViewer.hasAttachmentData
* @function
*/
me.hasAttachmentData = function()
{
if ($attachment.length) {
return true;
}
return false;
};
/** /**
* return the attachment * return the attachment
@ -2105,10 +2118,10 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
me.getAttachment = function() me.getAttachment = function()
{ {
return [ return [
me.$attachmentLink.prop('href'), $attachmentLink.prop('href'),
me.$attachmentLink.prop('download') $attachmentLink.prop('download')
]; ];
} };
/** /**
* moves the attachment link to another element * moves the attachment link to another element
@ -2123,68 +2136,66 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
me.moveAttachmentTo = function($element, label) me.moveAttachmentTo = function($element, label)
{ {
// move elemement to new place // move elemement to new place
me.$attachmentLink.appendTo($element); $attachmentLink.appendTo($element);
// update text // update text
I18n._(me.$attachmentLink, label, me.$attachmentLink.attr('download')); I18n._($attachmentLink, label, $attachmentLink.attr('download'));
} };
/**
/* * Read file data as dataURL using the FileReader API.
* Read file data as dataURL using the FileReader API * @param {type} aFile The loaded file.
* 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 {undefined}
*/ */
me.readFileData = function (file) { me.readFileData = function (aFile) {
if (typeof FileReader === 'undefined') { if (typeof FileReader === 'undefined') {
// revert loading status… // revert loading status…
AttachmentViewer.hideAttachment(); me.hideAttachment();
AttachmentViewer.hideAttachmentPreview(); me.hideAttachmentPreview();
Alert.showError(I18n._('Your browser does not support uploading encrypted files. Please use a newer browser.')); Alert.showError('Your browser does not support uploading encrypted files. Please use a newer browser.');
return; return;
} }
var fileReader = new FileReader(); var fileReader = new FileReader();
if (file === undefined) { if (aFile === undefined) {
file = me.$fileInput[0].files[0]; aFile = $fileInput[0].files[0];
$('#dragAndDropFileName').text(''); $($dragAndDropFileName).text('');
} else { } else {
$('#dragAndDropFileName').text(file.name); $($dragAndDropFileName).text(aFile.name);
} }
me.file = file; file = aFile;
fileReader.onload = function (event) { fileReader.onload = function (event) {
var dataURL = event.target.result; var dataURL = event.target.result;
me.attachmentData = dataURL; attachmentData = dataURL;
if (Editor.isPreview()) { if (Editor.isPreview()) {
me.handleAttachmentPreview(AttachmentViewer.$attachmentPreview, dataURL); me.handleAttachmentPreview($attachmentPreview, dataURL);
} }
}; };
fileReader.readAsDataURL(file); fileReader.readAsDataURL(aFile);
}; };
/** /**
* 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 {DOM Element} $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) {
if (data) { if (data) {
var mimeType = this.getMimeTypeFromDataURL(data); var mimeType = me.getMimeTypeFromDataURL(data);
if (mimeType.match(/image\//i)) { if (mimeType.match(/image\//i)) {
this.showImagePreview(targetElement, data); this.showImagePreview($targetElement, data);
} else if (mimeType.match(/video\//i)) { } else if (mimeType.match(/video\//i)) {
this.showVideoPreview(targetElement, data, mimeType); this.showVideoPreview($targetElement, data, mimeType);
} else if (mimeType.match(/audio\//i)) { } else if (mimeType.match(/audio\//i)) {
this.showAudioPreview(targetElement, data, mimeType); this.showAudioPreview($targetElement, data, mimeType);
} else if (mimeType.match(/\/pdf/i)) { } else if (mimeType.match(/\/pdf/i)) {
this.showPDFPreview(targetElement, data); this.showPDFPreview($targetElement, data);
} }
//else {
//console.log("file but no image/video/audio/pdf");
//}
} }
}; };
@ -2192,70 +2203,87 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
* Get Mime Type from a DataURL * Get Mime Type from a DataURL
* *
* @param {type} dataURL * @param {type} dataURL
* @returns Mime Type from a dataURL as obtained for a file using the FileReader API 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
*/ */
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,'));
}; };
me.showImagePreview = function (targetElement, image) { /**
targetElement.html( * Displays an image attachment within the $targetElement.
* @param {type} $targetElement jQuery reference to the element, where the image should be displayed.
* @param {type} image The image to display.
*/
me.showImagePreview = function ($targetElement, image) {
$targetElement.html(
$(document.createElement('img')) $(document.createElement('img'))
.attr('src', image) .attr('src', image)
.attr('class', 'img-thumbnail') .attr('class', 'img-thumbnail')
); );
targetElement.removeClass('hidden'); $targetElement.removeClass('hidden');
}; };
me.showVideoPreview = function (targetElement, video, mimeType) { /**
var videoPlayer = $(document.createElement('video')) * Displays a video with the HTML5 video tag.
* @param {type} $targetElement jQuery reference to the element, where the image should be displayed.
* @param {type} video The video file.
* @param {type} mimeType The mimeType of the video, as returned by getMimeTypeFromDataURL.
*/
me.showVideoPreview = function ($targetElement, video, mimeType) {
var $videoPlayer = $(document.createElement('video'))
.attr('controls', 'true') .attr('controls', 'true')
.attr('autoplay', 'true') .attr('autoplay', 'true')
.attr('loop', 'true')
.attr('class', 'img-thumbnail'); .attr('class', 'img-thumbnail');
videoPlayer.append($(document.createElement('source')) $videoPlayer.append($(document.createElement('source'))
.attr('type', mimeType) .attr('type', mimeType)
.attr('src', video)); .attr('src', video));
targetElement.html(videoPlayer); $targetElement.html($videoPlayer);
targetElement.removeClass('hidden'); $targetElement.removeClass('hidden');
}; };
me.showAudioPreview = function (targetElement, audio, mimeType) { /**
var audioPlayer = $(document.createElement('audio')) * Play audio with the HTML5 audio tag.
* @param {type} $targetElement jQuery reference to the element, where the image should be displayed.
* @param {type} audio The audio file.
* @param {type} mimeType The mimeType of the audio file, as returned by getMimeTypeFromDataURL.
*/
me.showAudioPreview = function ($targetElement, audio, mimeType) {
var $audioPlayer = $(document.createElement('audio'))
.attr('controls', 'true') .attr('controls', 'true')
.attr('autoplay', 'true'); .attr('autoplay', 'true');
audioPlayer.append($(document.createElement('source')) $audioPlayer.append($(document.createElement('source'))
.attr('type', mimeType) .attr('type', mimeType)
.attr('src', audio)); .attr('src', audio));
targetElement.html(audioPlayer); $targetElement.html($audioPlayer);
targetElement.removeClass('hidden'); $targetElement.removeClass('hidden');
}; };
me.showPDFPreview = function (targetElement, pdf) { me.showPDFPreview = function ($targetElement, pdf) {
//PDFs are only displayed if the filesize is smaller than about 1MB (after base64 encoding). //PDFs are only displayed if the filesize is smaller than about 1MB (after base64 encoding).
//Bigger filesizes currently cause crashes in various browsers. //Bigger filesizes currently cause crashes in various browsers.
//See also: https://code.google.com/p/chromium/issues/detail?id=69227 //See also: https://code.google.com/p/chromium/issues/detail?id=69227
//Firefox crashes with files that are about 1.5MB //Firefox crashes with files that are about 1.5MB
//The performance with 1MB files is bareable //The performance with 1MB files is bareable
if (pdf.length < 1398488) { if (pdf.length > 1398488) {
Alert.showError('File too large, to display a preview. Please download the attachment.');
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');
} else {
Alert.showError(I18n._('File too large, to display a preview. Please download the attachment.'));
}
}; };
/** /**
@ -2263,9 +2291,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
* @returns {undefined} * @returns {undefined}
*/ */
me.addDragDropHandler = function () { me.addDragDropHandler = function () {
var fileInput = me.$fileInput; if (typeof $fileInput === 'undefined' || $fileInput.length === 0) {
if (typeof fileInput === 'undefined' || fileInput.length === 0) {
return; return;
} }
@ -2275,14 +2301,15 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
}; };
var drop = function(event) { var drop = function(event) {
event.stopPropagation(); var evt = event.originalEvent;
event.preventDefault(); evt.stopPropagation();
evt.preventDefault();
if (fileInput) { if ($fileInput) {
var file = event.dataTransfer.files[0]; var file = evt.dataTransfer.files[0];
//Clear the file input: //Clear the file input:
fileInput.wrap('<form>').closest('form').get(0).reset(); $fileInput.wrap('<form>').closest('form').get(0).reset();
fileInput.unwrap(); $fileInput.unwrap();
//Only works in Chrome: //Only works in Chrome:
//fileInput[0].files = e.dataTransfer.files; //fileInput[0].files = e.dataTransfer.files;
@ -2290,10 +2317,10 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
} }
}; };
document.addEventListener("drop", drop, false); $(document).on('drop', drop);
document.addEventListener("dragenter", ignoreDragDrop, false); $(document).on('dragenter', ignoreDragDrop);
document.addEventListener("dragover", ignoreDragDrop, false); $(document).on('dragover', ignoreDragDrop);
fileInput.on("change", function () { $fileInput.on("change", function () {
me.readFileData(); me.readFileData();
}); });
}; };
@ -2303,7 +2330,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
* @returns {undefined} * @returns {undefined}
*/ */
me.addClipboardEventHandler = function () { me.addClipboardEventHandler = function () {
document.addEventListener("paste", $(document).on('paste',
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) {
@ -2312,7 +2339,23 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
me.readFileData(item.getAsFile()); me.readFileData(item.getAsFile());
} }
} }
}, false); });
};
me.getAttachmentData = function () {
return attachmentData;
};
me.getAttachmentLink = function () {
return $attachmentLink;
};
me.getAttachmentPreview = function () {
return $attachmentPreview;
};
me.getFile = function () {
return file;
}; };
/** /**
@ -2325,12 +2368,13 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
*/ */
me.init = function() me.init = function()
{ {
me.$attachment = $('#attachment'); $attachment = $('#attachment');
if(me.$attachment.length){ if($attachment.length){
me.$attachmentLink = $('#attachment a'); $attachmentLink = $('#attachment a');
me.$attachmentPreview = $('#attachmentPreview'); $attachmentPreview = $('#attachmentPreview');
$dragAndDropFileName = $('#dragAndDropFileName');
me.$fileInput = $('#file'); $fileInput = $('#file');
me.addDragDropHandler(); me.addDragDropHandler();
me.addClipboardEventHandler(); me.addClipboardEventHandler();
} }
@ -3560,10 +3604,10 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
* @param {function} callback - excuted when action is successful * @param {function} callback - excuted when action is successful
*/ */
function encryptAttachments(callback) { function encryptAttachments(callback) {
var file = AttachmentViewer.attachmentData; var file = AttachmentViewer.getAttachmentData();
if (typeof file !== 'undefined' && file !== null) { if (typeof file !== 'undefined' && file !== null) {
var fileName = AttachmentViewer.file.name; var fileName = AttachmentViewer.getFile().name;
Uploader.setData('attachment', file); Uploader.setData('attachment', file);
Uploader.setData('attachmentname', fileName); Uploader.setData('attachmentname', fileName);
@ -3678,7 +3722,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
// get data // get data
var plainText = Editor.getText(), var plainText = Editor.getText(),
format = PasteViewer.getFormat(), format = PasteViewer.getFormat(),
files = TopNav.getFileList() || AttachmentViewer.file || AttachmentViewer.hasAttachment(); files = TopNav.getFileList() || AttachmentViewer.getFile() || AttachmentViewer.hasAttachment();
// do not send if there is no data // do not send if there is no data
if (plainText.length === 0 && files === null) { if (plainText.length === 0 && files === null) {
@ -3943,7 +3987,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
try { try {
// decrypt attachments // decrypt attachments
if (paste.attachment) { if (paste.attachment) {
if (AttachmentViewer.$attachment.length) { if (AttachmentViewer.hasAttachmentData()) {
// try to decrypt paste and if it fails (because the password is // try to decrypt paste and if it fails (because the password is
// missing) return to let JS continue and wait for user // missing) return to let JS continue and wait for user
if (!decryptAttachment(paste, key, password)) { if (!decryptAttachment(paste, key, password)) {

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-wrGlxXZ5UYLGd+2CJB2I4xXJXoG632WaqM+glL2g669ta/mDwPgDhB+mhoXGdD7PWLpZ9JIgcjovMou/wrPtRg==" crossorigin="anonymous"></script> <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-bPnxglPsTLVc/s99MgzFi+rfER4B+Pp8/1l0n39CbhGg3QXZSn+yDmJoUEKGSaak4wtFPv8LZ5gWH+TmpYueuA==" 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-wrGlxXZ5UYLGd+2CJB2I4xXJXoG632WaqM+glL2g669ta/mDwPgDhB+mhoXGdD7PWLpZ9JIgcjovMou/wrPtRg==" crossorigin="anonymous"></script> <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-bPnxglPsTLVc/s99MgzFi+rfER4B+Pp8/1l0n39CbhGg3QXZSn+yDmJoUEKGSaak4wtFPv8LZ5gWH+TmpYueuA==" 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]-->