• Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Super lightweight jQuery tree plugin

jQuery Bonsai

jquery-bonsai is a lightweight jQuery plugin that takes a big nested list and prunes it down to a small expandable tree control.

Also includes support for checkboxes (including 'indeterminate' state) and for populating the tree using a JSON data source.

Installation

bower

bower install jquery-bonsai --save

npm

npm install jquery-bonsai --save

Usage

$('ul#my-nested-list').bonsai();

API

$.fn.bonsai(options)

$('#list').bonsai({
  expandAll: false, // expand all items
  expand: null, // optional function to expand an item
  collapse: null, // optional function to collapse an item
  addExpandAll: false, // add a link to expand all items
  addSelectAll: false, // add a link to select all checkboxes
  selectAllExclude: null, // a filter selector or function for selectAll
  idAttribute: 'id', // which attribute of the list items to use as an id

  // createInputs: create checkboxes or radio buttons for each list item
  // using a value of "checkbox" or "radio".
  //
  // The id, name and value for the inputs can be declared in the
  // markup using `data-id`, `data-name` and `data-value`.
  //
  // The name is inherited from parent items if not specified.
  //
  // Checked state can be indicated using `data-checked`.
  createInputs: false,
  // checkboxes: run qubit(this.options) on the root node (requires jquery.qubit)
  checkboxes: false,
  // handleDuplicateCheckboxes: update any other checkboxes that
  // have the same value
  handleDuplicateCheckboxes: false
});

Bonsai#update()

If the DOM changes then you'll need to call #update:

$('#list').bonsai('update');

Bonsai#listItem(id)

Return a jQuery object containing the <li> with the specified id.

Expanding/collapsing a single items

  • Bonsai#expand(listItem)
  • Bonsai#collapse(listItem)
  • Bonsai#toggle(listItem)
  • Bonsai#expandTo(listItem)
var bonsai = $('#list').data('bonsai');
bonsai.expand(listItem);

All of these methods accept either a DOMElement, a jQuery object or an id and return a jQuery object containing the list item.

Expanding/collapsing the whole tree

  • Bonsai#expandAll(listItem)
  • Bonsai#collapseAll(listItem)

Bonsai#serialize()

Returns an object representing the expanded/collapsed state of the list, using the items' id to identify the list items.

var bonsai = $('#list').data('bonsai');
var state = bonsai.serialize();

Bonsai#restore()

Restores the expanded/collapsed state of the list using the return value of #serialize().

var bonsai = $('#list').data('bonsai');
var state = bonsai.serialize();
// do stuff that changes the DOM, and may not retain collapsed state
bonsai.update(); // update to handle any new DOM elements
bonsai.restore(state); // restores the collapsed state

More Repositories

1

ember-devtools

A collection of useful Ember.js debugging functions.
JavaScript
161
star
2

tabcordion

A jQuery plugin that transforms Bootstrap tabs to an accordion and vice versa. Useful for responsive mobile sites.
CoffeeScript
91
star
3

lugg

A simple logging module that uses bunyan for logging and debug output with inspiration from @tj's debug.
JavaScript
38
star
4

jquery-qubit

Provides the semantics for a nested list of tri-state checkboxes, using the HTML5 "indeterminate" property
JavaScript
18
star
5

factory-girl-sequelize

A Sequelize adapter for factory-girl
JavaScript
11
star
6

jquery-json-list

A simple plugin to create a nested list from a JSON document.
JavaScript
10
star
7

factory-girl-bookshelf

A Bookshelf adapter for factory-girl
JavaScript
8
star
8

ember-spin.js

An Ember.js component for displaying a spinning loading indicator using spin.js.
JavaScript
6
star
9

silverstripe-hide-email

A SilverStripe module that provides Javascript email obfuscation with a <noscript> fallback option
PHP
4
star
10

ember-cli-jstransform

An ember-cli addon for applying jstransform transformations, such as transpiling ES6 to ES5
JavaScript
3
star
11

ember-pager

Scrolling and link-based pagination for Ember.js
CoffeeScript
3
star
12

ember-orchestrate.io

An Ember Data adapter for Orchestrate.io
JavaScript
3
star
13

git-tools

Some useful git scripts, including scripts to automate standard git-flow hotfix and release workflows.
Python
3
star
14

select-transformer

Transforms HTML select elements into groups of radio buttons or checkboxes
JavaScript
2
star
15

broccoli-jstransform

Broccoli plugin for jstransform
JavaScript
2
star
16

setlist.io

PHP
1
star
17

list-filter.js

A simple plugin to filter a list of items based on an input field.
JavaScript
1
star
18

ember-todomvc

A todo app written in Ember.js using ember-orchestrate.io
JavaScript
1
star
19

simplecart-utils

A set of tools for SimpleCart.js
JavaScript
1
star
20

silverstripe-soundcloud-player

A SoundCloud player module for SilverStripe CMS.
JavaScript
1
star
21

jquery-hover-zoom

Tiny little jQuery plugin that zooms images on hover. Uses jQuery.Transit to handle the animation.
1
star
22

jquery-equal-height

Very simple jQuery plugin that makes DOM elements have the same height. Usage via JavaScript or data attributes.
CoffeeScript
1
star
23

ember-select-transformer

A simple little ember-cli addon that adds a {{select-transformer}} component to your Ember app.
JavaScript
1
star