diff options
author | Alex Vitkov <alexvitkov98@gmail.com> | 2021-03-20 10:58:25 +0200 |
---|---|---|
committer | Alex Vitkov <alexvitkov98@gmail.com> | 2021-03-20 10:58:25 +0200 |
commit | 0255b5f7f31c4c6caefc736c59ba6959d671a92d (patch) | |
tree | 0bdad18ce5a702b7133b5169fb40d7951a8c105e /front/window.ts | |
parent | cb3949d974f30501281fd2546ef23c81ac0282b3 (diff) | |
download | fileup-0255b5f7f31c4c6caefc736c59ba6959d671a92d.tar.gz |
Broke up loggedin.js into modules
Diffstat (limited to 'front/window.ts')
-rw-r--r-- | front/window.ts | 104 |
1 files changed, 96 insertions, 8 deletions
diff --git a/front/window.ts b/front/window.ts index 79d053b..eb81095 100644 --- a/front/window.ts +++ b/front/window.ts @@ -1,5 +1,21 @@ +import { mk } from './util'; -export class OurWindow { +// An array with all the windows on the screen +export var windows: BaseWindow[] = []; + +// The focused window +export var focused_window: BaseWindow = null; + + +import * as drag from './dragging' + + +// Windows have a z-index. When we click a window it is sent to the top this will be its new z-index +// We then increment the depth, and the next window we click will go on top of the current one +var depth = 20; + + +export class BaseWindow { pwd: string[]; visuals: HTMLElement; h2: HTMLElement; // The titlebar of the window @@ -7,19 +23,91 @@ export class OurWindow { files: any[]; txt_editor: HTMLElement; // For editable text files, this is the DOM element the user can edit - // TODO move these to a subclass - foldercontents: any; - filecontents: any; - filecontentsroot: any; - filegrid: any; - save_btn_container: any; - constructor(pwd) { + constructor(pwd, x, y, w, h) { this.pwd = pwd; // pwd = [ "Folder1", "Folder2" ] means the current directory of that window is /Folder1/Folder2 this.visuals = null; // The DOM object this.h2 = null; // The titlebar of the window this.fileview = null; this.files = []; this.txt_editor = null; // For editable text files, this is the DOM element the user can edit + + make_window_base(this, pwd, x, y, w, h); + } + + destroy() { + var index = windows.indexOf(this); + + if (index >= 0) + windows.splice(index, 1); + + this.visuals.parentNode.removeChild(this.visuals); + if (this == focused_window) + focused_window = null; + } + + focus() { + if (focused_window == this) + return; + + // Unfocus the old window + if (focused_window) + focused_window.visuals.classList.remove('focus'); + + focused_window = this; + // And focus the new one! + this.visuals.classList.add('focus'); + this.visuals.style.zIndex = (depth++).toString(); } + + get_path(max_length?: number) { + if (max_length == undefined) { + max_length = this.pwd.length; + } + + var path = "/"; + for (let i = 0; i < max_length; i++) { + path += this.pwd[i]; + if (i != max_length - 1) + path += "/"; + } + return path; + } +} + + + +export function unfocus_window() { + if (focused_window) { + focused_window.visuals.classList.remove('focus'); + focused_window = null; + } +} + + +// This creates the parts of a window that are common between all window types +// This should only really be called by another function that will then fill up the window +function make_window_base(wnd, pwd, x, y, w, h) { + windows.push(wnd); + + wnd.visuals = mk(document.body, 'div', 'window'); + + wnd.visuals.style.width = w + "px"; + wnd.visuals.style.height = h ? (h + "px") : "unset"; + wnd.visuals.style.position = "absolute"; + wnd.visuals.style.left = x + "px"; + wnd.visuals.style.top = y + "px"; + + wnd.h2 = mk(wnd.visuals, 'h2'); + + wnd.visuals.onmousedown = (_e) => { + wnd.focus(); + } + + wnd.h2.onmousedown = (e) => { + if (!drag.dragging) + drag.set_dragging_candidate(e, wnd.visuals); + }; + + return wnd; }
\ No newline at end of file |