max1220 Window Manager Library - Documentation

A simple Window management library for the web.
Implemented using Vanilla JavaScript, HTML5, and CSS3.

Usage

To use the max1220 JavaScript Window manager library, simply instantiate a new WindowManager object, pass the required parameters, and register required event handlers:

let wm = new WindowManager(window_container, window_template, log_enable);
wm.register_mouse_events(window)
wm.register_message_events()

The library allows you to manage multiple windows and provides callbacks to handle various window events.

You can create a new window by calling the add_window method with a URL to load the content into an iframe. This also supports passing arguments to the window client:

wm.add_window("window.html", { my_arg: "hello world!" })

See also the section below about the WindowClient, which makes some functionality of the window manager available to the document inside the iframe.

HTML setup

In order to use this library, you need to load the stylesheet for the window decorations, and create a template HTML element.

<link rel="stylesheet" href="window_common.css">
<link rel="stylesheet" href="window_flat.css"> <!-- Theme -->
<template id="window_template">
	<div class="win">
		<nav class="win-titlebar win-drag-handle">
			<span class="win-icon">🗔</span>
			<span class="win-title win-drag-handle">Unnamed window</span>
			<button class="win-btn win-btn-minimize" onclick="wm.minimize_window(this.closest('.win'))" title="Minimize">▁</button>
			<button class="win-btn win-btn-restore hidden" onclick="wm.restore_window(this.closest('.win'))" title="Restore">🗗</button>
			<button class="win-btn win-btn-maximize" onclick="wm.maximize_window(this.closest('.win'))" title="Maximize">🗖</button>
			<button class="win-btn win-btn-close" onclick="wm.remove_window(this.closest('.win'))" title="Close">🞮</button>
		</nav>
		<iframe class="win-iframe"></iframe>
		<div class="win-resize-handle"></div>
	</div>
</template>

Mouse events and iframes

Due to how mouse events and iframes work together(or rather don't), only the currently focused window can receive mouse events. This explains why the first click on a window will focus it, but not send a click event to the iframe. Because iframes eat mouse events it is also necessary to disable mouse input during window moving/resizing.
This is done in JavaScript by setting the element pointer-events CSS attribute during moving, resizing, and during focus changes.

WindowManager Constructor

The WindowManager class manages the creation, interaction, and lifecycle of application windows.
It supports dragging, resizing, minimizing/unminimizing, maximizing/restoring, and postMessage()-based interaction between window clients and window manager.

WindowManager(window_container, window_template, log_enable)

Properties

Methods

Callbacks

Supported Classes

These classes are to be used in the window_template, and are automatically setup with the correct functionality as aproriate.

Additionally the window_container gets the has-maximized class if a window in it is maximized.

Window state classes

These classes are added/removed from a window as it's state changes.

Supported attributes

These attributes can be directly applied to the window element.


WindowClient Constructor

The WindowClient is a simple library for use inside a window's iframe document.
It enables the window to perform certain window operations on itself(close, focus, maximize, etc.), and enables a window to open other windows, optionally as dialogs with return values that block the input to the host window.

WindowClient(wm_window)

Properties

Methods

Callbacks


License

The max1220 Window Manager Library is released under the MIT license.
See license.html