Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danmasta/menubuilder
A lightweight javascript plugin for creating nested navigation menus from json objects
https://github.com/danmasta/menubuilder
Last synced: 12 days ago
JSON representation
A lightweight javascript plugin for creating nested navigation menus from json objects
- Host: GitHub
- URL: https://github.com/danmasta/menubuilder
- Owner: danmasta
- License: mit
- Created: 2014-08-04T01:33:56.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-08-09T00:47:36.000Z (over 7 years ago)
- Last Synced: 2024-08-01T19:47:52.899Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 77.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
menubuilder.js
========A very small and lightweight javascript plugin for creating nested navigation menus from json objects.
# Usage
You can add a menu object to cache by using:
`menuBuilder.addMenu(array, 'name')`Menus can be created using:
`menuBuilder.createMenu(domNode, (menu array or menu cache 'name'))`#### Methods
name | description
---- | ----
`menus` | Returns an object of currently added menus
`addMenu(menu, name)` | Add a menu object to menus list. Accepts a menu array and a name
`getMenu(name)` | Returns a stored menu object by name
`createFragment()` | Returns a new document fragment
`createElement(tag)` | Accepts one parameter as element tag name. Returns a new document element
`getElements(selector)` | Accepts a css selector and returns an array of matching dom nodes
`getElement(selector)` | Accepts a css selector and returns the first matching dom node
`isArray(item)` | Returns boolean, checks if item is an array
`addClass(node, classname)` | Add a class to a dom node, returns dom node after class has been added
`addMenuItem($menu, item)` | Accepts a dom node and an menu item object. Creates a menu list item, recurses if children are found
`addChildMenu($parent, children)` | Accepts a dom node and array of children menu item objects. Creates a child menu inside the parent list item
`createMenu(node, array)` | Accepts a dom node and either an array of menu items, or a string name of a previously added menu object. Initializes and creates the menu on the specified node