A free JavaScript plugin to create custom right click context menus.

Overview

CtxMenu (Javascript)

A modern, light weight, object oriented solution for adding right click context menus for your website.

preview

demo

Installation

  1. Download the latest version
  2. Upload the CtxMenu folder to your server
  3. Add the script to the html code of the pages where you'd like to use it
<script src="./ctxmenu.min/ctxmenu.min.js"></script>

Note: You must ensure the "src" points to the location of the script on your server.


Getting Started

The basic setup of a menu:

// Initialize a context menu for the entire page
var contextMenu = CtxMenu();

// Add an item to the menu
contextMenu.addItem("Hello World", function(){
  alert("Hello World!")
  });



Documentation

CtxMenu Initialization:

// Examples of different ways to initialize a context menu:

// Initialize a context menu for the entire page
var myContextMenu = CtxMenu();

// Initialize a context menu for a element defined by it's id
var myContextMenu = CtxMenu("#example");

// Initialize a context menu for a element defined by it's class
var myContextMenu = CtxMenu(".example");

// Initialize a context menu for all types of a certain element by using a nodeName
// The example below will create a context menu for all paragraphs on the page (<p></p>)
var myContextMenu = CtxMenu("p");

// Initialize a context menu for a element variable
var myElement = document.getElementById("example");
var myContextMenu = CtxMenu(myElement);

CtxMenu Functions:


addItem( text, function, ?icon, ?index )

Appends a new item to the menu.

Arguments Description
text The text that will be displayed in the menu
function The function to be called when the item is clicked
icon Url to an icon to be displayed before the text
index The list index where to insert the item
Return Value
The DIV element of the created seperator

myItem = myContextMenu.addItem("Text Here", myFunction, icon = "myIcon.png", index = 0);



addSeparator( ?index )

Adds a horizontal line to the menu

Arguments Description
index The list index where to insert the item
Return Value
The DIV element of the created seperator

mySeparator = myContextMenu.addSeparator(index = 1);



getItems()

Get all items in the context menu.

Return Value
A list with all of the DIV elements
myItems = myContextMenu.getItems();



getItemAtIndex( index )

Get the DIV of an item based on the index. This includes separators too

Arguments Description
index The index of the item
Return Value
The DIV element
myItem = myContextMenu.getItemAtIndex(0);

Other Functions:


CtxMenuBlock( element )

Block all context menus for this element (nothing will happen on right click)

CtxMenuBlock("#MyClass");

CtxMenuDefault( element )

Set the browsers default context menu on a specified element. Useful if E.g. you create a custom context menu for the entire page but would like all text inputs to still use the default context menu.

CtxMenuDefault(".MyClass");
Comments
  • [question]  multiple context menus

    [question] multiple context menus

    Hi,

    I am considering using your contextmenu solution. On my page, I have multiple list widgets in which I can select items. I want a context menu for each list widget. Can I use your solution and if so do you a suggestion how to apply it?

    thanks.

    opened by emicklei 1
  • Usage Of removeItem

    Usage Of removeItem

    For some cases i must remove some items from menu and add new ones. As i see in your code, there is a removeItem property. How can i use it? For example what is the usage of removeItem if i want to remove the first item from the menu?

    opened by buzkanlamaca 1
  • addSeparator Issue

    addSeparator Issue

    Hi, I'm having problems with the addSeparator function.

    I haven't modified the script or anything else that caused it to fail

    here is the code:

    var contextMenu = CtxMenu();

    contextMenu.addItem("Clear Advanced Of The Advanced" , icon = "Assets\favicon.ico"); contextMenu.addItem("Options" , icon = "Assets\favicon.ico"); contextMenu.addSeparator(); contextMenu.addItem("Exit" , icon = "Assets\favicon.ico");

    it says the function is invalid what is bad?

    opened by SilentStarX 1
  • Method to invoke the context menu

    Method to invoke the context menu

    Hi, Is there a method to call the context menu i created in desired event .. the scenario is i do something after left click event and i want to invoke the context menu directly when the code on-click finish
    so, is there a method to do this .......

    Thanks for sharing information

    opened by MohamedAliGit 0
  • How to get the clicked element

    How to get the clicked element

    Please correct me if I'm wrong, but the documentation mentions no way get the element that was clicked on. There is, however, a way to get it.

    
    contextMenu.addItem("alertElement", function () {
        alert(contextMenu._elementClicked)
    });
    

    I assume the _elementClicked variable is not supposed to be accessed, as it's marked as private. Still, I thought it could be worth mentioning!

    opened by TheWilley 1
Releases(v1.0.1)
Owner
Nils Söderman
Technical Animator
Nils Söderman
Kuldeep 2 Jun 21, 2022
A JavaScript animation plugin for menus. It creates a div that moves when you mouse over an element, giving it an elastic animation.

Lava-Lamp Description: A JavaScript animation plugin for menus. It creates a div that moves when you mouse over an element, giving it an elastic anima

Richard Hung 38 Jun 4, 2022
ContainerMenu is an API for BDSX that allows you to create fake interactive container menus !

ContainerMenu - A BDSX API ContainerMenu is an API for BDSX that allows you to create fake interactive container menus ! Features Multiple containers

Se7en 8 Oct 28, 2022
Create Bootstrap 5 Modal Box using JavaScript with custom title, description, button labels and custom YES button callback

Dynamic BS5 Modal Box Create Bootstrap 5 Modal Box using JavaScript with custom title, description, button labels and custom YES button callback Insta

null 5 Oct 23, 2022
The (extremely) lightweight alternative to the mmenu.js plugin for creating off-canvas mobile menus.

mmenu light The (extremely) lightweight alternative to the mmenu.js plugin for creating off-canvas mobile menus with the exact look and feel. Examples

Fred Heusschen 172 Dec 12, 2022
Ready to manipulate partitions file? Create a custom partition, apply custom security system, hide the partition and share your hidden data on the www

Paranoia ?? Ready to manipulate partitions file? Create a custom partition, apply custom security system, hide the partition and share your hidden dat

Alice Snow 3 Dec 29, 2022
Converts select multiple elements into dropdown menus with checkboxes

jquery-multi-select Converts <select multiple> elements into dropdown menus with a checkbox for each <option>. The original <select> element is hidden

mySociety 22 Dec 8, 2022
A pure CSS library for radial lists and menus

Radial menu and radial list A pure CSS library for inline lists and menus around a circle, flexible and customizable A radial layout organizes a list

Fabio Vitali 10 Aug 15, 2022
A good looking help command made with discord.js with select menus. Works with prefix and slash commands too!

fancy-help-command A good looking help command made with discord.js with select menus. Works with prefix and slash commands too! Dependencies: Select

LunarCodes 11 Dec 12, 2022
🍔 Access hours and menus from MC's caf

The Caf at MC The Caf is a webapp that acts as an easy way to access hours and the menu from the cafeteria. It's a Next.js project bootstrapped with c

Micah Lindley 4 Nov 5, 2022
A JavaScript library allows showing/hiding "dependent" field(s) if the value of the “dependee” field matches the right condition.

MF Conditional Fields A JavaScript library that show/hide form elements based on the value of one field or many. Advantages Lightweight & fast. Comes

Ali Khallad 11 Aug 11, 2022
⚡Chrome extension allows you to create lists of Google and Github dork to open multiple tabs with one click, import "scope/out of scope" from #HackerOne #Bugcrowd #Intigriti ...

FastDork v0.1 This chrome extension allows you to create lists of Google and Github dork to open multiple tabs with one click, import "scope/out of sc

skvndr 74 Dec 31, 2022
Specify various templates for different directories and create them with one click. 🤩

English | 简体中文 Gold Right Specify various templates for different directories and create them with one click. Reason Usually there is something in the

赵東澔 16 Aug 8, 2022
Create folder of snippets to activate them in one click !

-> FR Obsidian Group Snippet This plugin allow you to set group of CSS snippets to class them and enable them in one click (or command). Also, this pl

Lisandra Simonetti 8 Dec 31, 2022
A lightweight vanilla JavaScript context menu library with FontAwesome support.

Contextify A lightweight vanilla JavaScript context menu library with FontAwesome support. This library was written for use in a personal project of m

Jacob Hampton 2 Jun 1, 2022
A VS Code extension to practice and improve your typing speed right inside your code editor. Practice with simple words or code snippets.

Warm Up ?? ??‍?? A VS Code extension to practice and improve your typing speed right inside your code editor. Practice with simple words or code snipp

Arhun Saday 34 Dec 12, 2022
If you want to know more about your favorite TV show then you've come to the right place!

Ultimate Show Guide We want to introduce you this web page that will help you to manage all your favourite TV series from place. ??️ Desktop version H

William Morales 6 Jun 23, 2022
Demonstration of how you build full-stack, typed, NPM packages, the right way

NPM Packages - The Right way This repository aims to demonstrate how to build NPM packages the right way. my-package should import the shared code, bu

VulcanJS 61 Nov 27, 2022
Move all the disks from the left hand post to the right hand post, only moving the disks one at a time and a bigger disk can never be placed on a smaller disk.

Hanoi Tower Description The Tower of Hanoi was a famous problem posed by a mathematician in 1883, The "puzzle" is to move all the disks from the left

Dustin J Sellers 1 Feb 5, 2022