1
0
mirror of https://gitlab.com/timvisee/send.git synced 2024-11-11 21:52:39 +01:00
send/app/templates/welcome.js

63 lines
1.9 KiB
JavaScript
Raw Normal View History

const html = require('choo/html');
const assets = require('../../common/assets');
const fileList = require('./fileList');
const { fadeOut } = require('../utils');
module.exports = function(state, emit) {
const div = html`
<div id="page-one" class="fadeIn">
<div class="title">${state.translate('uploadPageHeader')}</div>
<div class="description">
<div>${state.translate('uploadPageExplainer')}</div>
<a href="https://testpilot.firefox.com/experiments/send" class="link">${state.translate(
'uploadPageLearnMore'
)}</a>
</div>
2017-09-12 02:09:29 +02:00
<div class="${state.config
.uploadWindowStyle}" ondragover=${dragover} ondragleave=${dragleave}>
<div id="upload-img"><img src="${assets.get(
'upload.svg'
)}" title="${state.translate('uploadSvgAlt')}"/></div>
<div id="upload-text">${state.translate('uploadPageDropMessage')}</div>
<span id="file-size-msg"><em>${state.translate(
'uploadPageSizeMessage'
)}</em></span>
<form method="post" action="upload" enctype="multipart/form-data">
2017-09-12 02:09:29 +02:00
<label for="file-upload" id="browse" class="${state.config
.uploadButtonStyle}">${state.translate(
'uploadPageBrowseButton1'
)}</label>
<input id="file-upload" type="file" name="fileUploaded" onchange=${upload} />
</form>
</div>
${fileList(state, emit)}
</div>
`;
function dragover(event) {
2017-08-29 20:36:40 +02:00
const div = document.querySelector('.upload-window');
div.classList.add('ondrag');
}
function dragleave(event) {
2017-08-29 20:36:40 +02:00
const div = document.querySelector('.upload-window');
div.classList.remove('ondrag');
}
async function upload(event) {
event.preventDefault();
const target = event.target;
const file = target.files[0];
2017-08-29 20:20:34 +02:00
if (file.size === 0) {
return;
}
await fadeOut('page-one');
emit('upload', { file, type: 'click' });
}
if (state.layout) {
return state.layout(state, div);
}
return div;
};