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

pure-context-menu

v1.2.8

Published

Easy context menu manager for Bootstrap and vanilla js

Downloads

138

Readme

Pure Context Menu

NPM Downloads

How to use

Easily manage the right click context menu.

No additional CSS needed if you are using Bootstrap!

import PureContextMenu from "./pure-context-menu.js";

const items = [
  {
    label: "Click here",
    callback: () => {
      alert("You clicked here");
    },
  },
  "-",
  {
    label: "Target click",
    callback: (e) => {
      if (e.target.id) {
        alert("You clicked on target " + e.target.id);
      } else {
        alert("You didn't click on a target");
      }
    },
  },
  {
    label: "This is a long menu item that spans on two line",
    callback: () => {
      alert("You clicked on a long line");
    },
  },
  {
    label: "This will not close",
    preventCloseOnClick: true,
    callback: () => {
      alert("It didn't close");
    },
  },
];
// bind to html if body does not have 100% height
let bodyMenu = new PureContextMenu(document.querySelector("html"), items);

Features

Built-in styles for Bootstrap

Easy context menu use default Bootstrap styles so you don't need extra css. Otherwise, look at styles.scss to see some default styles you can use. It can either use dropdown or list groups styles.

Prevent close on click

By default, clicking on an item will close the menu. You can control this with preventCloseOnClick.

Determining target

The callback receive the event that originally opened the context menu. This allow determing the target under the context menu. If you need to adjust items based on the current target, use setItems during the show callback.

Dividers

Simply pass "-" in the list of elements to mark dividers. This doesn't work well with list group styles since items are already separated.

Mobile support

Surprisingly, modern mobile browsers translate long press to a contextmenu event that it works out of the box :-)

If it's not working, long-press is supported, simply add it to your pages

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/long-press-event.min.js" type="module"></script>

Popover api

Popover api will be used if available or fallback gracefully to fixed/z-index.

Options

Options can be either passed to the constructor (eg: optionName) or globally updated using PureContextMenu.updateGlobalOptions

| Name | Type | Description | | ------------------- | --------------------- | --------------------------------------------------------------- | | contextMenuClass | String | Class applied for holder element | | dropdownClass | String | Class applied for dropdown. Accepts space separated classes | | dividerClass | String | Class applied to the divider item | | menuItemClass | String | Class applied to the li in all cases. | | itemClass | String | Class applied to the menu item. Accepts space separated classes | | disabledClass | String | Class applied to the disabled items | | zIndex | Number | z-index assigned to the menu | | preventCloseOnClick | Boolean | Global behaviour for items when clicking | | useLists | Boolean | Enable list groups | | listClass | String | Class applied to the list | | listItemClass | String | Class applied to the list item. Accepts space separated classes | | fastClick | Boolean | Triggers click on touchstart for mobile devices | | closeIfOpen | Boolean | Close menu with right close if already opened | | show | function | Whether to show menu based on event | | minWidth | String | Defaults to 120px | | maxWidth | String | Defaults to 240px | | popover | Boolean | Use popover api if available. Allows backdrops. |

Item

| Name | Type | | --------------------- | --------------------- | | label | String | | [html] | Boolean | | [classes] | Array | | [preventCloseOnClick] | Boolean | | [disabled] | Boolean | | [callback] | function |

Demo

https://codepen.io/lekoalabe/pen/LYJbGYg

Browser supports

Modern browsers (edge, chrome, firefox, safari... not IE11). Add a warning if necessary.