UI.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import supportsEvent, { supportsEvents } from '../lib/supportsEvent';
  2. import AbstractUI from '../lib/AbstractUI';
  3. import handleFileUpload from '../lib/handleFileUpload';
  4. export class UI extends AbstractUI {
  5. protected bindEvents(): void {
  6. const isTouch = supportsEvent('touchstart'),
  7. supportsDragDrop = supportsEvents('dragstart', 'drop');
  8. // DOM events
  9. if (isTouch) {
  10. this.addClass('is-touch');
  11. }
  12. if (!supportsDragDrop) {
  13. this.addClass('no-drag-drop');
  14. }
  15. if (supportsDragDrop) {
  16. this.onEach(['dragenter', 'dragover'], (event: DragEvent): void => {
  17. event.preventDefault();
  18. event.stopPropagation();
  19. this.addClass('active');
  20. });
  21. this.onEach(['dragleave', 'drop'], (event: DragEvent): void => {
  22. event.preventDefault();
  23. event.stopPropagation();
  24. this.removeClass('active');
  25. });
  26. this.on('drop', async (event: DragEvent): Promise<void> => {
  27. const { files } = event.dataTransfer;
  28. for (const file of files) {
  29. await handleFileUpload(this.dav(), this.state(), file);
  30. }
  31. });
  32. }
  33. }
  34. }
  35. export default UI;