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

selectbox

v1.0.2

Published

Selectbox is a simple and flexible jQuery plugin that helps you fully style your `<select>` elements, and keeps them readable and accessible to all.

Downloads

158

Readme

Selectbox

Selectbox is a simple and flexible jQuery plugin that helps you fully style your <select> elements, and keeps them readable and accessible to all.

Install and use

Simply download the plugin through npm or bower. You can then use it with your favorite environment (the plugin supports CommonJS, AMD and global jQuery).

// CommonJS
var $ = require('jquery');
require('selectbox');

$('select').selectbox();

// AMD
require(['jquery', 'selectbox'], function($) {

  $('select').selectbox();
});

// Global (include both jquery and selectbox JS files in your html)
$('select').selectbox();

You can then style the generated elements (see the examples for basic styling).

Options

html (boolean)

default : false You can switch it to true to insert the options' labels and option groups' labels as html instead of plain text (be careful of injections !). You can add a data-original-label attribute on the options to use as a new label.

onParseOption (function)

A function that takes the option jQuery object as a parameter and must return a string that will be injected as the option or option group label.

width (string)

default : 'min-width' Tells selectbox which CSS property it should use to set the select width : min-width or width. Use "manual" if you want to set the width with CSS.

isResponsive (boolean)

default : true Tells selectbox to switch between two rendering modes depending on the viewport's width.

mobileBreakpoint (int)

default : 768 Under this viewport's width, selectbox will switch to mobile display of the options' list.

desktopAnimation (string|function)

default : 'toggle' The animation function to use when selectbox is in desktop mode. (see animation section).

mobileAnimation (string|function)

default : 'mobile' The animation function to use when selectbox is in mobile mode. (see animation section).

optionsTitleLabel (string)

default : null If specified, it will be displayed on top of the options' list. If not, selectbox will retrieve the <label> associated with the source <select> element.

cancelBtnLabel (string)

default : 'Cancel' The label of the cancel button that closes the options list.

containerClass (string)

default : 'selectbox'

buttonClass (string)

default : 'selectbox-button'

listBoxClass (string)

default : 'selectbox-list-box'

listClass (string)

default : 'selectbox-list'

listItemClass (string)

default : 'selectbox-list-item'

groupLabelClass (string)

default : 'selectbox-group-label'

groupItemClass (string)

default : 'selectbox-group-item'

dividerClass (string)

default : 'selectbox-list-divider'

optionsTitleClass (string)

default : 'selectbox-items-title'

cancelBtnClass (string)

default : 'selectbox-cancel'

API

The API can be called through the plugin, or by retrieving it with the jQuery data() method.

// with the plugin
$element.selectbox('method_name', {params});

// with the data
var api = $element.data('selectbox');
api.method_name(params);

Methods

open()

Opens the options list.

close()

Closes the options list.

setValue(value)

Sets the value of the select.

disable()

Disables the select.

enable()

Enables the select.

isDisabled() => (boolean)

Returns if the select is disabled.

refresh()

Updates all options and option groups. To call when the source <select> has changed.

options(options)

Changes the settings and then refresh the selectbox.

destroy()

Removes the plugin and restore the source <select>.

Useful properties

When using the API through the data method, you can access these properties.

settings (object)

The list of the selectbox settings.

$element (jQuery object)

The source <select>.

$container (jQuery object)

$button (jQuery object)

$list (jquery object)

Animations

Selectbox comes with two default animations : 'toggle' and 'mobile'. Those reproduce basic rendering of a native <select> element.

You can also create your own function to call when opening or closing the selectbox, and pass them through options (see above).

$('select').selectbox({
  desktopAnimation: function($selectbox, api, show) {

    // Code here
  },
  mobileAnimation: function($selectbox, api, show) {

    // Code here
  }
});

$selectbox refers to the main selectbox container as a jQuery object, show is a boolean (true if the selectbox is opening, false if it's closing), and see above for what you can access from the api parameter.

If you need to store the function, you can add it to the $.fn.selectbox.animations, and refers to it through its name when passing options.

$.fn.selectbox.animations.customAnimation = function($selectbox, api, show) {

  // Code here
};

$('select').selectbox({
  desktopAnimation: 'customAnimation'
});