Giter Club home page Giter Club logo

listbox.js's Introduction

Listbox.js

Author: Igor Kalnitsky
License:BSD 3-clause
Version: 0.2.0
Tests:travis

Listbox.js is a simple jQuery plugin that provides a more powerful alternative to the standard <select> tag. The main problem of <select tag is that last one isn't flexible for customization with CSS. Listbox.js solves this problem. This component runs on top of <select> tag and creates an alternative to the last one based on <div> tags. It opens up great possibilities for customization.

In addition, this component provides the search bar which would be useful in lists with a lot of items.

This component was born special for XSnippet project.

NOTE: This is my first JavaScript code. So don't judge strictly.

Usage

Link the component and a stylesheet from your page.

<!-- make sure that jQuery is already included -->
<script src="/path/to/jquery.js"></script>

<!-- include listbox plugin and default stylesheet -->
<link href="/path/to/listbox.css" rel="stylesheet">
<script src="/path/to/listbox.js"></script>

Create Listbox object.

<select>
  <option>Item #1</option>
  <option>Item #2</option>
  <option>Item #3</option>
  <option>Item #4</option>
</select>

<script>
    $(function() {
        $('select').listbox({
            'class':      'myOwnClass',
            'searchbar':  true
        });
    });
</script>

Customization

Listbox.js uses following CSS classes.

.lbjs {}                        /* <div>: component container */
.lbjs-list {}                   /* <div>: container for list items */
.lbjs-item {}                   /* <div>: list item */
.lbjs-item:not([disabled]) {}   /* <div>: enabled list item */
.lbjs-item[disabled] {}         /* <div>: disabled list item */
.lbjs-item[selected] {}         /* <div>: selected list item */
.lbjs-searchbar {}              /* <input>: search query input */

FAQ

  • How to bind event handler to the `click` list item event?

    Because of Listbox.js dynamically changes DOM you should use jQuery's live() method:

    $('.myListboxClass .lbjs-item').live('click', function() {
        alert($(this).html());
    });
  • How to make disabled item?

    The process is similar to making disabled items in the <select>-tag. All you need is to set the disabled attribute.

    $('.myOwnClass .lbjs-item').each(function () {
        var value = $(this).html();
    
        if (['PHP', 'JavaScript'].indexOf(value) != -1)
            $(this).attr('disabled', '');
    });

listbox.js's People

Contributors

yjding avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.