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

simple_js_menu

v1.0.3

Published

Simple customizable context menus for JavaScript

Downloads

8

Readme

Simple Javascript Menu

A JavaScript library to create a context menus for your web pages.

Demo

Install

Download the library file context_menu.umd.cjs and include it to your web page:

<script src="context_menu.umd.cjs"></script>

or, if you develop project with JavaScript framework, you can install it using NPM:

npm install simple_js_menu

and import to your JavaScript code:

import {Menus} from "simple_js_menu";

Use

After install the library using one of two way above, you have Menus factory object in global namespace, which can be used to construct and setup menus.

Please see the basic example of how to construct and setup the menu:

<html>
<head>
    <title>Context Menu Demo</title>
    <script src="https://code.germanov.dev/context_menu/context_menu.umd.cjs"></script>
</head>
<body>
<div id="myDiv">My element</div>

<script>
    // obtain a link to the element 
    const div = document.getElementById("myDiv");
    
    // define menu items
    const items = [
        {id:"item1", title: "Item 1"},
        {id:"item2", title: "Item 2"},
        {id:"item3", title: "Item 3"}
    ];
    
    // create menu with specified items
    // and bind it to specified DIV element
    const menu = Menus.create(items,div);

    // react when user clicks on menu items
    menu.on('click', (event) => {
        // run different actions depending on ID of item
        // on which user has clicked
        switch (event.itemId) {
            case "item1":
                console.log("User clicked first item");
                console.log("Mouse cursor position X:",
                        event.cursorX,"Y:",event.cursorY);
                break;
            case "item2":
                console.log("User clicked second item");
                console.log("Mouse cursor position X:",
                        event.cursorX,"Y:",event.cursorY);
                break;
            case "item3":
                console.log("User clicked third item");
                console.log("Mouse cursor position X:",
                        event.cursorX,"Y:",event.cursorY);
                break;
        }
    })
</script>
</body>
</html>

This page will display a DIV with My Element text. When you right-click on it, it will display a simple menu:

Simple menu demo

When you click on any item, the menu.on method will react to your click and display appropriate text in JavaScript console.

Documentation and examples

Read more advanced tutorial here:

https://dev.to/andreygermanov/simple-way-to-add-custom-context-menus-to-web-pages-10lc

Full API documentation for Menu object you can find here:

https://github.com/AndreyGermanov/context_menu/blob/main/docs/API.md

Please, try the SmartShape Studio which uses context menus, created by this library to edit vector shapes:

https://shapes.germanov.dev