npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery-bonsai

v2.1.3

Published

A lightweight jQuery plugin that takes a big nested list and prunes it down to a small expandable tree control.

Downloads

2,407

Readme

jQuery Bonsai

Visit project page and demos

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.

See http://simonwade.me/jquery-bonsai/ for more information.

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