0.10.0 • Published 2 years ago

marking-menu v0.10.0

Weekly downloads
24
License
MIT
Repository
github
Last release
2 years ago

Marking Menu

NPM Build Status codecov

This library is an implementation of Gordon Kurtenbach's infamous Marking Menus in JavaScript [1, 2, 3].

Have a look at the demo.

License

This codebase is licensed under the MIT license. However, Marking Menus are concerned by several patents, none of which are owned by the author of this library. Make sure you have the rights to include this library in your application before doing so. The authors and contributors of this library may not be held responsible for any patent infringement following the use of this codebase.

Dependencies

Install

Browser with CDN

You can use unpkg to fetch both rxjs and marking-menu:

<!DOCTYPE html>
<html>
  <head>
    <script
      src="https://unpkg.com/rxjs@7/dist/bundles/rxjs.umd.js"
      defer
    ></script>
    <script src="https://unpkg.com/marking-menu" defer></script>
    <script defer>
      // Your stuff.
    </script>
  </head>
  <body></body>
</html>

ES modules or CommonJS

npm install -S marking-menu

Then (ES modules)

import MarkingMenu from 'marking-menu';

or (CommonJS)

var MarkingMenu = require('marking-menu');

API

MarkingMenu(items, parentDOM): Observable

MarkingMenu returns a 'hot' Observable that emits notification of the form { name, angle }. The menu is activated upon subscription of this observable, and disabled upon un-subscription.

  • items: Array of string or { name, children }. The list of the menu's items. If children is provided, the item will be considered as a sub-menu (children has the same form as items). Currently, MarkingMenu supports up to 8 items per level. The first item is on the right and the followings are layed out clockwise.

  • parentDOM: HTMLElement. The container of the menu.

Example

// Create the menu with a sub-menu at the bottom.
const items = [
  'Item Right',
  {
    name: 'Others...',
    children: ['Sub Right', 'Sub Down', 'Sub Left', 'Sub Top'],
  },
  'Item Left',
  'Item Up',
];
const mm = MarkingMenu(items, document.getElementById('main'));

// Subscribe (and activates) the menu.
const subscription = mm.subscribe((selection) => {
  // Do something.
  console.log(selection.name);
});

setTimeout(() => {
  // Later, disable the menu.
  subscription.unsubscribe();
}, 60 * 1000);
0.10.0

2 years ago

0.9.0

6 years ago

0.11.0

6 years ago

0.9.0-beta.1

6 years ago

0.9.0-beta.0

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.8.0-alpha.0

6 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago