1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import Constants from './constants/index.js'
|
9 | import MultipleSelect from './MultipleSelect.js'
|
10 |
|
11 | $.fn.multipleSelect = function (option, ...args) {
|
12 | let value
|
13 |
|
14 | this.each((i, el) => {
|
15 | const $this = $(el)
|
16 | let data = $this.data('multipleSelect')
|
17 |
|
18 | const options = $.extend(
|
19 | {},
|
20 | $this.data(),
|
21 | typeof option === 'object' && option
|
22 | )
|
23 |
|
24 | if (!data) {
|
25 | data = new MultipleSelect($this, options)
|
26 | $this.data('multipleSelect', data)
|
27 | }
|
28 |
|
29 | if (typeof option === 'string') {
|
30 | if ($.inArray(option, Constants.METHODS) < 0) {
|
31 | throw new Error(`Unknown method: ${option}`)
|
32 | }
|
33 | value = data[option](...args)
|
34 |
|
35 | if (option === 'destroy') {
|
36 | $this.removeData('multipleSelect')
|
37 | }
|
38 | } else {
|
39 | data.init()
|
40 | }
|
41 | })
|
42 |
|
43 | return typeof value !== 'undefined' ? value : this
|
44 | }
|
45 |
|
46 | $.fn.multipleSelect.defaults = Constants.DEFAULTS
|
47 | $.fn.multipleSelect.locales = Constants.LOCALES
|
48 | $.fn.multipleSelect.methods = Constants.METHODS
|