2017-08-24 21:54:02 +00:00
|
|
|
const html = require('choo/html');
|
|
|
|
const assets = require('../../common/assets');
|
|
|
|
const fileList = require('./fileList');
|
2017-11-07 23:54:42 +00:00
|
|
|
const fxPromo = require('./fxPromo');
|
2017-08-24 21:54:02 +00:00
|
|
|
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>
|
2017-08-31 16:43:36 +00:00
|
|
|
<a href="https://testpilot.firefox.com/experiments/send"
|
|
|
|
class="link">${state.translate('uploadPageLearnMore')}</a>
|
2017-08-24 21:54:02 +00:00
|
|
|
</div>
|
2017-08-31 16:43:36 +00:00
|
|
|
<div class="upload-window"
|
|
|
|
ondragover=${dragover}
|
|
|
|
ondragleave=${dragleave}>
|
|
|
|
<div id="upload-img">
|
|
|
|
<img src="${assets.get('upload.svg')}"
|
|
|
|
title="${state.translate('uploadSvgAlt')}"/>
|
|
|
|
</div>
|
2017-08-24 21:54:02 +00:00
|
|
|
<div id="upload-text">${state.translate('uploadPageDropMessage')}</div>
|
2017-08-31 16:43:36 +00: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 13:00:58 +00:00
|
|
|
<label for="file-upload"
|
|
|
|
id="browse"
|
|
|
|
class="btn browse"
|
|
|
|
title="${state.translate('uploadPageBrowseButton1')}">
|
|
|
|
${state.translate('uploadPageBrowseButton1')}</label>
|
2017-08-24 21:54:02 +00:00
|
|
|
</div>
|
2017-11-07 23:54:42 +00:00
|
|
|
${state.promo === 'body' ? fxPromo(state, emit) : ''}
|
2017-08-24 21:54:02 +00:00
|
|
|
${fileList(state, emit)}
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
function dragover(event) {
|
2017-08-29 18:36:40 +00:00
|
|
|
const div = document.querySelector('.upload-window');
|
|
|
|
div.classList.add('ondrag');
|
2017-08-24 21:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function dragleave(event) {
|
2017-08-29 18:36:40 +00:00
|
|
|
const div = document.querySelector('.upload-window');
|
|
|
|
div.classList.remove('ondrag');
|
2017-08-24 21:54:02 +00:00
|
|
|
}
|
|
|
|
|
2017-09-12 23:49:50 +00:00
|
|
|
function onfocus(event) {
|
|
|
|
event.target.classList.add('has-focus');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onblur(event) {
|
|
|
|
event.target.classList.remove('has-focus');
|
|
|
|
}
|
|
|
|
|
2017-08-24 21:54:02 +00:00
|
|
|
async function upload(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
const target = event.target;
|
|
|
|
const file = target.files[0];
|
2017-08-29 18:20:34 +00:00
|
|
|
if (file.size === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-24 21:54:02 +00:00
|
|
|
await fadeOut('page-one');
|
|
|
|
emit('upload', { file, type: 'click' });
|
|
|
|
}
|
|
|
|
return div;
|
|
|
|
};
|