dual-listbox](#module_dual-listbox)
36 |
37 | * [~DualListbox](#module_dual-listbox..DualListbox)
38 | * [.setDefaults()](#module_dual-listbox..DualListbox+setDefaults)
39 | * [.addEventListener(eventName, callback)](#module_dual-listbox..DualListbox+addEventListener)
40 | * [.addSelected(listItem)](#module_dual-listbox..DualListbox+addSelected)
41 | * [.redraw()](#module_dual-listbox..DualListbox+redraw)
42 | * [.removeSelected(listItem)](#module_dual-listbox..DualListbox+removeSelected)
43 | * [.searchLists(searchString, dualListbox)](#module_dual-listbox..DualListbox+searchLists)
44 | * [.updateAvailableListbox()](#module_dual-listbox..DualListbox+updateAvailableListbox)
45 | * [.updateSelectedListbox()](#module_dual-listbox..DualListbox+updateSelectedListbox)
46 | * [._actionAllSelected()](#module_dual-listbox..DualListbox+_actionAllSelected)
47 | * [._updateListbox()](#module_dual-listbox..DualListbox+_updateListbox)
48 | * [._actionItemSelected()](#module_dual-listbox..DualListbox+_actionItemSelected)
49 | * [._actionAllDeselected()](#module_dual-listbox..DualListbox+_actionAllDeselected)
50 | * [._actionItemDeselected()](#module_dual-listbox..DualListbox+_actionItemDeselected)
51 | * [._actionItemDoubleClick()](#module_dual-listbox..DualListbox+_actionItemDoubleClick)
52 | * [._actionItemClick()](#module_dual-listbox..DualListbox+_actionItemClick)
53 | * [._addButtonActions()](#module_dual-listbox..DualListbox+_addButtonActions)
54 | * [._addClickActions(listItem)](#module_dual-listbox..DualListbox+_addClickActions)
55 | * [._createList()](#module_dual-listbox..DualListbox+_createList)
56 | * [._createButtons()](#module_dual-listbox..DualListbox+_createButtons)
57 |
58 |
59 |
60 | #### dualListbox.setDefaults()
61 | Sets the default values that can be overwritten.
62 |
63 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
64 |
65 |
66 | #### dualListbox.addEventListener(eventName, callback)
67 | Add eventListener to the dualListbox element.
68 |
69 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
70 |
71 | | Param | Type |
72 | | --- | --- |
73 | | eventName | String |
74 | | callback | function |
75 |
76 |
77 |
78 | #### dualListbox.addSelected(listItem)
79 | Add the listItem to the selected list.
80 |
81 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
82 |
83 | | Param | Type |
84 | | --- | --- |
85 | | listItem | NodeElement |
86 |
87 |
88 |
89 | #### dualListbox.redraw()
90 | Redraws the Dual listbox content
91 |
92 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
93 |
94 |
95 | #### dualListbox.removeSelected(listItem)
96 | Removes the listItem from the selected list.
97 |
98 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
99 |
100 | | Param | Type |
101 | | --- | --- |
102 | | listItem | NodeElement |
103 |
104 |
105 |
106 | #### dualListbox.searchLists(searchString, dualListbox)
107 | Filters the listboxes with the given searchString.
108 |
109 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
110 |
111 | | Param | Type |
112 | | --- | --- |
113 | | searchString | Object |
114 | | dualListbox | |
115 |
116 |
117 |
118 | #### dualListbox.updateAvailableListbox()
119 | Update the elements in the available listbox;
120 |
121 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
122 |
123 |
124 | #### dualListbox.updateSelectedListbox()
125 | Update the elements in the selected listbox;
126 |
127 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
128 |
129 |
130 | #### dualListbox.\_actionAllSelected()
131 | Action to set all listItems to selected.
132 |
133 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
134 |
135 |
136 | #### dualListbox.\_updateListbox()
137 | Update the elements in the listbox;
138 |
139 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
140 |
141 |
142 | #### dualListbox.\_actionItemSelected()
143 | Action to set one listItem to selected.
144 |
145 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
146 |
147 |
148 | #### dualListbox.\_actionAllDeselected()
149 | Action to set all listItems to available.
150 |
151 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
152 |
153 |
154 | #### dualListbox.\_actionItemDeselected()
155 | Action to set one listItem to available.
156 |
157 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
158 |
159 |
160 | #### dualListbox.\_actionItemDoubleClick()
161 | Action when double clicked on a listItem.
162 |
163 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
164 |
165 |
166 | #### dualListbox.\_actionItemClick()
167 | Action when single clicked on a listItem.
168 |
169 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
170 |
171 |
172 | #### dualListbox.\_addButtonActions()
173 | Adds the actions to the buttons that are created.
174 |
175 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
176 |
177 |
178 | #### dualListbox.\_addClickActions(listItem)
179 | Adds the click items to the listItem.
180 |
181 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
182 |
183 | | Param | Type |
184 | | --- | --- |
185 | | listItem | Object |
186 |
187 |
188 |
189 | #### dualListbox.\_createList()
190 | Creates list with the header.
191 |
192 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
193 |
194 |
195 | #### dualListbox.\_createButtons()
196 | Creates the buttons to add/remove the selected item.
197 |
198 | **Kind**: instance method of [DualListbox](#module_dual-listbox..DualListbox)
199 |
--------------------------------------------------------------------------------
/dist/dual-listbox.js:
--------------------------------------------------------------------------------
1 | (()=>{var L="dual-listbox",_="dual-listbox__container",p="dual-listbox__available",b="dual-listbox__selected",r="dual-listbox__title",o="dual-listbox__item",v="dual-listbox__buttons",E="dual-listbox__button",c="dual-listbox__search",n="dual-listbox__item--selected",h="up",u="down",d=class{constructor(t,e={}){this.setDefaults(),this.dragged=null,this.options=[],d.isDomElement(t)?this.select=t:this.select=document.querySelector(t),this._initOptions(e),this._initReusableElements(),e.options!==void 0?this.options=e.options:this._splitOptions(this.select.options),this._buildDualListbox(this.select.parentNode),this._addActions(),this.showSortButtons&&this._initializeSortButtons(),this.redraw()}setDefaults(){this.availableTitle="Available options",this.selectedTitle="Selected options",this.showAddButton=!0,this.addButtonText="add",this.showRemoveButton=!0,this.removeButtonText="remove",this.showAddAllButton=!0,this.addAllButtonText="add all",this.showRemoveAllButton=!0,this.removeAllButtonText="remove all",this.searchPlaceholder="Search",this.showSortButtons=!1,this.sortFunction=(t,e)=>t.selected?-1:e.selected?1:t.order<select class="select1" multiple>
41 | <option value="1">One</option>
42 | <option value="2">Two</option>
43 | <option value="3">Three</option>
44 | </select>
45 |
46 | <script>
47 | let dlb1 = new DualListbox('.select1');
48 | </script>
49 |
50 |
55 | <select class="select2" multiple>
68 | <option value="1">One</option>
69 | <option value="2">Two</option>
70 | <option value="3">Three</option>
71 | </select>
72 |
73 | <script>
74 | let dlb2 = new DualListbox('.select2', {
75 | availableTitle:'Available numbers',
76 | selectedTitle: 'Selected numbers',
77 | addButtonText: '>',
78 | removeButtonText: '<',
79 | addAllButtonText: '>>',
80 | removeAllButtonText: '<<',
81 | searchPlaceholder: 'search numbers'
82 | });
83 | dlb2.addEventListener('added', function(event){
84 | console.log(event);
85 | });
86 | dlb2.addEventListener('removed', function(event){
87 | console.log(event);
88 | });
89 | </script>
90 |
91 | Selected element:
93 |<select class="select3" multiple>
116 | <option value="1">One</option>
117 | <option value="2">Two</option>
118 | <option value="3">Three</option>
119 | </select>
120 |
121 | <script>
122 | let dlb3 = new DualListbox('.select3', {
123 | showAddButton: false,
124 | showAddAllButton: false,
125 | showRemoveButton: false,
126 | showRemoveAllButton: false
127 | });
128 | </script>
129 |
130 |
135 | <select class="select4" multiple>
148 | <option value="1">One</option>
149 | <option value="2">Two</option>
150 | <option value="3">Three</option>
151 | </select>
152 |
153 | <script>
154 | let dlb4 = new DualListbox('.select4', {
155 | showSortButtons: true,
156 | });
157 | </script>
158 |
159 |
170 | | Option | 180 |Default | 181 |Excepted values | 182 |Explanation | 183 |
|---|---|---|---|
| draggable | 188 |true |
189 | boolean |
190 | If the list items should be draggable. | 191 |
| showSortButtons | 194 |false |
195 | boolean |
196 | 197 | If the sort buttons should be shown. (up and 198 | down) 199 | | 200 |
| enableDoubleClick | 203 |true |
204 | boolean |
205 | 206 | If double clicking a list items should change 207 | column. 208 | | 209 |
| showAddButton | 212 |true |
213 | boolean |
214 | If the "add" button should be shown. | 215 |
| showRemoveButton | 218 |true |
219 | boolean |
220 | If the "remove" button should be shown. | 221 |
| showAddAllButton | 224 |true |
225 | boolean |
226 | If the "add all" button should be shown. | 227 |
| showRemoveAllButton | 230 |true |
231 | boolean |
232 | If the "remove all" button should be shown. | 233 |
| availableTitle | 237 |"Available options" |
238 | string |
239 | 240 | The title that should be shown above the 241 | "Available options" 242 | | 243 |
| selectedTitle | 246 |"Selected options" |
247 | string |
248 | 249 | The title that should be shown above the 250 | "Selected options" 251 | | 252 |
| addButtonText | 255 |"add" |
256 | string |
257 | 258 | The text that should be displayed in the "add" 259 | button. 260 | | 261 |
| removeButtonText | 264 |"remove" |
265 | string |
266 | 267 | The text that should be displayed in the 268 | "remove" button. 269 | | 270 |
| addAllButtonText | 273 |"add all" |
274 | string |
275 | 276 | The text that should be displayed in the "add 277 | all" button. 278 | | 279 |
| removeAllButtonText | 282 |"remove all" |
283 | string |
284 | 285 | The text that should be displayed in the "remove 286 | all" button. 287 | | 288 |
| searchPlaceholder | 291 |"Search" |
292 | string |
293 | 294 | The text that should be displayed in the 295 | "search" fields. 296 | | 297 |
| upButtonText | 300 |"up" |
301 | string |
302 | 303 | The text that should be displayed in the "up" 304 | button. (only when sorting is enabled) 305 | | 306 |
| downButtonText | 309 |"down" |
310 | string |
311 | 312 | The text that should be displayed in the "down" 313 | button. (only when sorting is enabled) 314 | | 315 |
| options | 318 |
319 | undefined
320 | |
321 |
322 | Array<{text:"text to display", value: "what
324 | the select value should be", selected:
325 | false, order: 1}>
327 | |
328 | 329 | A list of options that should be added. This 330 | will overwrite the select options 331 | | 332 |
| sortFunction | 335 |
336 | Function
337 | |
338 | Function |
339 | 340 | A function to overwrite the default sorting that 341 | will be applied. 342 | | 343 |
| Function name | 356 |Arguments | 357 |Explanation | 358 |
|---|---|---|
| changeOrder | 363 |liItem, newPosition | 364 |365 | Change the order of the given list Element and 366 | the new position 367 | | 368 |
| addOptions | 371 |options | 372 |Add a single option to the options list. | 373 |
| addOption | 376 |option, index (optional) | 377 |378 | Add a single option to the options list. 379 | Optionally add the index. 380 | | 381 |
| addEventListener | 384 |eventName, callback | 385 |Add an eventListener | 386 |
| changeSelected | 389 |listItem | 390 |391 | Change the selected state of the list element. 392 | | 393 |
| actionAllSelected | 396 |event (optional) | 397 |Change all items to be selected. | 398 |
| actionAllDeselected | 401 |event (optional) | 402 |Change all items to not be selected. | 403 |
| redraw | 407 |408 | | Redraw the lists. | 409 |