npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dom-window-manager

v1.0.3

Published

DOM Window Manager is a simple window manager for DOM elements

Downloads

77

Readme

DOM Window Manager logo

DOM Window Manager

A simple window manager for DOM elements

Demo 1

Demo 2

Repository

npm package

What it does

  1. Makes DOM elements draggable
  2. Moves an element on top of all other draggable elements (ex. when clicked)

Description

DOM Window Manager consists of a single class, WindowManager, and a set of utility functions. WindowManager uses the singleton pattern, effectively restricting the instantiation of the class to a singular instance to be used by all components, in any file.

Instructions

At first, you need to import WindowManager and dragElement in each file that you create elements that you want to use with the DOM Window Manager. WindowManager is the class that manages the elements and dragElement is the utility function that makes elements draggable.

import { WindowManager, dragElement }  from "dom-window-manager";

Then, you have to instanciate the window manager in each file as well.

let windowManager = new WindowManager();

It takes an optional parameter, base, that is the initial z-index value that all elements will have. If no value is provided, base defaults to 1.

Then, at some point you will create an element

const element = document.createElement("div");

It could be any type of element (p, h1, div etc.). The only prerequisite, is to set its position attribute to absolute. It can be done either in JavaScript of in the CSS file.

element.style.position = "absolute";

You can now call the dragElement function, with the element as its parameter.

dragElement(element);

You also need to set the elements z-index value to the base provided by WindowManager.

element.style.zIndex = windowManager.base;

Finally, you will probably want to make the element come on top of all other elements when clicked.

element.addEventListener("mousedown", () => {
    element.style.zIndex = windowManager.moveOnTop();
});

As you have seen, DOM Window Manager takes a very minimalist approach, providing you with the bare necessities, and giving you absolute freedom to use it as you see fit for your project.

All the code

import { WindowManager, dragElement }  from "dom-window-manager";

let windowManager = new WindowManager();
const element = document.createElement("div");
element.style.position = "absolute";
dragElement(element);
element.style.zIndex = windowManager.base;

element.addEventListener("mousedown", () => {
    element.style.zIndex = windowManager.moveOnTop();
});

License

Copyright (c) 2023 Michael Kolesidis Licensed under the GNU Affero General Public License v3.0.