|
@@ -22,6 +22,27 @@
|
|
|
/** global: showdown */
|
|
/** global: showdown */
|
|
|
/** global: kjua */
|
|
/** global: kjua */
|
|
|
|
|
|
|
|
|
|
+jQuery.fn.draghover = function() {
|
|
|
|
|
+ return this.each(function() {
|
|
|
|
|
+ let collection = $(),
|
|
|
|
|
+ self = $(this);
|
|
|
|
|
+
|
|
|
|
|
+ self.on('dragenter', function(e) {
|
|
|
|
|
+ if (collection.length === 0) {
|
|
|
|
|
+ self.trigger('draghoverstart');
|
|
|
|
|
+ }
|
|
|
|
|
+ collection = collection.add(e.target);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ self.on('dragleave drop', function(e) {
|
|
|
|
|
+ collection = collection.not(e.target);
|
|
|
|
|
+ if (collection.length === 0) {
|
|
|
|
|
+ self.trigger('draghoverend');
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
// main application start, called when DOM is fully loaded
|
|
// main application start, called when DOM is fully loaded
|
|
|
jQuery(document).ready(function() {
|
|
jQuery(document).ready(function() {
|
|
|
'use strict';
|
|
'use strict';
|
|
@@ -2492,7 +2513,8 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
file,
|
|
file,
|
|
|
$fileInput,
|
|
$fileInput,
|
|
|
$dragAndDropFileName,
|
|
$dragAndDropFileName,
|
|
|
- attachmentHasPreview = false;
|
|
|
|
|
|
|
+ attachmentHasPreview = false,
|
|
|
|
|
+ $dropzone;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* sets the attachment but does not yet show it
|
|
* sets the attachment but does not yet show it
|
|
@@ -2714,7 +2736,9 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
// revert loading status…
|
|
// revert loading status…
|
|
|
me.hideAttachment();
|
|
me.hideAttachment();
|
|
|
me.hideAttachmentPreview();
|
|
me.hideAttachmentPreview();
|
|
|
- Alert.showError('Your browser does not support uploading encrypted files. Please use a newer browser.');
|
|
|
|
|
|
|
+ Alert.showError(
|
|
|
|
|
+ I18n._('Your browser does not support uploading encrypted files. Please use a newer browser.')
|
|
|
|
|
+ );
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2728,16 +2752,20 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
|
|
|
|
|
file = loadedFile;
|
|
file = loadedFile;
|
|
|
|
|
|
|
|
- fileReader.onload = function (event) {
|
|
|
|
|
- const dataURL = event.target.result;
|
|
|
|
|
- attachmentData = dataURL;
|
|
|
|
|
|
|
+ if (typeof loadedFile !== 'undefined') {
|
|
|
|
|
+ fileReader.onload = function (event) {
|
|
|
|
|
+ const dataURL = event.target.result;
|
|
|
|
|
+ attachmentData = dataURL;
|
|
|
|
|
|
|
|
- if (Editor.isPreview()) {
|
|
|
|
|
- me.setAttachment(dataURL, loadedFile.name || '');
|
|
|
|
|
- $attachmentPreview.removeClass('hidden');
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
- fileReader.readAsDataURL(loadedFile);
|
|
|
|
|
|
|
+ if (Editor.isPreview()) {
|
|
|
|
|
+ me.handleAttachmentPreview($attachmentPreview, dataURL);
|
|
|
|
|
+ $attachmentPreview.removeClass('hidden');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ TopNav.highlightFileupload();
|
|
|
|
|
+ };
|
|
|
|
|
+ fileReader.readAsDataURL(loadedFile);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -2780,8 +2808,21 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
.attr('src', blobUrl))
|
|
.attr('src', blobUrl))
|
|
|
);
|
|
);
|
|
|
} else if (mimeType.match(/\/pdf/i)) {
|
|
} else if (mimeType.match(/\/pdf/i)) {
|
|
|
|
|
+ // PDFs are only displayed if the filesize is smaller than about 1MB (after base64 encoding).
|
|
|
|
|
+ // Bigger filesizes currently cause crashes in various browsers.
|
|
|
|
|
+ // See also: https://code.google.com/p/chromium/issues/detail?id=69227
|
|
|
|
|
+
|
|
|
|
|
+ // Firefox crashes with files that are about 1.5MB
|
|
|
|
|
+ // The performance with 1MB files is bearable
|
|
|
|
|
+ if (data.length > 1398488) {
|
|
|
|
|
+ Alert.showError(
|
|
|
|
|
+ I18n._('File too large to display a preview. Please download the attachment.')
|
|
|
|
|
+ ); //TODO: is this error really neccessary?
|
|
|
|
|
+ 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();
|
|
|
|
|
|
|
+ const clientHeight = $(window).height();
|
|
|
|
|
|
|
|
$targetElement.html(
|
|
$targetElement.html(
|
|
|
$(document.createElement('embed'))
|
|
$(document.createElement('embed'))
|
|
@@ -2808,12 +2849,12 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const ignoreDragDrop = function(event) {
|
|
|
|
|
|
|
+ const handleDragEnterOrOver = function(event) {
|
|
|
event.stopPropagation();
|
|
event.stopPropagation();
|
|
|
event.preventDefault();
|
|
event.preventDefault();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const drop = function(event) {
|
|
|
|
|
|
|
+ const handleDrop = function(event) {
|
|
|
const evt = event.originalEvent;
|
|
const evt = event.originalEvent;
|
|
|
evt.stopPropagation();
|
|
evt.stopPropagation();
|
|
|
evt.preventDefault();
|
|
evt.preventDefault();
|
|
@@ -2830,9 +2871,19 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- $(document).on('drop', drop);
|
|
|
|
|
- $(document).on('dragenter', ignoreDragDrop);
|
|
|
|
|
- $(document).on('dragover', ignoreDragDrop);
|
|
|
|
|
|
|
+ $(document).draghover().on({
|
|
|
|
|
+ 'draghoverstart': function() {
|
|
|
|
|
+ // show dropzone to indicate drop support
|
|
|
|
|
+ $dropzone.removeClass('hidden');
|
|
|
|
|
+ },
|
|
|
|
|
+ 'draghoverend': function() {
|
|
|
|
|
+ $dropzone.addClass('hidden');
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ $(document).on('drop', handleDrop);
|
|
|
|
|
+ $(document).on('dragenter dragover', handleDragEnterOrOver);
|
|
|
|
|
+
|
|
|
$fileInput.on('change', function () {
|
|
$fileInput.on('change', function () {
|
|
|
readFileData();
|
|
readFileData();
|
|
|
});
|
|
});
|
|
@@ -2920,6 +2971,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
$attachmentLink = $('#attachment a');
|
|
$attachmentLink = $('#attachment a');
|
|
|
$attachmentPreview = $('#attachmentPreview');
|
|
$attachmentPreview = $('#attachmentPreview');
|
|
|
$dragAndDropFileName = $('#dragAndDropFileName');
|
|
$dragAndDropFileName = $('#dragAndDropFileName');
|
|
|
|
|
+ $dropzone = $('#dropzone');
|
|
|
|
|
|
|
|
$fileInput = $('#file');
|
|
$fileInput = $('#file');
|
|
|
addDragDropHandler();
|
|
addDragDropHandler();
|
|
@@ -3741,6 +3793,25 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
retryButtonCallback = callback;
|
|
retryButtonCallback = callback;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Highlight file upload
|
|
|
|
|
+ *
|
|
|
|
|
+ * @name TopNav.highlightFileupload
|
|
|
|
|
+ * @function
|
|
|
|
|
+ */
|
|
|
|
|
+ me.highlightFileupload = function()
|
|
|
|
|
+ {
|
|
|
|
|
+ // visually indicate file uploaded
|
|
|
|
|
+ const $attachDropdownToggle = $attach.children('.dropdown-toggle');
|
|
|
|
|
+ if ($attachDropdownToggle.attr('aria-expanded') === 'false') {
|
|
|
|
|
+ $attachDropdownToggle.click();
|
|
|
|
|
+ }
|
|
|
|
|
+ $fileWrap.addClass('highlight');
|
|
|
|
|
+ setTimeout(function () {
|
|
|
|
|
+ $fileWrap.removeClass('highlight');
|
|
|
|
|
+ }, 300);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* init navigation manager
|
|
* init navigation manager
|
|
|
*
|
|
*
|
|
@@ -4479,7 +4550,9 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
|
|
|
|
|
// log detailed error, but display generic translation
|
|
// log detailed error, but display generic translation
|
|
|
console.error(message);
|
|
console.error(message);
|
|
|
- Alert.showError('Could not decrypt data. Did you enter a wrong password? Retry with the button at the top.');
|
|
|
|
|
|
|
+ Alert.showError(
|
|
|
|
|
+ I18n._('Could not decrypt data. Did you enter a wrong password? Retry with the button at the top.')
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
// reset password, so it can be re-entered
|
|
// reset password, so it can be re-entered
|
|
|
Prompt.reset();
|
|
Prompt.reset();
|
|
@@ -4548,8 +4621,8 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
* @param {object} document
|
|
* @param {object} document
|
|
|
* @class
|
|
* @class
|
|
|
*/
|
|
*/
|
|
|
- var InitialCheck = (function () {
|
|
|
|
|
- var me = {};
|
|
|
|
|
|
|
+ const InitialCheck = (function () {
|
|
|
|
|
+ const me = {};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* blacklist of UserAgents (parts) known to belong to a bot
|
|
* blacklist of UserAgents (parts) known to belong to a bot
|
|
@@ -4762,7 +4835,9 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|
|
|
|
|
|
|
// missing decryption key (or paste ID) in URL?
|
|
// missing decryption key (or paste ID) in URL?
|
|
|
if (window.location.hash.length === 0) {
|
|
if (window.location.hash.length === 0) {
|
|
|
- Alert.showError('Cannot decrypt paste: Decryption key missing in URL (Did you use a redirector or an URL shortener which strips part of the URL?)');
|
|
|
|
|
|
|
+ Alert.showError(
|
|
|
|
|
+ I18n._('Cannot decrypt paste: Decryption key missing in URL (Did you use a redirector or an URL shortener which strips part of the URL?)')
|
|
|
|
|
+ );
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|