Fix #1 prevent user to leave page before job done
This commit is contained in:
parent
5237e74a40
commit
50aa763ee1
|
@ -71,6 +71,7 @@ function spawnWebsocket() {
|
|||
pbd.innerHTML = '<a href="'+URL.createObjectURL(blob)+'" class="btn btn-primary" download="'+data.name+'">'+i18n.download+'</a>';
|
||||
|
||||
ws.send('{"ended":true}');
|
||||
window.onbeforeunload = null;
|
||||
} else {
|
||||
if (ws.readyState === 3) {
|
||||
ws = spawnWebsocket();
|
||||
|
@ -83,11 +84,14 @@ function spawnWebsocket() {
|
|||
console.log('error');
|
||||
}
|
||||
}
|
||||
|
||||
// When it's ready
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
window.a = new Array();
|
||||
window.key = pageKey();
|
||||
|
||||
// Set websocket
|
||||
ws = spawnWebsocket();
|
||||
|
||||
// Prevent exiting page before full download
|
||||
window.onbeforeunload = confirmExit;
|
||||
});
|
||||
|
|
|
@ -93,6 +93,8 @@ function handleFiles(f) {
|
|||
|
||||
// Create progress bar and call slicing and uploading function
|
||||
function uploadFile(i, delay, del_at_first_view) {
|
||||
// Prevent exiting page before full upload
|
||||
window.onbeforeunload = confirmExit;
|
||||
|
||||
// Create a random key, different for all files
|
||||
var randomkey = sjcl.codec.base64.fromBits(sjcl.random.randomWords(8, 0), 0);
|
||||
|
@ -211,6 +213,8 @@ function updateProgressBar(data) {
|
|||
if (i < window.files.length) {
|
||||
uploadFile(i, delay, del_at_first_view);
|
||||
} else {
|
||||
// We have finished
|
||||
document.onbeforeunload = null;
|
||||
document.getElementById('delete-day').removeAttribute('disabled');
|
||||
document.getElementById('first-view').removeAttribute('disabled');
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ var i18n = {
|
|||
delText: '<%= l('Deletion link') %>',
|
||||
dlText: '<%= l('Download link') %>',
|
||||
download: '<%= l('Download') %>',
|
||||
confirmExit: '<%= l('You have attempted to leave this page. The upload will be canceled. Are you sure?') %>',
|
||||
hit: '<%= l('Hit Enter, then Ctrl+C to copy the download link') %>',
|
||||
hits: '<%= l('Hit Enter, then Ctrl+C to copy all the download links') %>',
|
||||
}
|
||||
|
|
|
@ -20,6 +20,12 @@
|
|||
%= stylesheet '/css/cover.css'
|
||||
%= stylesheet '/css/lufi.css'
|
||||
%= stylesheet '/css/fontello.css'
|
||||
%= javascript begin
|
||||
function confirmExit() {
|
||||
console.log(i18n.confirmExit);
|
||||
return i18n.confirmExit;
|
||||
}
|
||||
% end
|
||||
</head>
|
||||
<body>
|
||||
<div class="site-wrapper">
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
var ws_url = '<%= url_for('download')->to_abs() %>';
|
||||
var i18n = {
|
||||
download: '<%= l('Download') %>',
|
||||
confirmExit: '<%= l('You have attempted to leave this page. The download will be canceled. Are you sure?') %>',
|
||||
}
|
||||
% end
|
||||
%= javascript '/js/sjcl.js'
|
||||
|
|
Loading…
Reference in New Issue