2017-06-02 03:59:27 +00:00
|
|
|
const FileSender = require('./fileSender');
|
2017-06-01 22:10:00 +00:00
|
|
|
|
2017-06-06 21:24:51 +00:00
|
|
|
$(document).ready(function() {
|
2017-06-08 19:57:56 +00:00
|
|
|
// reset copy button
|
2017-06-06 21:23:10 +00:00
|
|
|
let copyBtn = $('#copy-btn');
|
2017-06-06 21:24:51 +00:00
|
|
|
copyBtn.attr('disabled', false);
|
|
|
|
copyBtn.html('Copy');
|
2017-06-08 19:57:56 +00:00
|
|
|
|
2017-06-06 21:23:10 +00:00
|
|
|
$('#page-one').show();
|
|
|
|
$('#file-list').hide();
|
|
|
|
$('#upload-progress').hide();
|
|
|
|
$('#share-link').hide();
|
2017-06-01 22:10:00 +00:00
|
|
|
|
2017-06-08 19:57:56 +00:00
|
|
|
// copy link to clipboard
|
2017-06-06 21:24:51 +00:00
|
|
|
copyBtn.click(() => {
|
|
|
|
var aux = document.createElement('input');
|
|
|
|
aux.setAttribute('value', $('#link').attr('value'));
|
2017-06-06 21:23:10 +00:00
|
|
|
document.body.appendChild(aux);
|
|
|
|
aux.select();
|
2017-06-06 21:24:51 +00:00
|
|
|
document.execCommand('copy');
|
2017-06-06 21:23:10 +00:00
|
|
|
document.body.removeChild(aux);
|
2017-06-06 21:24:51 +00:00
|
|
|
copyBtn.attr('disabled', true);
|
|
|
|
copyBtn.html('Copied!');
|
2017-06-06 21:23:10 +00:00
|
|
|
});
|
2017-06-08 19:57:56 +00:00
|
|
|
|
|
|
|
// link back to home page
|
2017-06-06 21:24:51 +00:00
|
|
|
$('.send-new').click(() => {
|
2017-06-06 21:23:10 +00:00
|
|
|
$('#page-one').show();
|
|
|
|
$('#file-list').show();
|
|
|
|
$('#upload-progress').hide();
|
|
|
|
$('#share-link').hide();
|
2017-06-06 21:24:51 +00:00
|
|
|
copyBtn.attr('disabled', false);
|
|
|
|
copyBtn.html('Copy');
|
2017-06-06 21:23:10 +00:00
|
|
|
});
|
2017-06-01 22:12:30 +00:00
|
|
|
|
2017-06-08 19:57:56 +00:00
|
|
|
// on file upload by browse or drag & drop
|
|
|
|
window.onUpload = event => {
|
|
|
|
event.preventDefault();
|
|
|
|
let file = "";
|
|
|
|
if (event.type == "drop"){
|
|
|
|
file = event.dataTransfer.files[0];
|
|
|
|
} else {
|
|
|
|
file = event.target.files[0];
|
|
|
|
}
|
2017-06-06 21:23:10 +00:00
|
|
|
let fileList = $('#uploaded-files');
|
|
|
|
let row = document.createElement('tr');
|
|
|
|
let name = document.createElement('td');
|
|
|
|
let link = document.createElement('td');
|
|
|
|
let expiry = document.createElement('td');
|
2017-06-08 19:57:56 +00:00
|
|
|
let del = document.createElement('td');
|
|
|
|
let btn = document.createElement('button');
|
|
|
|
let popupDiv = document.createElement('div');
|
|
|
|
let $popupText = $('<span>', {'class': 'popuptext'});
|
2017-06-06 21:23:10 +00:00
|
|
|
let cellText = document.createTextNode(file.name);
|
2017-06-08 19:57:56 +00:00
|
|
|
let progress = document.createElement('p');
|
2017-06-01 17:54:17 +00:00
|
|
|
|
2017-06-06 21:23:10 +00:00
|
|
|
name.appendChild(cellText);
|
2017-06-01 22:10:00 +00:00
|
|
|
|
2017-06-08 19:57:56 +00:00
|
|
|
// create delete button
|
|
|
|
btn.innerHTML = 'x';
|
|
|
|
btn.classList.add('delete-btn');
|
|
|
|
|
|
|
|
// create popup
|
|
|
|
popupDiv.classList.add('popup');
|
|
|
|
$popupText.html("<span class='del-file'>Delete</span><span class='nvm'> Nevermind</span>");
|
2017-06-06 21:23:10 +00:00
|
|
|
|
2017-06-08 19:57:56 +00:00
|
|
|
// add data cells to table row
|
2017-06-06 21:23:10 +00:00
|
|
|
row.appendChild(name);
|
|
|
|
row.appendChild(link);
|
|
|
|
row.appendChild(expiry);
|
2017-06-08 19:57:56 +00:00
|
|
|
popupDiv.appendChild(btn);
|
|
|
|
$(popupDiv).append($popupText);
|
|
|
|
del.appendChild(popupDiv);
|
|
|
|
row.appendChild(del);
|
|
|
|
fileList.append(row); //add row to table
|
2017-06-06 21:23:10 +00:00
|
|
|
|
|
|
|
const fileSender = new FileSender(file);
|
|
|
|
fileSender.on('progress', percentComplete => {
|
|
|
|
$('#page-one').hide();
|
|
|
|
$('#file-list').hide();
|
|
|
|
$('#upload-progress').show();
|
|
|
|
$('#upload-filename').innerHTML += file.name;
|
|
|
|
progress.innerText = `Progress: ${percentComplete}%`;
|
2017-06-02 03:59:27 +00:00
|
|
|
});
|
2017-06-06 21:23:10 +00:00
|
|
|
fileSender.upload().then(info => {
|
2017-06-06 17:24:58 +00:00
|
|
|
const url = info.url.trim() + `#${info.secretKey}`.trim();
|
2017-06-06 21:24:51 +00:00
|
|
|
$('#link').attr('value', url);
|
|
|
|
link.innerHTML = url;
|
|
|
|
localStorage.setItem(info.fileId, info.deleteToken);
|
2017-06-08 19:57:56 +00:00
|
|
|
|
|
|
|
// delete file
|
|
|
|
console.log($popupText.first());
|
|
|
|
$popupText.find(".del-file").click(e => {
|
2017-06-06 21:24:51 +00:00
|
|
|
FileSender.delete(
|
|
|
|
info.fileId,
|
|
|
|
localStorage.getItem(info.fileId)
|
|
|
|
).then(() => {
|
2017-06-08 19:57:56 +00:00
|
|
|
e.target.parentNode.parentNode.parentNode.parentNode.remove();
|
2017-06-06 21:24:51 +00:00
|
|
|
localStorage.removeItem(info.fileId);
|
2017-06-06 21:23:10 +00:00
|
|
|
});
|
|
|
|
});
|
2017-06-08 19:57:56 +00:00
|
|
|
|
|
|
|
// show popup
|
|
|
|
btn.addEventListener('click', e => {
|
|
|
|
$popupText.toggleClass('show');
|
|
|
|
});
|
|
|
|
// hide popup
|
|
|
|
$popupText.find(".nvm").click( e => {
|
|
|
|
$popupText.toggleClass('show');
|
|
|
|
});
|
2017-06-06 21:24:51 +00:00
|
|
|
$('#upload-progress').hide();
|
|
|
|
$('#share-link').show();
|
|
|
|
});
|
|
|
|
};
|
2017-06-01 22:10:00 +00:00
|
|
|
|
2017-06-08 19:57:56 +00:00
|
|
|
window.allowDrop = function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
|
2017-06-06 21:24:51 +00:00
|
|
|
});
|