Footer.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Element from './Element';
  2. import i18next from 'i18next';
  3. import joinPath from '../../joinPath';
  4. import trailingSlash from '../../trailingSlash';
  5. export default class Footer extends Element {
  6. constructor() {
  7. const template = `<footer class="upload">
  8. <span class="droppable">${i18next.t(
  9. 'dropFilesAnywhereToUpload'
  10. )}</span> ${i18next.t('or')}
  11. <span class="files">${i18next.t(
  12. 'uploadFiles'
  13. )} <input type="file" multiple></span> ${i18next.t('or')}
  14. <a href="#" class="create-directory">${i18next.t('createNewDirectory')}</a>
  15. </footer>`;
  16. super(template);
  17. this.bindEvents();
  18. }
  19. bindEvents(element = this.element) {
  20. element
  21. .querySelector('input[type="file"]')
  22. .addEventListener('change', async (event) => {
  23. for (const file of event.target.files) {
  24. this.trigger('upload', location.pathname, file);
  25. }
  26. element.value = null;
  27. });
  28. element
  29. .querySelector('.create-directory')
  30. .addEventListener('click', async (event) => {
  31. event.preventDefault();
  32. const directoryName = prompt('', i18next.t('directoryName'));
  33. if (!directoryName) {
  34. return;
  35. }
  36. this.trigger(
  37. 'create-directory',
  38. trailingSlash(joinPath(location.pathname, directoryName)),
  39. directoryName,
  40. location.pathname
  41. );
  42. });
  43. }
  44. }