• Stars
    star
    548
  • Rank 78,027 (Top 2 %)
  • Language
    JavaScript
  • Created about 13 years ago
  • Updated over 4 years ago

Reviews

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

Repository Details

A jQuery plugin for replacing <select> elements.

jQuery selectBox: A styleable replacement for SELECT elements

Licensed under the MIT license: http://opensource.org/licenses/MIT

Features

  • Supports OPTGROUPS
  • Supports standard dropdown controls
  • Supports multi-select controls (i.e. multiple="multiple")
  • Supports inline controls (i.e. size="5")
  • Fully accessible via keyboard
  • Shift + click (or shift + enter) to select a range of options in multi-select controls
  • Type to search when the control has focus
  • Auto-height based on the size attribute (to use, omit the height property in your CSS!)
  • Tested in IE7-IE9, Firefox 3-4, recent WebKit browsers, and Opera

Usage

Download the latest version: https://github.com/marcj/jquery-selectBox/releases

Link to the JS file:

<script src="jquery.selectbox.js" type="text/javascript"></script>

Add the CSS file (or append contents to your own stylesheet):

<link href="jquery.selectbox.css" rel="stylesheet" type="text/css" />

To initialize:

// default
$('select').selectBox();

// or with custom settings
$('select').selectBox({
    mobile: true,
    menuSpeed: 'fast'
});

Settings

Key Default Values Description
mobile false Boolean Disables the widget for mobile devices
menuTransition default default, slide, fade The show/hide transition for dropdown menus
menuSpeed normal slow, normal, fast The show/hide transition speed
loopOptions false Boolean Flag to allow arrow keys to loop through options
topPositionCorrelation 0 Integer Will be plused to top position if droplist will be show at the top
bottomPositionCorrelation 0 Integer Will be substracted from top position if droplist will be shown at the bottom
hideOnWindowScroll true Boolean If false then showed droplist will not hide itself on window scroll event
keepInViewport true Boolean If set to false, the droplist will be always open towards the bottom

To specify settings after the init, use this syntax:

$('select').selectBox('settings', {settingName: value, ... });

Methods

To call a method use this syntax:

$('select').selectBox('methodName', [option]);

Available methods

Key Description
create Creates the control (default)
destroy Destroys the selectBox control and reverts back to the original form control
disable Disables the control (i.e. disabled="disabled")
enable Enables the control
value If passed with a value, sets the control to that value; otherwise returns the current value
options If passed either a string of HTML or a JSON object, replaces the existing options; otherwise Returns the options container element as a jQuery object
control Returns the selectBox control element (an anchor tag) for working with directly
refresh Updates the selectBox control's options based on the original controls options
instance Returns the SelectBox instance, where you have more methods available (only in v1.2.0-dev
             | available) as in the `SelectBox` class below.                                                 |

API SelectBox

You can instantiate the selectBox also through a classic OOP way:

var selectBox = new SelectBox($('#mySelectBox'), settings = {});
selectBox.showMenu();

The public methods are:

refresh()
destroy()
disable()
enable()

getLabelClass()
getLabelText()
getSelectElement()
getOptions(String type = 'inline'|'dropdown')

hideMenus()
showMenu()

setLabel()
setOptions(Object options)
setValue(String value)

removeHover(HTMLElement li)
addHover(HTMLElement li)

disableSelection(HTMLElement selector)
generateOptions(jQuery self, jQuery options)
handleKeyDown(event)
handleKeyPress(event)
init(options)
keepOptionInView(jQuery li, Boolean center)
refresh()
removeHover(HTMLElement li)
selectOption(HTMLElement li, event)

Events

Events are fired on the original select element. You can bind events like this:

$('select').selectBox().change(function () {
    alert($(this).val());
});

Available events

Key Description
focus Fired when the control gains focus
blur Fired when the control loses focus
change Fired when the value of a control changes
beforeopen Fired before a dropdown menu opens (cancelable)
open Fired after a dropdown menu opens (not cancelable)
beforeclose Fired before a dropdown menu closes (cancelable)
close Fired after a dropdown menu closes (not cancelable)

Known Issues

  • The blur and focus callbacks are not very reliable in IE7. The change callback works fine.

Credits

Original plugin by Cory LaViska of A Beautiful Site, LLC. (http://www.abeautifulsite.net/)

Bitdeli Badge

More Repositories

1

css-element-queries

CSS Element-Queries aka Container Queries. High-speed element dimension/media queries in valid css.
JavaScript
4,270
star
2

TypeRunner

High-performance TypeScript compiler
C++
2,569
star
3

angular2-localstorage

Angular 2+ decorator to save and restore variables/class properties to HTML5 LocalStorage automatically.
TypeScript
302
star
4

topsort.php

High-Performance Topological Sort / Dependency resolver in PHP
PHP
237
star
5

php-rest-service

Php-Rest-Service is a very simple and fast PHP class for server-side RESTful JSON APIs.
PHP
217
star
6

BetterQuitJobBundle

You should better quit your current job instead of searching a solution for *that* problem.
95
star
7

angular-es6-annotations

This little collection of annotations and registry functions allows you to register directives, controllers and filter with annotations at your angular module.
JavaScript
66
star
8

Pesto

Pesto is a high-performance GUI framework in C++ highly inspired by CSS and HTML, using Skia as rendering engine.
C++
64
star
9

angular-desktop-ui

Angular & Electron desktop UI framework. Angular components for native looking and behaving macOS desktop UI (Electron/Web)
TypeScript
51
star
10

pybridge

TypeScript library to access python functions in NodeJS, type-safe and easy to use.
TypeScript
44
star
11

typescript-react-dependency-injection

React + Vite + Deepkit's powerful dependency injection system
TypeScript
27
star
12

typedoc-plugin-lerna-packages

A plugin for Typedoc that groups all Lerna packages into own TS module
TypeScript
27
star
13

npm-local-development

Replacement for 'npm link' that actually works. Automatically overwrites installed packages with a locally available dev version.
JavaScript
24
star
14

glut.ts

The first reactive full-stack framework for Typescript specially tailored for admin interfaces and complex SPA.
TypeScript
23
star
15

bitcoin.ts

Typescript implementation of a Cryptocurrency inspired by the Bitcoin blockchain.
TypeScript
19
star
16

chrome-chatgpt-screenshot-extension

JavaScript
12
star
17

google-api-php-client

Google APIs Client Library for PHP
PHP
11
star
18

krycms-bundle-old

Don't use it. Don't Star it. Old project. New Project is https://github.com/jarves/jarves |
JavaScript
10
star
19

angular-typescript-decorators

Kinda hackish handy decorators for using Typescript with Angular v1.4+
TypeScript
9
star
20

katana-orm

Katana ORM, the new incredible sharp PHP ORM - maybe someday.
8
star
21

optimistic-locking-behavior

A behavior allowing you to use optimistic locking in Propel 2
PHP
5
star
22

twig-apply_filter-bundle

Symfony Bundle for Twig 'apply_filter' to call dynamic filters.
PHP
4
star
23

typescript-semantic-search

TypeScript
4
star
24

deepkit-bookstore

Example bookstore API with Deepkit API Console
TypeScript
3
star
25

angular-zoneless

Angular v16+ Zoneless implementation for SSR with Hydration
TypeScript
3
star
26

angular-unsub

Unsubscribes automatically your RXJS subscriptions when component is ngOnDestroy'ed
TypeScript
3
star
27

change-logger-behavior

Logs changes for defined columns in a extra logger table, for Propel2
PHP
3
star
28

glut-admin

The first real-time headless CMS/CMF with crud builder, based on Typescript/Angular. So efficient and fast it hurts.
TypeScript
2
star
29

mootools-sprintf

Mootools Javascript sprintf/printf function.
JavaScript
2
star
30

estdlib.ts

Engineer's strict stdlib for TypeScript.
TypeScript
2
star
31

mowla.js

A fast and super simple JavaScript Template Engine.
JavaScript
1
star
32

Propel2-old

PHP
1
star
33

shellfuncs

Some useful bash functions
Shell
1
star
34

deepkit-webpack

JavaScript
1
star
35

git-objects-sync

git push based on objects, instead of commits.
Python
1
star
36

angular-ivy-issue1

TypeScript
1
star
37

shut-the-lock

iOs Game "Shut the lock"
JavaScript
1
star
38

vscode-vertical-tabs

1
star
39

docker-macOS-container

An easy way to run commands in docker using macOS catalina as OS (via qemu) via ssh. Jenkins node possible
Shell
1
star
40

angular-desktop-ui-example

Angular v9 with angular-desktop-ui configured and ready to use
TypeScript
1
star