├── .gitignore
├── History.md
├── Makefile
├── Readme.md
├── component.json
├── example.html
├── index.css
├── index.js
├── template.html
└── test
├── index.html
└── test.js
/.gitignore:
--------------------------------------------------------------------------------
1 | components
2 | build
3 |
--------------------------------------------------------------------------------
/History.md:
--------------------------------------------------------------------------------
1 |
2 | 0.5.1 / 2014-01-05
3 | ==================
4 |
5 | * NEED TO UPDATE THIS
6 |
7 | 0.5.0 / 2013-09-29
8 | ==================
9 |
10 | * update pillbox
11 | * dont search down, up or enter are down
12 | * make .select-single input 100% width and 100% height [jonathanong]
13 | * add .select-multiple class when multiple, closes #36
14 | * ignore enter on search, closes #38
15 | * meta viewport + border-box styling [jonathanong]
16 |
17 | 0.4.0 / 2013-09-24
18 | ==================
19 |
20 | * add .empty() to remove all options, closes #28
21 | * fix .remove(name) when option is selected
22 | * fix .deselect(name) on multiple
23 | * prevent propagation on touch start
24 | * show dropdown on search, closes #32
25 | * bubble .select(), should close #31
26 | * Use component/debounce [jonathanong]
27 |
28 | 0.3.0 / 2013-09-23
29 | ==================
30 |
31 | * add .unbind()
32 | * add .blur()
33 | * fix ios7 blur, closes #25
34 | * fix search on backspace, closes #26
35 | * add .focus() docs, closes #27
36 | * clear single select on blur, closes #21
37 | * use matthewmueller/debounce, closes #23
38 | * Load `template.html` directly [jonathanong]
39 |
40 | 0.2.0 / 2013-09-21
41 | ==================
42 |
43 | * add demo prop
44 | * use e.preventDefault() when necessary closes #15
45 | * show dropdown if hidden, on down / up, closes #16
46 | * dehighlight selected, closes #17
47 | * highlight on hover, closes #14
48 | * change single-select to have a single searchable input
49 | * fix mouse click / hide behavior, should close #10
50 | * escape shouldnt show dropdown, closes #12
51 |
52 | 0.1.0 / 2013-09-16
53 | ==================
54 |
55 | * add custom element support, closes #4
56 | * add .highlight(name) and .dehighlight(), closes #8
57 | * change .options to a map of name to option
58 | * hide dropdown on "esc"
59 | * fix in firefox
60 |
61 | 0.0.3 / 2013-09-14
62 | ==================
63 |
64 | * add .remove(name)
65 | * add search tests
66 | * add search input helper
67 |
68 | 0.0.2 / 2013-09-13
69 | ==================
70 |
71 | * add tests
72 | * better example
73 | * no need to use .bind within foreach [jonathanong]
74 |
75 | 0.0.1 / 2013-09-13
76 | ==================
77 |
78 | * Initial commit
79 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 |
2 | build: components index.js
3 | @component build --dev
4 |
5 | components: component.json
6 | @component install --dev
7 |
8 | clean:
9 | rm -fr build components template.js
10 |
11 | test: build
12 | @open test/index.html
13 |
14 | .PHONY: clean test
15 |
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | # select
2 |
3 | modern <select>. (WIP)
4 |
5 | [see the demo](http://yields.github.io/select/index.html)
6 |
7 | ```js
8 | var Select = require('select');
9 |
10 | var select = Select()
11 | .label('Select a language')
12 | .multiple()
13 | .add('Javascript')
14 | .add('Google Go')
15 | .add('Bash')
16 | .add('Ruby')
17 | .add('Lua')
18 | .add('C++')
19 | .add('C', 200)
20 | .select('Jasvascript')
21 | .select('Google Go')
22 | .deselect('Google Go')
23 | .select('c');
24 |
25 | document.body.appendChild(select.el);
26 |
27 | select.on('change', function(){
28 | console.log(select.values());
29 | // => ['javascript', 200]
30 | });
31 | ```
32 |
33 |
34 | ## Installation
35 |
36 | Install with [component(1)](http://component.io):
37 |
38 | $ component install yields/select
39 |
40 | ## API
41 |
42 | ### Select()
43 |
44 | Initialize a new `Select`.
45 |
46 | #### .unbind()
47 |
48 | Unbind internal events.
49 |
50 | #### .label(label)
51 |
52 | Set the label.
53 |
54 | #### .multiple([label])
55 |
56 | Allow multiple selections.
57 |
58 | #### .searchable([label])
59 |
60 | Allow search.
61 |
62 | #### add(name[, value [, el]])
63 |
64 | Add an option with `name` and optional `value`.
65 |
66 | An option `el` can be given, this can be either `html` string
67 | or native `Element`.
68 |
69 | add('js', 0, '
Javascript')
70 |
71 | #### remove(name)
72 |
73 | Remove an option with `name`.
74 |
75 | #### empty()
76 |
77 | Remove all options.
78 |
79 | #### select(name)
80 |
81 | Select an option with `name`.
82 |
83 | #### deselect(name)
84 |
85 | De-select `name`.
86 |
87 | #### focus()
88 |
89 | Focus ``.
90 |
91 | #### blur()
92 |
93 | Blur ``.
94 |
95 | #### highlight(name)
96 |
97 | Highlight an option by `name`.
98 |
99 | When an option is in "highlight" mode, it will be selected when the
100 | user hits enter.
101 |
102 | #### dehighlight()
103 |
104 | De-highlight "highlight"ed option
105 |
106 | #### get(name)
107 |
108 | Get an option with `name`.
109 |
110 | #### show([name])
111 |
112 | Show the dropdown or option `name`.
113 |
114 | #### hide([name])
115 |
116 | Hide the dropdown or option `name`.
117 |
118 | #### visible([name])
119 |
120 | Check if option `name` or dropdown are visible.
121 |
122 | #### toggle([name])
123 |
124 | Toggle `.show([name])`, `.hide([name])`.
125 |
126 | #### disable(name)
127 |
128 | Disable an option `name`.
129 |
130 | #### enable(name)
131 |
132 | Enable an option `name`.
133 |
134 | #### selected([options])
135 |
136 | Get / set selected options.
137 |
138 | #### values()
139 |
140 | Get selected values.
141 |
142 | #### search(term)
143 |
144 | Search options with `term`, if there are listeners for `search` event, the `.search()` method will do nothing.
145 | this allows you to set up custom search.
146 |
147 | var select = Select()
148 | .add('one')
149 | .add('two')
150 | .on('search', function(term){
151 | ajax(term, function(opts){
152 | opts.forEach(select.add, select);
153 | select.highlight(opts[0].name);
154 | })
155 | })
156 |
157 | ### Events
158 |
159 | #### "add"
160 |
161 | Emitted when you add an `option` with an object:
162 |
163 | {
164 | name:
165 | value:
166 | el:
167 | selected:
168 | }
169 |
170 | #### "remove"
171 |
172 | Emitted when an option is removed, `option` object is given as an argument.
173 |
174 | #### "select"
175 |
176 | Emitted when an option is selected.
177 |
178 | {
179 | name:
180 | value:
181 | el:
182 | selected:
183 | }
184 |
185 | #### "change"
186 |
187 | Emitted with `Select` instance.
188 |
189 | #### "deselect"
190 |
191 | Emitted with an `option` object.
192 |
193 | #### "show"
194 |
195 | Emitted when the select dropdown is shown.
196 |
197 | #### "hide"
198 |
199 | Emitted when the select dropdown is hidden.
200 |
201 | #### "search"
202 |
203 | Emitted when `.search(term)` is called, if there are listeners
204 | the method `.search(term)` will do nothing.
205 |
206 | #### "found"
207 |
208 | Emitted after a search was performed with number of matches.
209 |
210 | ### Tests
211 |
212 | ```bash
213 | $ make test
214 | ```
215 |
216 | ## License
217 |
218 | MIT
219 |
--------------------------------------------------------------------------------
/component.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "select",
3 | "repo": "yields/select",
4 | "description": "modern