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