Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

build: index.js components
@component build
@component build --dev

components:
@component install
components: component.json
@component install --dev

clean:
rm -fr build components
Expand Down
153 changes: 131 additions & 22 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,56 @@ oncontextmenu = function(e){
};
```

## License

MIT

## API

### Menu()

Create a new `Menu`:
Initialize a new `Menu`.

```js
var Menu = require('menu');
var menu = new Menu();
var menu = Menu();
```

### Menu#add([slug], text, [fn])
Emits:

- "show" when shown
- "hide" when hidden
- "remove" with the item name when an item is removed
- "select" (item) when an item is selected
- * menu item events are emitted when clicked

### Menu.prototype()

Inherit from `Emitter.prototype`.

### Menu.move(`direction`:`String`)

Focus on the next menu item in `direction`.


### Menu.get(`slug`:`String`)
> _returns_ MenuItem

Gets a menu item named `slug`.


### Menu.add(`text`:`String`, `fn`:`Function`)
> _returns_ Menu

Add a new menu item with the given `text`, optional `slug` and callback `fn`.
Add a new menu item with the given `text`, optional `slug` and callback `fn`.

Using events to handle selection:
When the item is clicked `fn()` will be invoked
and the `Menu` is immediately closed. When clicked
an event of the name `text` is emitted regardless of
the callback function being present.

Using events to handle selection:

```js
menu.add('Hello');
Expand All @@ -83,17 +116,17 @@ menu.on('Hello', function(){
});
```

Using callbacks:
Using callbacks:

```js
menu.add('Hello', function(){
console.log('clicked hello');
});
```

Using a custom slug, otherwise "hello" is generated
from the `text` given, which may conflict with "rich"
styling like icons within menu items, or i18n.
Using a custom slug, otherwise "hello" is generated
from the `text` given, which may conflict with "rich"
styling like icons within menu items, or i18n.

```js
menu.add('add-item', 'Add Item');
Expand All @@ -107,25 +140,39 @@ menu.add('add-item', 'Add Item', function(){
});
```

### Menu#remove(slug)
### Menu.remove(`slug`:`String`)
> _returns_ Menu

Remove an item by the given `slug`:
Remove an item by the given `slug`:

```js
menu.add('Add item');
menu.remove('Add item');
```

Or with custom slugs:
Or with custom slugs:

```js
menu.add('add-item', 'Add item');
menu.remove('add-item');
```

### Menu#has(slug)
### Menu.change(`slug`:`String`)
> _returns_ Menu

Change menu item with `slug`.


### Menu.clear()
> _returns_ Menu

Clear menu.


### Menu.has(`item`:`MenuItem`)
> _returns_ Boolean

Check if a menu item is present.
Check if a menu item is present.

```js
menu.add('Add item');
Expand All @@ -140,18 +187,80 @@ menu.has('Foo');
// => false
```

### Menu#moveTo(x, y)
### Menu.indexOf(`item`:`MenuItem`)
> _returns_ Number

Move the menu to `(x, y)`.
Find index of menu `item`.

### Menu#show()

Show the menu.
### Menu.moveTo(`x`:`Number`, `y`:`Number`)
> _returns_ Menu

### Menu#hide()
Move context menu to `(x, y)`.

Hide the menu.

## License
### Menu.moveToCenter(`x`:`Number`, `y`:`Number`)
> _returns_ Menu

Move context menu to `(x, y)`.


### Menu.show()
> _returns_ Menu

Show the menu.


### Menu.hide()
> _returns_ Menu

Hide the menu.


### Menu.showItem(`item`:`Element`)
> _returns_ Menu

Show a menu item.


### Menu.hideItem(`item`:`Element`)
> _returns_ Menu

Hide a menu item.


### Menu.unhideAll()
> _returns_ Menu

Unhide all items.


### Menu.toggle()
> _returns_ Menu

Toggle the menu.


### Menu.filter(`fn`:`Function`)
> _returns_ Menu

Filter menu using `fn`.


### Menu.isOpen()
> _returns_ Boolean

Check if menu is visible.


### Menu.isSelecting()
> _returns_ Boolean

Check if user is selecting.


### MenuItem(`item`:`Object`)

MenuItem class.


MIT
8 changes: 6 additions & 2 deletions component.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"name": "menu",
"description": "Menu component",
"version": "0.1.1",
"version": "0.2.0",
"keywords": [
"menu",
"ui"
],
"dependencies": {
"component/emitter": "*",
"component/jquery": "*"
"component/jquery": "*",
"stagas/viewport": "*"
},
"development": {
"stagas/watch-js": "*"
},
"styles": [
"menu.css"
Expand Down
Loading