Simple and lightweight vertical 3-dot context menu

Overview

3-dot Context Menu

Thanks for taking a look at our 3-dot context menu for web development.

The 3-dot context menu allows a simple and lightweight implementation for showing 3 vertical dots allowing the user to click and show a menu. Below is a screenshot showing an example of what it looks like

3dot-context-menu example

Requirements

Jquery is required and most modern browsers should support the library. We've tested on the latest versions of Google Chrome, Internet Explorer, Microsoft Edge and Firefox.

Implementing 3-dot Context Menu

Implementing the 3-dot context menu is as straight forward as adding 1 javascript file and 1 css file with 1 line of javascript code to implement the menu.

The 3-dot menu can be added inside <td> tags within tables, within <p> tags and html heading tags such as <h1>, <h2> etc. (up to <h5>).

In the head tag of your web page add the following

<script src="/3dot-context-menu/context-menu.js"></script>
<link href="/3dot-context-menu.css" rel="stylesheet">

Add the 3-dot menu to a component within your web page. Below we're going to do it in a table, but <p> tags and heading tags are supported.

Check the example project included for examples on how to implement with each tag.

In a <td> tag add the class context-menu and a data attribute called date-container-id with the id value of the div containing your menu items. For example as below:

<td class="context-menu" data-container-id="my-context-menu-items"></td>

Then in your document ready function create a new instance of ContextMenu and pass in two parameters. The first parameter is the id of the div containing your menu items (same value as in your data-container-id) and the second parameter is your menu item click callback as follows:

var varContextMenu = null;
$(document).ready(function(){
    varContextMenu = new ContextMenu("context-menu-items", function (menu_item, parent)
         {
             alert("Menu Item Clicked: " + menu_item.text() + "\nRecord ID: " + parent.attr("data-row-id"));
         });
});

Customising 3-dot context menuu

You can also add a 3rd parameter to the ContextMenu call which is an options array. At the moment this options array only has one available option, but its done this way so its future proofed if there are new customisation options to be added in the future.

<<<<<<< HEAD The options array has one option which is to define an open call back, i.e. when the 3-dot menu is clicked, just before the context menu is opened, you'll receive a callback first to allow you to modify the menu such as disabling menu items (discussed later on).

You can create the context menu with the options array as follows:

var varContextMenu = null;
$(document).ready(function(){
    var options = {
        openCallBack: function(contextMenu) {
            console.log("Opening context menu call back called");
        }
    };
    varContextMenu = new ContextMenu("context-menu-items", function (menu_item, parent)
         {
             alert("Menu Item Clicked: " + menu_item.text() + "\nRecord ID: " + parent.attr("data-row-id"));
         }, options);
});

In the openCallback function you'll get passed back to you a parameter. The parameter is the context menu object that is linked to the 3-dot anchor point. Don't forget though, if multiple 3-dot menus are linked to the same context-menu-container and you manipulate the menu items in the callback, when opening the context menu from another 3-dot context menu, if its the same id, the same manipulated items will be shown, but can be amended again if required by using the openCallback function.

Disabling menu items

You can disable a menu item from being clickable dynamically. This can be done in two ways. You can either disable a menu item from within the openCallBack method or by calling the disable method by the contextMenu object, in the example above this would be varContextMenu.

The method for disabling a menu item is disableMenuItem(param). The parameter of this method is the menu item that should be disabled. This can be a number (the position of the item within the menu (its 0 indexed)). The parameter can also be a string, the string being the text of the menu item.

Below is how you would disable the menu item from the openCallBack method

var options = {
    openCallBack: function(contextMenu) {
        contextMenu.disableMenuItem(0); //Delete the first menu item
    }
}

There is also a function to re-enable the menu item which is enableMenuItem(param). This works in exactly the same way as the disableMenuItem function, but this would likely only be used within the openCallBack() method. The paramater can be again a number to indicate the menu item in what position to be re-enabled, or a string which is the text value of the menu item to re-enabled.

var options = {
    openCallBack: function(contextMenu) {
        contextMenu.hideMenuItem(0); //Delete the first menu item
    }
}

There is also a function to reshow the menu item which is showMenuItem(param). This works in exactly the same way as the hideMenuItem function, but this would likely only be used witin the openCallBak() method. The parameter can again be a number to indicate the menu item in what position to be re-shown, or a string which is the text value of the menu item to be reshown.

Hide Menu Items

You can hide a menu item from being shown dynamically. This can be done in two ways. You can either a disable a menu item from within the openCallBack method, or by calling the hideMenuItem method by the contextMenu object, in the example above this would be varContextMenu.

The method for hiding a menu item is hideMenuItem(param). The parameter of this method is the menu item that should be disabled. This can be a number (the position of the item within the menu (its 0 indexed)). The parameter can also be a s tring, t he string being the text oof the menu item.

Below is how you would hide the menu item from the open openCallBack method.

CSS Classes available for menu items

There are two CSS classes available that provide a different background colour to the menu item. The two classes available are warning and danger. These could be used to provide a warning to the user that by that clicking the menu item could have an undesired affect. For example, say you have a menu item "Delete my Account" this item could have the class "danger" which would show a red background on hover.

The CSS is pretty straight forward for the menu so it should be fairly straight forward to modify or add new classes for your own needs.

##Reloading dynamic data where the context menu would be re-created If you dynamically load data, such as in our example a table make sure you call destory() on the contextMenuReturn object before re-creating your view. If you don't do this, the click handler for the menu might not fire, it might fire multiple times depending on your browser.

Reporting bugs/feature requests/getting help

If you want to report an issue, have a feature request or just want to get some help, you can either use the issue tracker within GitHub or our support portal at https://support.boardiesitsolutions.com.

We would love for the open source community to contribute to this project and if you would like to, please check out our contributing guidelines here.

You might also like...

Story Show Gallery - JS & React - minimalist, vertical photo gallery, mobile friendly

 Story Show Gallery - JS & React - minimalist, vertical photo gallery, mobile friendly

Vertical photo gallery optimized for smartphones (notch area included). SSG will support your brand and marketing. Optimally placed captions, full screen lightbox, no ugly arrows

Oct 4, 2022

A simple library to draw option menu or other popup inputs and layout on Node.js console.

A simple library to draw option menu or other popup inputs and layout on Node.js console.

console-gui-tools A simple library to draw option menu or other popup inputs and layout on Node.js console. console-gui-tools A simple Node.js library

Dec 24, 2022

Navigation-Menu-Javascript - A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked.

Navigation-Menu-Javascript - A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked.

Navigation-Menu-Javascript A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked. Desktop view Mobile v

Feb 16, 2021

Finance-Tracker - A basic finance-tracker application built using Next.js, React Hooks and Context API

Next.js + Tailwind CSS Example This example shows how to use Tailwind CSS (v3.0) with Next.js. It follows the steps outlined in the official Tailwind

Jan 2, 2022

๐Ÿš€๐Ÿš€ A Shopify embedded app starter template, with updated dependencies, session storage, app context and examples for basic functionalities.

Shopify Node App Starter This is a starter template for embedded shopify apps based on the shopify cli node app. Contributions to create the perfect s

Jan 8, 2023

mock APIs, intelligently, with context, and perform other stuff as well

@sasta-sa/project mock APIs, intelligently, with context, and perform other stuff as well ๐Ÿ˜„ Setting up Clone the project git clone https://github.com

Jan 27, 2022

A table component for your Mantine data-rich applications, supporting asynchronous data loading, column sorting, custom cell data rendering, row context menus, dark theme, and more.

A table component for your Mantine data-rich applications, supporting asynchronous data loading, column sorting, custom cell data rendering, row context menus, dark theme, and more.

Mantine DataTable A "dark-theme aware" table component for your Mantine UI data-rich applications, featuring asynchronous data loading support, pagina

Jan 4, 2023

A Node.js AI chatbot with unlimited context and chat history.

Memory Bot Memory Bot is an AI chatbot built with Node.js to demonstrate unlimited context and chat history for more cost-efficient context-aware conv

May 10, 2023

Todo-App with React-Context

View on Heroku : [https://todo-app-context.herokuapp.com/] Getting Started with Create React App This project was bootstrapped with Create React App.

Jan 2, 2022
Comments
  • Fix multiple click binds

    Fix multiple click binds

    Hi,

    thank you for this very useful little library. I just found one bug. I am kind of surprised that no one noticed it eralier.

    If you open one context menu and then click on another 3-dot menu and then select some option, the listener will execute twice. Seems like removing all click binds prior to adding new one is sufficent fix.

    Earlier solution did not counted with possibility of just clicking elsewhere on the page, thus not executing the unbind function.

    opened by Everis 1
Releases(1.1.0.5)
Owner
Boardies IT Solutions
Boardies IT Solutions
jSide Menu is a well designed, simple and clean side navigation menu with dropdowns.

jQuery jSide Menu jSide Menu is a well designed, simple and clean side navigation menu with dropdowns. Browse: Live Demo & Using Guide Main Features F

CodeHim 24 Feb 14, 2022
Easy responsive tabs - is a lightweight jQuery plugin which optimizes normal horizontal or vertical tabs to accordion on multi devices

Easy responsive tabs - is a lightweight jQuery plugin which optimizes normal horizontal or vertical tabs to accordion on multi devices like: web, tablets, Mobile (IPad & IPhone). This plugin adapts the screen size and changes its action accordingly.

Samson Onna 600 Dec 8, 2022
API dot Open Sauced is NestJS and SupaBase powered OAS3 backend designed to remove client complexity and provide a structured graph of all @open-sauced integrations

?? Open Sauced Nest Supabase API ?? The path to your next Open Source contribution ?? Prerequisites In order to run the project we need the following

TED Vortex (Teodor-Eugen Duศ›ulescu) 13 Dec 18, 2022
Displaying actual age in percentage with 9 signs after dot (floating number)

Actual Age Chrome Extension Displaying actual age in percentage with 9 signs after dot (floating number) Features Popup You can select your Birth date

Igor Makeenko 22 Nov 2, 2022
VanillaSelectBox - A dropdown menu with lots of features that takes a select tag and transforms it into a single or multi-select menu with 1 or 2 levels

vanillaSelectBox v1.0.0 vanillaSelectBox : v1.00 : Adding a package.json file New : Possibility to change the dropdown tree and change the remote sear

philippe MEYER 103 Dec 16, 2022
This restaurant project is a SPA (single-page application) website. The user can navigate between the home, menu and contact page. I used the MealDB API to display some menu items.

Fresh Cuisine This restaurant project is from the Odin Project and it is a SPA (single-page application) website. The user can navigate between the ho

Virag Kormoczy 7 Nov 2, 2022
Obsidian-dataview-table-filter-menu - Dynamically created filter menu for dataview tables in obsidian

Dataview table Filter Menu for Obsidian Dynamically created filter menu for data

shiro 17 Sep 24, 2022
A little animation for a big menu where the letters of a word shuffle to become the first letter of each menu item.

Letter Shuffle Animation for a Menu A little animation for a big menu where the letters of a word shuffle to become the first letter of each menu item

Codrops 29 Dec 4, 2022
jQuery Tabs Plugin. CSS Tabs with Accessible and Responsive Design. Lot of Tab Themes with Vertical and Horizontal Orientation.

Macaw Tabs Macaw Tabs is jQuery tabs plugin. It helps you to create accessible and responsive jQuery tabs by implementing the W3 design patterns for t

HTMLCSSFreebies 6 Dec 8, 2022
jQuery Plugin for Ticker, News Ticker with Vertical, Horizontal, Marquee and Typewriting effects

AcmeTicker - News Ticker A very lightweight jQuery plugin for creating advanced news ticker. Demo: Gutentor News Ticker Ticker Type Vertical Horizonta

Santosh Kunwar 11 Sep 3, 2022