1 |
8c360548
|
Anděl Ondřej
|
# jquery-multi-select
|
2 |
|
|
|
3 |
|
|
Converts `<select multiple>` elements into dropdown menus with a checkbox for each `<option>`.
|
4 |
|
|
|
5 |
|
|
## Use this plugin
|
6 |
|
|
|
7 |
|
|
Assuming HTML markup like this:
|
8 |
|
|
|
9 |
|
|
<label for="people">Select people:</label>
|
10 |
|
|
<select id="people" name="people" multiple>
|
11 |
|
|
<option value="alice">Alice</option>
|
12 |
|
|
<option value="bob">Bob</option>
|
13 |
|
|
<option value="carol">Carol</option>
|
14 |
|
|
</select>
|
15 |
|
|
|
16 |
|
|
You’ll want to run this:
|
17 |
|
|
|
18 |
|
|
$('#people').multiSelect();
|
19 |
|
|
|
20 |
|
|
You can pass a number of options into `.multiSelect()` to customise the HTML output it generates. Eg:
|
21 |
|
|
|
22 |
|
|
$('#people').multiSelect({
|
23 |
|
|
containerHTML: '<div class="btn-group">',
|
24 |
|
|
menuHTML: '<div class="dropdown-menu">',
|
25 |
|
|
buttonHTML: '<button class="btn btn-default">',
|
26 |
|
|
menuItemHTML: '<label>',
|
27 |
|
|
activeClass: 'dropdown-menu--open',
|
28 |
|
|
noneText: '-- Choisir --',
|
29 |
|
|
allText: 'Tout le monde',
|
30 |
|
|
presets: [
|
31 |
|
|
{ name: 'Favouris', options: ['item2', 'item4'] }
|
32 |
|
|
]
|
33 |
|
|
});
|
34 |
|
|
|
35 |
|
|
Options related to markup:
|
36 |
|
|
|
37 |
|
|
| Option | Default value | Notes |
|
38 |
|
|
|---|---|---|
|
39 |
|
|
| `containerHTML` | `'<div class="multi-select-container">'` | |
|
40 |
|
|
| `menuHTML` | `'<div class="multi-select-menu">'` | |
|
41 |
|
|
| `buttonHTML` | `'<span class="multi-select-button">'` | |
|
42 |
|
|
| `menuItemsHTML` | `'<div class="multi-select-menuitems">'` | |
|
43 |
|
|
| `menuItemHTML` | `'<label class="multi-select-menuitem">'` | |
|
44 |
|
|
| `presetsHTML` | `'<div class="multi-select-presets">'` | |
|
45 |
|
|
| `modalHTML` | `undefined` | Set this to some HTML (eg: `<div class="multi-select-modal">`) to enable the modal overlay. |
|
46 |
|
|
| `activeClass` | `'multi-select-container--open'` | The class that will be added to the container element when the menu is "open". |
|
47 |
|
|
|
48 |
|
|
Options related to labels and (select) options:
|
49 |
|
|
|
50 |
|
|
| Option | Default value | Notes |
|
51 |
|
|
|---|---|---|
|
52 |
|
|
| `noneText` | `'-- Select --'` | Shown in the button when no options have been selected. |
|
53 |
|
|
| `allText` | `undefined` | Shown in the button when all options have been selected. |
|
54 |
|
|
| `presets` | `undefined` | An array of preset option groups, see the demo for an example. |
|
55 |
|
|
|
56 |
|
|
Options related to positioning:
|
57 |
|
|
|
58 |
|
|
| Option | Default value | Notes |
|
59 |
|
|
|---|---|---|
|
60 |
|
|
| `positionMenuWithin` | `undefined` | If you provide a jQuery object here, the plugin will add a class (see `positionedMenuClass` option) to the container when the _right edge_ of the dropdown menu is about to extend outside the specified element, giving you the opportunity to use CSS to prevent the menu extending, for example, by allowing the option labels to wrap onto multiple lines. |
|
61 |
|
|
| `positionedMenuClass` | `'multi-select-container--positioned'` | The class that will be added to the container, when the menu is about to extend beyond the _right edge_ of the `positionMenuWithin` element. |
|
62 |
|
|
| `viewportBottomGutter` | `20` | The plugin will attempt to keep this distance, in pixels, clear between the bottom of the menu and the bottom of the viewport, by setting a fixed `height` style if the menu would otherwise approach this distance from the _bottom edge_ of the viewport. |
|
63 |
|
|
| `menuMinHeight` | `200` | The minimum height, in pixels, that the menu will be reduced to before the `viewportBottomGutter` option is ignored and the menu is allowed to extend beyond the _bottom edge_ of the viewport. |
|
64 |
|
|
|
65 |
|
|
## See a demo
|
66 |
|
|
|
67 |
|
|
Run `make demo`, or open `demo/index.html` in your web browser.
|
68 |
|
|
|
69 |
|
|
## Run the tests
|
70 |
|
|
|
71 |
|
|
Run `make test`, or open `test/SpecRunner.html` in your web browser.
|
72 |
|
|
|
73 |
|
|
## Compile minimized version
|
74 |
|
|
|
75 |
|
|
You'll need the Closure Compiler, which you can get with `brew install
|
76 |
|
|
closure-compiler` or directly from Google's website. If you use brew
|
77 |
|
|
(or otherwise create a closure-compiler script in your PATH), you can
|
78 |
|
|
run `make dist`, or otherwise you can run:
|
79 |
|
|
`make dist COMPILER='java -jar path-to-compiler.jar'`.
|