2017-12-21 10:47:31 +01:00
|
|
|
/* global MAXFILESIZE */
|
2017-08-24 23:54:02 +02:00
|
|
|
const html = require('choo/html');
|
2018-02-13 20:32:59 +01:00
|
|
|
const assets = require('../../../common/assets');
|
|
|
|
const fileList = require('../../templates/fileList');
|
|
|
|
const { bytes, fadeOut } = require('../../utils');
|
2017-08-24 23:54:02 +02:00
|
|
|
|
|
|
|
module.exports = function(state, emit) {
|
2018-02-13 20:32:59 +01:00
|
|
|
// the page flickers if both the server and browser set 'effect--fadeIn'
|
|
|
|
const fade = state.layout ? '' : 'effect--fadeIn';
|
2018-02-16 21:56:53 +01:00
|
|
|
return html`
|
2018-02-05 22:28:38 +01:00
|
|
|
<div id="page-one" class="${fade}">
|
2017-08-24 23:54:02 +02:00
|
|
|
<div class="title">${state.translate('uploadPageHeader')}</div>
|
|
|
|
<div class="description">
|
|
|
|
<div>${state.translate('uploadPageExplainer')}</div>
|
2018-01-24 19:23:13 +01:00
|
|
|
<a
|
|
|
|
href="https://testpilot.firefox.com/experiments/send"
|
|
|
|
class="link">
|
|
|
|
${state.translate('uploadPageLearnMore')}
|
|
|
|
</a>
|
2017-08-24 23:54:02 +02:00
|
|
|
</div>
|
2018-02-13 20:32:59 +01:00
|
|
|
<div class="uploadArea"
|
2017-08-31 18:43:36 +02:00
|
|
|
ondragover=${dragover}
|
|
|
|
ondragleave=${dragleave}>
|
|
|
|
<div id="upload-img">
|
2018-01-24 19:23:13 +01:00
|
|
|
<img
|
|
|
|
src="${assets.get('upload.svg')}"
|
2017-08-31 18:43:36 +02:00
|
|
|
title="${state.translate('uploadSvgAlt')}"/>
|
|
|
|
</div>
|
2018-02-13 20:32:59 +01:00
|
|
|
<div class="uploadArea__msg">
|
|
|
|
${state.translate('uploadPageDropMessage')}
|
|
|
|
</div>
|
|
|
|
<span class="uploadArea__sizeMsg">
|
|
|
|
${state.translate('uploadPageSizeMessage')}
|
2017-08-31 18:43:36 +02:00
|
|
|
</span>
|
|
|
|
<input id="file-upload"
|
2018-02-13 20:32:59 +01:00
|
|
|
class="inputFile"
|
2017-08-31 18:43:36 +02:00
|
|
|
type="file"
|
|
|
|
name="fileUploaded"
|
|
|
|
onfocus=${onfocus}
|
|
|
|
onblur=${onblur}
|
|
|
|
onchange=${upload} />
|
2017-11-05 14:00:58 +01:00
|
|
|
<label for="file-upload"
|
2018-02-13 20:32:59 +01:00
|
|
|
class="btn btn--file"
|
2017-11-05 14:00:58 +01:00
|
|
|
title="${state.translate('uploadPageBrowseButton1')}">
|
2018-01-24 19:23:13 +01:00
|
|
|
${state.translate('uploadPageBrowseButton1')}
|
|
|
|
</label>
|
2017-08-24 23:54:02 +02:00
|
|
|
</div>
|
|
|
|
${fileList(state, emit)}
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
function dragover(event) {
|
2018-02-13 20:32:59 +01:00
|
|
|
const div = document.querySelector('.uploadArea');
|
|
|
|
div.classList.add('uploadArea--dragging');
|
2017-08-24 23:54:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function dragleave(event) {
|
2018-02-13 20:32:59 +01:00
|
|
|
const div = document.querySelector('.uploadArea');
|
|
|
|
div.classList.remove('uploadArea--dragging');
|
2017-08-24 23:54:02 +02:00
|
|
|
}
|
|
|
|
|
2017-09-13 01:49:50 +02:00
|
|
|
function onfocus(event) {
|
2018-02-13 20:32:59 +01:00
|
|
|
event.target.classList.add('inputFile--focused');
|
2017-09-13 01:49:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onblur(event) {
|
2018-02-13 20:32:59 +01:00
|
|
|
event.target.classList.remove('inputFile--focused');
|
2017-09-13 01:49:50 +02:00
|
|
|
}
|
|
|
|
|
2017-08-24 23:54:02 +02:00
|
|
|
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;
|
|
|
|
}
|
2017-12-21 10:47:31 +01:00
|
|
|
if (file.size > MAXFILESIZE) {
|
|
|
|
window.alert(state.translate('fileTooBig', { size: bytes(MAXFILESIZE) }));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-13 20:32:59 +01:00
|
|
|
await fadeOut('#page-one');
|
2017-08-24 23:54:02 +02:00
|
|
|
emit('upload', { file, type: 'click' });
|
|
|
|
}
|
|
|
|
};
|