2017-12-21 10:47:31 +01:00
|
|
|
/* global MAXFILESIZE */
|
2017-08-24 23:54:02 +02:00
|
|
|
const html = require('choo/html');
|
|
|
|
const assets = require('../../common/assets');
|
2018-01-30 21:15:09 +01:00
|
|
|
const fileList = require('../templates/fileList');
|
2017-12-21 10:47:31 +01:00
|
|
|
const { bytes, fadeOut } = require('../utils');
|
2017-08-24 23:54:02 +02:00
|
|
|
|
|
|
|
module.exports = function(state, emit) {
|
2018-02-05 22:28:38 +01:00
|
|
|
// the page flickers if both the server and browser set 'fadeIn'
|
|
|
|
const fade = state.layout ? '' : 'fadeIn';
|
2017-08-24 23:54:02 +02:00
|
|
|
const div = 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>
|
2017-08-31 18:43:36 +02:00
|
|
|
<div class="upload-window"
|
|
|
|
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>
|
2017-08-24 23:54:02 +02:00
|
|
|
<div id="upload-text">${state.translate('uploadPageDropMessage')}</div>
|
2017-08-31 18:43:36 +02:00
|
|
|
<span id="file-size-msg">
|
|
|
|
<em>${state.translate('uploadPageSizeMessage')}</em>
|
|
|
|
</span>
|
|
|
|
<input id="file-upload"
|
|
|
|
type="file"
|
|
|
|
name="fileUploaded"
|
|
|
|
onfocus=${onfocus}
|
|
|
|
onblur=${onblur}
|
|
|
|
onchange=${upload} />
|
2017-11-05 14:00:58 +01:00
|
|
|
<label for="file-upload"
|
|
|
|
id="browse"
|
|
|
|
class="btn browse"
|
|
|
|
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) {
|
2017-08-29 20:36:40 +02:00
|
|
|
const div = document.querySelector('.upload-window');
|
|
|
|
div.classList.add('ondrag');
|
2017-08-24 23:54:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function dragleave(event) {
|
2017-08-29 20:36:40 +02:00
|
|
|
const div = document.querySelector('.upload-window');
|
|
|
|
div.classList.remove('ondrag');
|
2017-08-24 23:54:02 +02:00
|
|
|
}
|
|
|
|
|
2017-09-13 01:49:50 +02:00
|
|
|
function onfocus(event) {
|
|
|
|
event.target.classList.add('has-focus');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onblur(event) {
|
|
|
|
event.target.classList.remove('has-focus');
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-08-24 23:54:02 +02:00
|
|
|
await fadeOut('page-one');
|
|
|
|
emit('upload', { file, type: 'click' });
|
|
|
|
}
|
|
|
|
return div;
|
|
|
|
};
|