diff --git a/frontend/src/upload.js b/frontend/src/upload.js index 40ee4b90..999fa4eb 100644 --- a/frontend/src/upload.js +++ b/frontend/src/upload.js @@ -1,16 +1,18 @@ const FileSender = require('./fileSender'); $(document).ready(function() { + // reset copy button let copyBtn = $('#copy-btn'); copyBtn.attr('disabled', false); copyBtn.html('Copy'); + $('#page-one').show(); $('#file-list').hide(); $('#upload-progress').hide(); $('#share-link').hide(); + // copy link to clipboard copyBtn.click(() => { - console.log('copied'); var aux = document.createElement('input'); aux.setAttribute('value', $('#link').attr('value')); document.body.appendChild(aux); @@ -20,6 +22,8 @@ $(document).ready(function() { copyBtn.attr('disabled', true); copyBtn.html('Copied!'); }); + + // link back to home page $('.send-new').click(() => { $('#page-one').show(); $('#file-list').show(); @@ -29,25 +33,46 @@ $(document).ready(function() { copyBtn.html('Copy'); }); - let onChange = event => { - const file = event.target.files[0]; - + // 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]; + } let fileList = $('#uploaded-files'); let row = document.createElement('tr'); let name = document.createElement('td'); let link = document.createElement('td'); let expiry = document.createElement('td'); - + let del = document.createElement('td'); + let btn = document.createElement('button'); + let popupDiv = document.createElement('div'); + let $popupText = $('', {'class': 'popuptext'}); let cellText = document.createTextNode(file.name); + let progress = document.createElement('p'); name.appendChild(cellText); - let progress = document.createElement('p'); + // create delete button + btn.innerHTML = 'x'; + btn.classList.add('delete-btn'); + // create popup + popupDiv.classList.add('popup'); + $popupText.html("Delete Nevermind"); + + // add data cells to table row row.appendChild(name); row.appendChild(link); row.appendChild(expiry); - fileList.append(row); + popupDiv.appendChild(btn); + $(popupDiv).append($popupText); + del.appendChild(popupDiv); + row.appendChild(del); + fileList.append(row); //add row to table const fileSender = new FileSender(file); fileSender.on('progress', percentComplete => { @@ -62,25 +87,34 @@ $(document).ready(function() { $('#link').attr('value', url); link.innerHTML = url; localStorage.setItem(info.fileId, info.deleteToken); - let del = document.createElement('td'); - let btn = document.createElement('button'); - btn.innerHTML = 'x'; - btn.classList.add('delete-btn'); - btn.addEventListener('click', e => { + + // delete file + console.log($popupText.first()); + $popupText.find(".del-file").click(e => { FileSender.delete( info.fileId, localStorage.getItem(info.fileId) ).then(() => { - e.target.parentNode.parentNode.remove(); + e.target.parentNode.parentNode.parentNode.parentNode.remove(); localStorage.removeItem(info.fileId); }); }); - del.appendChild(btn); - row.appendChild(del); + + // show popup + btn.addEventListener('click', e => { + $popupText.toggleClass('show'); + }); + // hide popup + $popupText.find(".nvm").click( e => { + $popupText.toggleClass('show'); + }); $('#upload-progress').hide(); $('#share-link').show(); }); }; - window.onChange = onChange; + window.allowDrop = function(ev) { + ev.preventDefault(); + } + }); diff --git a/public/main.css b/public/main.css index 2329feb7..20fb6242 100644 --- a/public/main.css +++ b/public/main.css @@ -28,7 +28,7 @@ input, select, textarea, button { .title { font-size: 14px; width: 80%; - margin: 50px auto; + margin: 40px auto; text-align: center; } @@ -108,6 +108,59 @@ td { cursor: pointer; } +/* Popup container */ +.popup { + position: relative; + display: inline-block; + cursor: pointer; +} + +/* The actual popup (appears on top) */ +.popup .popuptext { + visibility: hidden; + width: 160px; + background-color: #555; + color: #fff; + text-align: center; + border-radius: 6px; + padding: 8px 0; + position: absolute; + z-index: 1; + bottom: 125%; + left: 50%; + margin-left: -80px; +} + +/* Popup arrow */ +.popup .popuptext::after { + content: ""; + position: absolute; + top: 100%; + left: 50%; + margin-left: -5px; + border-width: 5px; + border-style: solid; + border-color: #555 transparent transparent transparent; +} + +/* Toggle this class when clicking on the popup container (hide and show the popup) */ +.popup .show { + visibility: visible; + -webkit-animation: fadeIn 1s; + animation: fadeIn 1s +} + +/* Add animation (fade in the popup) */ +@-webkit-keyframes fadeIn { + from {opacity: 0;} + to {opacity: 1;} +} + +@keyframes fadeIn { + from {opacity: 0;} + to {opacity:1 ;} +} + /** upload-progress **/ diff --git a/views/index.handlebars b/views/index.handlebars index d44e98e0..fa46a515 100644 --- a/views/index.handlebars +++ b/views/index.handlebars @@ -14,7 +14,7 @@
Share your files quickly, privately and securely.
-
+
DRAG & DROP @@ -26,7 +26,7 @@
- +
@@ -41,7 +41,9 @@ Expires in Delete -
+