Multi-level contextmenu created in Vanilla Javascript (no css files included)

Overview

ContexMenu.js

Multi-level ContextMenu Created in Vanilla Javascript (No CSS Files)

Import with jsDelivr

<script src="https://cdn.jsdelivr.net/gh/L1quidH2O/ContextMenu.js@latest/contextmenu.js"></script>

How to use

createContextMenu(Element, Structure, Click)
  • Element : could be a selector like "#div", or a DOM Element like document.body
  • Structure : an Array that contains information about the structure of the ContextMenu (Will be explained below)
  • Click : leave it undefined for the ContextMenu to be activated by a right-click, define it so it would be activated by a left-click

Structure

Example:

[
    {
        'text': 'Item',
        'extraText': '#1',
        'onclick': function(e){console.log(e)}
    },
    {
        'text': 'Item',
        'extraText': '#2'
    },
    'divider',
    {
        'text': 'Sub',
        'extraText': '#3',
        'sub': [
            {
                'text': 'Item',
                'extraText': '#4'
            }
        ]
    }
]

Each object in the the Array is an Item in the ContextMenu

  • "text" : [String] main text to display on left side of Item
  • "extraText": [String] text to display on right side of Item (Used for shortcuts such as "ctrl+s")
  • "onclick": [Function] function to run when Item is clicked, first argument is click event
  • "sub": [Array] create a Sub-ContextMenu (Multi-Level ContextMenu), syntax is the same as Structure, hovering over Item will open Sub-ContextMenu
  • "divider": Divider is not part of an Item, its a <hr> element

Custom CSS

Create Custom CSS by changing the following classes:

Class Element Type Note
.contextmenu-container <div> ----
.contextmenu-item <div> ----
.contextmenu-divider <hr> ----
.contextmenu-text <span> ----
.contextmenu-extraText <span> Used mainly to display keyboard shortcut
.contextmenu-focus <div> A class name that is applied to .contextmenu-item if it has a sub-contextmenu that is opened

HTML Diagram:

<div class="contextmenu-container">
    <div style="position: relative;">
        <div class="contextmenu-item">
            <span class="contextmenu-text">text</span>
        </div>
    </div>
    <div class="contextmenu-focus" style="position: relative;">
        <div class="contextmenu-item">
             <span class="contextmenu-text">(sub) -></span>
        </div>
        <div class="contextmenu-container">
            <div class="contextmenu-item">
                <span class="contextmenu-text">text</span>
            </div>
        </div>
    </div>
</div>

The above Diagram would have this code:

CreateContextmenu(Element, [
    {
        "text": "text"
    },
    {
        "text": "(Sub)",
        "sub":[
            {
                "text": "text"
            },
        ]
    }
], Click)

Also, note that the opened sub-contextmenu has the class ".contextmenu-focus"

NOTE

Sub-ContextMenus will not work on ContextMenus with heights larger than the windows height

You might also like...

πŸš€ Battle-tested Next.js TypeScript Prisma template with an opinionated architecture. πŸ”‹ Included ℒ️

πŸš€ Battle-tested Next.js TypeScript Prisma template with an opinionated architecture. πŸ”‹ Included ℒ️

πŸš€ The Ultimate Next.js Starter Pack Next.js ^12 + TypeScript + Prisma + Chakra UI starter packed with useful development features. I've adopted indus

Dec 10, 2022

A refined tool for exploring open-source projects on GitHub with a file tree, rich Markdown and image previews, multi-pane multi-tab layouts and first-class support for Ink syntax highlighting.

A refined tool for exploring open-source projects on GitHub with a file tree, rich Markdown and image previews, multi-pane multi-tab layouts and first-class support for Ink syntax highlighting.

Ink codebase browser, "Kin" πŸ” The Ink codebase browser is a tool to explore open-source code on GitHub, especially my side projects written in the In

Oct 30, 2022

proxy πŸ¦„ yxorp is your Web Proxy as a Service (SAAS) Multi-tenant, Multi-Threaded, with Cache & Article Spinner

proxy πŸ¦„ yxorp is your Web Proxy as a Service (SAAS) Multi-tenant, Multi-Threaded, with Cache & Article Spinner

proxy πŸ¦„ yxorp is your Web Proxy as a Service (SAAS) Multi-tenant, Multi-Threaded, with Cache & Article Spinner. Batteries are included, Content Spinning and Caching Engine, all housed within a stunning web GUI. A unique high-performance, plug-and-play, multi-threaded website mirror and article spinner

Dec 30, 2022

This is a todo list created using webpack and vanilla javascript.

This is a todo list created using webpack and vanilla javascript. It lets a user add and remove to do items. It contains testing suite using jest framework.

Dec 15, 2022

Weather app created using vanilla JavaScript and APIs. You can search cities worldwide and get current and forecast weather features.

Weather app created using vanilla JavaScript and APIs. You can search cities worldwide and get current and forecast weather features.

Weather App Live Demo About the Project Weather app created using vanilla JavaScript and APIs. You can search cities worldwide and get current and for

Dec 28, 2022

World Best Multi-device Whatsapp Bot. Created by Vihanga-YT

World Best Multi-device Whatsapp Bot. Created by Vihanga-YT

By Vihanga YT| Β© | Reserved ASTRO-BOT-MD-V1.0 TOTAL REPO VIEWS πŸ“ [Β©] AstroBot-MD New Features Playstore Apk Downloder [.downapk] Playstore Apk

Jan 7, 2023

fully selfhosted multi-user web app for externally storing Reddit items (saved, created, upvoted, downvoted, hidden) to bypass Reddit's 1000-item listing limits

expanse fully selfhosted multi-user web app for externally storing Reddit items (saved, created, upvoted, downvoted, hidden) to bypass Reddit's 1000-i

Dec 30, 2022

Merge multiple JSON files - Vanilla JavaScript and HTML (graphic mode: browser+explorer)

JSON Merger Usage First, git clone project git clone https://github.com/mtacnet/json-merger.git Move to cloned repository and open generate.html with

Sep 18, 2022

JavaScript library for parsing Dirtywave M8 files, complete with a CLI for interacting with M8 files.

m8-js This repository contains a JavaScript library for parsing Dirtywave M8 files, as well as a CLI for interacting with M8 files. The hopes are not

Dec 17, 2022
Owner
null
Vite plugin to client bundle i18next locales composited from one to many json/yaml files from one to many libraries. Zero config HMR support included.

vite-plugin-i18next-loader yarn add -D vite-plugin-i18next-loader Vite plugin to client bundle i18next locales composited from one to many json/yaml f

AlienFast 4 Nov 30, 2022
This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js. But in most cases, I would recommend you to use something like Express in a production project for productivity purposes.

Eduardo Dantas 7 Jul 19, 2022
This Photoshop script exports all top-level layers and groups to cropped PNG and JPEG files and creates a file usable in Tumult Hype 4 based on your Photoshop document.

Export To Hype (Photoshop Edition) This Photoshop script exports all top-level layers and groups to cropped PNG and JPEG files and creates a file usab

Max Ziebell 6 Nov 9, 2022
A vanilla JavaScript multi-checkbox dropdown web component.

Multi-Checkbox Web Component Multi-Checkbox is a web component that utilizes multiple checkboxes in a dropdown list to populate the value of an input.

null 2 Dec 24, 2021
Superlight vanilla javascript plugin, for modern web dropdowns. Supporting multi-options, search and images. Designed to be seamlessly themed

Superlight vanilla javascript dropdowns by LCweb Need to jump off of jQuery (or any other) dependency? Other packages are too heavy to just tweak sele

Luca 10 Dec 26, 2022
🍦 ✨ Simple multi-select pure vanilla Javascript library.

multiSelect.js ✨ Simple multi-select pure vanilla Javascript library. ?? Live Demo v1.0.8 multiSelect.js is a simple, pure vanilla Javascript library

Jacob Kleiman 5 Mar 15, 2022
Create beautiful, functional and extensive (Multi) Select Fields with pure, vanilla JavaScript.

tail.select.js - Beautify Select Fields (formerly tail.select) Replace and Improve your HTML <select> fields with style and without jQuery! The tail.s

Ciprian Popescu 69 Dec 30, 2022
Framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. πŸ—ΊοΈ Remix driver included. 🀟

About routes-gen is a framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. Think of it as Prisma,

Stratulat Alexandru 192 Jan 2, 2023
Template Repository for making your own budder Module. CORE is not included, this is just for the module.

A quick copy of the "How to make your own module" section Check out the official budderAPI repository Template Repository for making your own budder M

Logic 2 Apr 3, 2022
A solid create-remix app, that applies best practices into a clean, batteries included template. SQLite version. Deploys to Fly.io

Remix Barebones Stack npx create-remix --template dev-xo/barebones-stack A solid create-remix app, that follows community guidelines and applies best

Dev XO 97 Dec 30, 2022