diff options
author | Alex Vitkov <alexvitkov98@gmail.com> | 2021-03-25 10:46:07 +0200 |
---|---|---|
committer | Alex Vitkov <alexvitkov98@gmail.com> | 2021-03-25 10:46:07 +0200 |
commit | b377a01261b6356c8b13b73bece635056e38efe6 (patch) | |
tree | d791e2cf2324807800a778f763150c70557efb6d /front/dragging.ts | |
parent | 0255b5f7f31c4c6caefc736c59ba6959d671a92d (diff) | |
download | fileup-b377a01261b6356c8b13b73bece635056e38efe6.tar.gz |
asdf
Diffstat (limited to 'front/dragging.ts')
-rw-r--r-- | front/dragging.ts | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/front/dragging.ts b/front/dragging.ts index f01e414..b65f1f4 100644 --- a/front/dragging.ts +++ b/front/dragging.ts @@ -1,23 +1,42 @@ -import { FileView } from './explorer'; + +export class Draggable { + el: HTMLElement; + + canDragX: boolean = true; + canDragY: boolean = true; + reparent: boolean = true; + + lockSize: boolean = true; + + onBeforeDragStart: () => void = null; + onAfterDragEnd: () => void = null; + + Draggable(el: HTMLElement) { + this.el = el; + } +} + + + // If we're currently dragging something (a window or a file), this is the DOM object we're dragging // dragging_offset_x and dragging_offset_y are the difference between the objec's top left point and the cursor position // this is then added to the cursor position when the mouse is moved -export var dragging = null; +export var dragging: Draggable = null; export var dragging_offset_x = 0, dragging_offset_y = 0; // If we have pressed down a window's title bar but haven't yet started dragging it, it's the drag candidate // This is needed because we don't yet know whether we want to start dragging the window or click an element in the titlebar // Once the mouse has moved sufficiently far away from dragging_candidate_x or y, we start dragging -export var dragging_candidate: HTMLElement = null; +export var dragging_candidate: Draggable = null; export var dragging_candidate_x, dragging_candidate_y; // If we're dragging a fileview, this is set to the fileview class instance itself, because 'dragging' is just a DOM object // The placeholder is a dummy DIV that we insert in the object's place on the grid to keep things nicely aligned -export var dragging_fileview: FileView; -export var dragging_placeholder = null; +// export var dragging_fileview: FileView; +// export var dragging_placeholder = null; -export function set_dragging_candidate(e, candidate: HTMLElement) { +export function set_dragging_candidate(e, candidate: Draggable) { dragging_candidate = candidate; dragging_candidate_x = e.clientX; dragging_candidate_y = e.clientY; @@ -26,29 +45,29 @@ export function set_dragging_candidate(e, candidate: HTMLElement) { // Start dragging the 'obj' DOM element // e is a DOM event, this should only get called in response of a DOM event -export function begin_drag(e, obj: HTMLElement, dont_set_width?: boolean) { +export function begin_drag(e, d: Draggable) { set_iframe_enabled(false); - dragging = obj; + dragging = d; dragging_candidate = null; - dragging.classList.add("dragged"); + dragging.el.classList.add("dragged"); - var elemRect = dragging.getBoundingClientRect(); + var elemRect = dragging.el.getBoundingClientRect(); dragging_offset_x = e.clientX - elemRect.left; dragging_offset_y = -e.clientY + elemRect.top; - if (dragging_placeholder) - obj.parentNode.insertBefore(dragging_placeholder, obj); + //if (dragging_placeholder) + // dragging.el.parentNode.insertBefore(dragging_placeholder, dragging.el); - dragging.style.left = (e.clientX - dragging_offset_x) + "px"; - dragging.style.top = (e.clientY + dragging_offset_y) + "px"; + dragging.el.style.left = (e.clientX - dragging_offset_x) + "px"; + dragging.el.style.top = (e.clientY + dragging_offset_y) + "px"; - if (!dont_set_width) { - dragging.style.width = elemRect.width + "px"; - dragging.style.height = elemRect.height + "px"; + if (dragging.lockSize) { + dragging.el.style.width = elemRect.width + "px"; + dragging.el.style.height = elemRect.height + "px"; } - dragging.style.position = "absolute"; - document.body.appendChild(dragging); + dragging.el.style.position = "absolute"; + document.body.appendChild(dragging.el); } export function end_drag(_e) { |