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

bootstrap-contextmenu

v1.0.0

Published

Context-menu extension for the Bootstrap framework

Downloads

1,810

Readme

Bootstrap Context Menu

#This project is a fork of https://github.com/sydcanem/bootstrap-contextmenu

This project is unmaintained but I prefer it to its alternative, jQuery-contextMenu, due to its light weight.

I've forked it mainly to publish it to npm, as I'm a fan of webpack. I will accept contributions and pull requests, issues, or even transfer the right to the project or the npm registry to someone more motivated than I am.

A context menu extension of Bootstrap made for everyone's convenience.

See a [demo page] [id]. [id]:http://sydcanem.github.io/bootstrap-contextmenu/

Installation

npm install bootstrap-contextmenu

Note: Requires bootstrap.css

Usage

Via data attributes

Add data-toggle="context" to any element that needs a custom context menu and via CSS set position: relative to the element.

Point data-target attribute to your custom context menu.

<div class="context" data-toggle="context" data-target="#context-menu"></div>

Via Javascript

Call the context menu via JavaScript:

$('.context').contextmenu({
  target:'#context-menu', 
  before: function(e,context) {
    // execute code before context menu if shown
  },
  onItem: function(context,e) {
    // execute on menu item selection
  }
})

Options

target - is the equivalent of the data-target attribute. It identifies the html of the menu that will be displayed.

before - is a function that is called before the context menu is displayed. If this function returns false, the context menu will not be displayed. It is passed two parameters,

  • e - the original event. (You can do an e.preventDefault() to cancel the browser event).
  • context - the DOM element where right click occured.

onItem - is a function that is called when a menu item is clicked. Useful when you want to execute a specific function when an item is clicked. It is passed two parameters,

  • context - the DOM element where right click occured.
  • e - the click event of the menu item, $(e.target) is the item element.

scopes - DOM selector for dynamically added context elements. See issue.

Events

All events are fired at the context's menu. Check out dropdown plugin for a complete description of events.

  • show.bs.context - This event fires immediately when the menu is opened.
  • shown.bs.context - This event is fired when the dropdown has been made visible to the user.
  • hide.bs.context - This event is fired immediately when the hide instance method has been called.
  • hidden.bs.context - This event is fired when the dropdown has finished being hidden from the user (will wait for CSS transitions, to complete).

Sample

$('#myMenu').on('show.bs.context',function () {
  // do something...
});

Example

Activate and specify selector for context menu

$('#main').contextmenu({'target':'#context-menu'});

Activate within a div, but not on spans

$('#main').contextmenu({
  target: '#context-menu2',
  before: function (e, element, target) {
      e.preventDefault();
      if (e.target.tagName == 'SPAN') {
          e.preventDefault();
          this.closemenu();
          return false;
      }
      return true;
  }
});

Modify the menu dynamically

$('#main').contextmenu({
  target: "#myMenu",
  before: function(e) { 
    this.getMenu().find("li").eq(2).find('a').html("This was dynamically changed");
  }
});

Show menu name on selection

$('#main').contextmenu({
  onItem: function(context, e) {
    alert($(e.target).text());
  }
});

Nice to have features:

  • Close and open animations
  • Keyboard shortcuts for menus

License

MIT