• This repository has been archived on 04/Apr/2019
  • Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
    JavaScript
  • Created about 11 years ago
  • Updated over 10 years ago

Reviews

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

Repository Details

modern <select>

select

modern <select>. (WIP)

see the demo

var Select = require('select');

var select = Select()
  .label('Select a language')
  .multiple()
  .add('Javascript')
  .add('Google Go')
  .add('Bash')
  .add('Ruby')
  .add('Lua')
  .add('C++')
  .add('C', 200)
  .select('Jasvascript')
  .select('Google Go')
  .deselect('Google Go')
  .select('c');

document.body.appendChild(select.el);

select.on('change', function(){
  console.log(select.values());
  // => ['javascript', 200]
});

Installation

Install with component(1):

$ component install yields/select

API

Select()

Initialize a new Select.

.unbind()

Unbind internal events.

.label(label)

Set the label.

.multiple([label])

Allow multiple selections.

.searchable([label])

Allow search.

add(name[, value [, el]])

Add an option with name and optional value.

An option el can be given, this can be either html string or native Element.

add('js', 0, '<li><img src="js.jpg">Javascript')

remove(name)

Remove an option with name.

empty()

Remove all options.

select(name)

Select an option with name.

deselect(name)

De-select name.

focus()

Focus <input>.

blur()

Blur <input>.

highlight(name)

Highlight an option by name.

When an option is in "highlight" mode, it will be selected when the user hits enter.

dehighlight()

De-highlight "highlight"ed option

get(name)

Get an option with name.

show([name])

Show the dropdown or option name.

hide([name])

Hide the dropdown or option name.

visible([name])

Check if option name or dropdown are visible.

toggle([name])

Toggle .show([name]), .hide([name]).

disable(name)

Disable an option name.

enable(name)

Enable an option name.

selected([options])

Get / set selected options.

values()

Get selected values.

search(term)

Search options with term, if there are listeners for search event, the .search() method will do nothing. this allows you to set up custom search.

var select = Select()
  .add('one')
  .add('two')
  .on('search', function(term){
    ajax(term, function(opts){
      opts.forEach(select.add, select);
      select.highlight(opts[0].name);
    })
  })

Events

"add"

Emitted when you add an option with an object:

{
  name: <lowercase option name>
  value: <the option value>
  el: <the element>
  selected: <true if the option is selected>
}

"remove"

Emitted when an option is removed, option object is given as an argument.

"select"

Emitted when an option is selected.

{
  name: <lowercase option name>
  value: <the option value>
  el: <the element>
  selected: <true if the option is selected>
}

"change"

Emitted with Select instance.

"deselect"

Emitted with an option object.

"show"

Emitted when the select dropdown is shown.

"hide"

Emitted when the select dropdown is hidden.

"search"

Emitted when .search(term) is called, if there are listeners the method .search(term) will do nothing.

"found"

Emitted after a search was performed with number of matches.

Tests

$ make test

License

MIT

More Repositories

1

phony

Tiny command line fake data generator.
Go
733
star
2

ant

A web crawler for Go
Go
277
star
3

k

keyboard event dispatcher.
JavaScript
185
star
4

editable

Fixing contenteditable.
JavaScript
178
star
5

store

local store, unserializes and serializes values automagically :)
JavaScript
68
star
6

shortcuts

keyboard shortcuts, similiar to component/events.
JavaScript
53
star
7

gravy

saucelabs
JavaScript
44
star
8

sortable

UI Sortable.
JavaScript
42
star
9

fmt

tiny fmt utility
JavaScript
39
star
10

coverage

code coverage
CSS
39
star
11

sublime-go

An opinionated plugin for Go.
Python
38
star
12

component-bundle

component-bundle(1)
JavaScript
37
star
13

uniq-selector

get a uniq css selector from element.
JavaScript
37
star
14

component-graph

component-graph
JavaScript
29
star
15

serialize

serialize a form to urlencoded string.
JavaScript
27
star
16

colorpicker

minimal colorpicker.
JavaScript
24
star
17

pick

"pick" stuff from html source.
Go
24
star
18

redact-popover

medium inspired editor popover
JavaScript
18
star
19

dex

Lightweight IndexedDB wrapper
JavaScript
18
star
20

paper-stack

paper stack effect with css.
17
star
21

select-reflect

reflect native <select> to yields/select instance.
JavaScript
16
star
22

lru-cache

LRU Cache
JavaScript
15
star
23

css-ease

CSS Easing functions
JavaScript
14
star
24

ago

Date(now - 1e3) => "a second ago"
JavaScript
13
star
25

on-select

Invoke a callback when a user selects some text.
JavaScript
12
star
26

instrument

in-browser code coverage instrumentation
JavaScript
11
star
27

cycle

modern selectbox.
JavaScript
10
star
28

k-sequence

keyboard sequences
JavaScript
10
star
29

measure-string

Measure a string width.
JavaScript
9
star
30

stream-log

stream logger
JavaScript
9
star
31

is-touch

Check if touch is supported.
JavaScript
9
star
32

to-element

get a node from value.
JavaScript
9
star
33

clear-timeouts

clear all timeouts
JavaScript
9
star
34

mongoose-time

timestamps for mongoose schemas
JavaScript
9
star
35

traverse

low level traverse function, inspired by $.dir
JavaScript
8
star
36

scrolltop

get the window's scrolltop value, cross-browser.
JavaScript
8
star
37

zip

zip stuff.
JavaScript
8
star
38

path-lookup

lookup path within `object`.
JavaScript
8
star
39

grow-width

grow input's width.
JavaScript
7
star
40

keycode

name to keycode
JavaScript
7
star
41

clear-intervals

clear all intervals
JavaScript
7
star
42

status

user activity emitter, "idle" "active" etc..
JavaScript
7
star
43

mongoose-slug

mongoose slug plugin
JavaScript
7
star
44

co-timeout

co timeout.
JavaScript
7
star
45

carry

Carry over attrs and classes from one element to another.
JavaScript
6
star
46

apool

generic pool
JavaScript
6
star
47

xhr

Cross-browser XMLHttpRequest
JavaScript
6
star
48

editable-placeholder

Editable placeholder a la medium.com
JavaScript
6
star
49

approximate-time

approximate human readable time
JavaScript
6
star
50

send-json

send json across domains and browsers.
JavaScript
6
star
51

delegate-events

delegate events from one emitter to another
JavaScript
6
star
52

sublime-reload

refresh the browser on sublime post save.
Python
5
star
53

set-active

Set document.activeElement.
JavaScript
5
star
54

download

download files with `xhr`, report progress and send the file.
JavaScript
5
star
55

slug

slug component
JavaScript
5
star
56

extensible

extensible constructors
JavaScript
5
star
57

rework-pseudos

rework pseudo elements support.
JavaScript
5
star
58

crop

Image cropper.
JavaScript
5
star
59

emitter-mixin

EventEmitter mixin
JavaScript
5
star
60

uniq

array unique component
JavaScript
4
star
61

sortable-table

Sortable table.
JavaScript
4
star
62

indexof

indexof element.
JavaScript
4
star
63

data

attach data to elements. think $.data()
JavaScript
4
star
64

atkinson

Atkinson can remember form input data across requests.
JavaScript
4
star
65

prevent

Cross browser prevent default, because microsoft is awesome.
JavaScript
4
star
66

placeholder

Placeholder for older browsers.
JavaScript
4
star
67

visibility

Sane page visibility API.
JavaScript
3
star
68

sidebar

sidebar implementation, inspired by OSX notification center.
JavaScript
3
star
69

wd-browser

parse browser names
JavaScript
3
star
70

empty

empty an element.
JavaScript
3
star
71

svg-create

Create svg elements
JavaScript
3
star
72

load-image

load an image
JavaScript
3
star
73

idb-request

Tiny IDBRequest wrapper that allows node style callbacks
JavaScript
3
star
74

unserialize

Unserializes stringified json correctly.
JavaScript
3
star
75

scan-html

tiny html lexer.
JavaScript
3
star
76

fuzzy-object

fuzzy object.
JavaScript
3
star
77

eql

eql utility
JavaScript
3
star
78

function-source

get inner function source
JavaScript
3
star
79

cover-map

map coverage data from yields/instrument
JavaScript
3
star
80

parse-attrs

html attribute parser.
JavaScript
2
star
81

editable-shortcuts

add shortcuts to Editable instance.
JavaScript
2
star
82

buffer-events

Buffer Event Emitter events.
JavaScript
2
star
83

currency

format currency
JavaScript
2
star
84

mixtur

inline css with html
JavaScript
2
star
85

svg-attributes

SVG Attributes
JavaScript
2
star
86

capitalize

if i only had a nickel for every time i wrote this...
JavaScript
2
star
87

hasflash

Wether or not the browser has flash plugin enabled.
JavaScript
2
star
88

merge

merge two objects
JavaScript
2
star
89

get-selected-text

get user selected text
JavaScript
2
star
90

skeleton

skeleton's css
CSS
2
star
91

isArray

es5 isArray
JavaScript
2
star
92

rework-ignore-selectors

Ignore the given selectors.
JavaScript
2
star
93

before

JavaScript
1
star
94

dos-time

get / convert a date to dos-timestamp
JavaScript
1
star
95

normalize-case

tiny utility to normalize case recursively
JavaScript
1
star
96

dos-date

get / convert a date to DOS date.
JavaScript
1
star
97

progress

generic progress emitter.
JavaScript
1
star
98

hms

get hours, minutes and seconds from milliseconds
JavaScript
1
star
99

within

Date(now + 1e3) => "in a second"
JavaScript
1
star
100

wrap

wrap an element
JavaScript
1
star