slim-select 1.25.0 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data.d.ts +1 -0
- package/dist/helper.d.ts +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/slimselect.js +120 -79
- package/dist/slimselect.min.js +1 -1
- package/dist/slimselect.min.mjs +1 -0
- package/docs/index.html +5 -1
- package/docs/js/app.db13c724.js +2 -0
- package/docs/js/app.db13c724.js.map +1 -0
- package/docs/js/chunk-vendors.cc40aa28.js +28 -0
- package/docs/js/chunk-vendors.cc40aa28.js.map +1 -0
- package/docs/js/home.8bcb44fd.js +2 -0
- package/docs/js/home.8bcb44fd.js.map +1 -0
- package/docs/js/install.02f31028.js +2 -0
- package/docs/js/install.02f31028.js.map +1 -0
- package/docs/js/methods.1b31e988.js +11 -0
- package/docs/js/methods.1b31e988.js.map +1 -0
- package/docs/js/options.39fe1005.js +2 -0
- package/docs/js/options.39fe1005.js.map +1 -0
- package/docs/js/selects.f4d0b859.js +2 -0
- package/docs/js/selects.f4d0b859.js.map +1 -0
- package/package.json +24 -16
- package/public/index.html +10 -3
- package/src/docs/app.vue +3 -1
- package/src/docs/pages/options.vue +156 -4
- package/src/main.ts +0 -2
- package/src/slim-select/data.ts +6 -2
- package/src/slim-select/helper.ts +10 -0
- package/src/slim-select/index.ts +83 -45
- package/src/slim-select/select.ts +7 -2
- package/src/slim-select/slim.ts +29 -27
- package/tslint.json +2 -1
- package/docs/autotrack.js +0 -36
- package/docs/js/app.7716b276.js +0 -2
- package/docs/js/app.7716b276.js.map +0 -1
- package/docs/js/chunk-vendors.7a3fb284.js +0 -20
- package/docs/js/chunk-vendors.7a3fb284.js.map +0 -1
- package/docs/js/home.5687b755.js +0 -2
- package/docs/js/home.5687b755.js.map +0 -1
- package/docs/js/install.e97aac1d.js +0 -2
- package/docs/js/install.e97aac1d.js.map +0 -1
- package/docs/js/methods.1c04086b.js +0 -9
- package/docs/js/methods.1c04086b.js.map +0 -1
- package/docs/js/options.62b3d536.js +0 -2
- package/docs/js/options.62b3d536.js.map +0 -1
- package/docs/js/selects.3c803ae5.js +0 -2
- package/docs/js/selects.3c803ae5.js.map +0 -1
- package/public/autotrack.js +0 -36
- package/src/docs/google-analytics.js +0 -12
|
@@ -7,7 +7,6 @@ export default Vue.extend({
|
|
|
7
7
|
return {
|
|
8
8
|
addToBodySingle: null as any,
|
|
9
9
|
addToBodyMultiple: null as any,
|
|
10
|
-
butts: '',
|
|
11
10
|
beforeOnChangeSingle: null,
|
|
12
11
|
beforeOnChangeMultiple: null,
|
|
13
12
|
onChangeSingle: null,
|
|
@@ -63,9 +62,7 @@ export default Vue.extend({
|
|
|
63
62
|
data.push({ text: j.name })
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
callback(data)
|
|
68
|
-
}, 1000)
|
|
65
|
+
callback(data)
|
|
69
66
|
})
|
|
70
67
|
.catch((error) => {
|
|
71
68
|
callback(false)
|
|
@@ -98,6 +95,24 @@ export default Vue.extend({
|
|
|
98
95
|
}
|
|
99
96
|
})
|
|
100
97
|
|
|
98
|
+
const displaySelect = new SlimSelect({
|
|
99
|
+
select: '#selectdisplay'
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const displayData = [
|
|
103
|
+
{ value: 'A', text: 'A', display: false },
|
|
104
|
+
{ value: 'B', text: 'B' },
|
|
105
|
+
{ value: 'C', text: 'C' }
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
displaySelect.setData(displayData)
|
|
109
|
+
displaySelect.set(['A', 'C'])
|
|
110
|
+
|
|
111
|
+
new SlimSelect({
|
|
112
|
+
select: '#selectdisplay2'
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
|
|
101
116
|
new SlimSelect({
|
|
102
117
|
select: '#placeholderSingle',
|
|
103
118
|
placeholder: 'Placeholder Text Here'
|
|
@@ -147,6 +162,23 @@ export default Vue.extend({
|
|
|
147
162
|
}
|
|
148
163
|
})
|
|
149
164
|
|
|
165
|
+
const mandatorySelect = new SlimSelect({
|
|
166
|
+
select: '#selectMultiMandatory'
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const mandatoryData = [
|
|
170
|
+
{ value: 'A', text: 'A', mandatory: true },
|
|
171
|
+
{ value: 'B', text: 'B' },
|
|
172
|
+
{ value: 'C', text: 'C' }
|
|
173
|
+
]
|
|
174
|
+
|
|
175
|
+
mandatorySelect.setData(mandatoryData)
|
|
176
|
+
mandatorySelect.set(['A', 'C'])
|
|
177
|
+
|
|
178
|
+
new SlimSelect({
|
|
179
|
+
select: '#selectMultiMandatory2'
|
|
180
|
+
})
|
|
181
|
+
|
|
150
182
|
new SlimSelect({
|
|
151
183
|
select: '#selectMultiLimit',
|
|
152
184
|
limit: 2
|
|
@@ -645,6 +677,66 @@ export default Vue.extend({
|
|
|
645
677
|
</pre>
|
|
646
678
|
</div>
|
|
647
679
|
|
|
680
|
+
<div class="content">
|
|
681
|
+
<h2 class="header">display</h2>
|
|
682
|
+
<p>Allows to hide elements of select options.</p>
|
|
683
|
+
|
|
684
|
+
<div class="set-content">
|
|
685
|
+
<select id="selectdisplay" multiple></select>
|
|
686
|
+
</div>
|
|
687
|
+
|
|
688
|
+
<pre>
|
|
689
|
+
<code class="language-javascript">
|
|
690
|
+
const displaySelect = new SlimSelect({
|
|
691
|
+
select: '#selectdisplay'
|
|
692
|
+
})
|
|
693
|
+
|
|
694
|
+
const displayData = [
|
|
695
|
+
{ value: 'A', text: 'A', display: false },
|
|
696
|
+
{ value: 'B', text: 'B' },
|
|
697
|
+
{ value: 'C', text: 'C' }
|
|
698
|
+
]
|
|
699
|
+
|
|
700
|
+
displaySelect.setData(displayData)
|
|
701
|
+
displaySelect.set(['A', 'C'])
|
|
702
|
+
</code>
|
|
703
|
+
</pre>
|
|
704
|
+
|
|
705
|
+
<pre>
|
|
706
|
+
<code class="language-html">
|
|
707
|
+
<select id="selectMultiMandatory" multiple>
|
|
708
|
+
</select>
|
|
709
|
+
</code>
|
|
710
|
+
</pre>
|
|
711
|
+
|
|
712
|
+
<p>Or</p>
|
|
713
|
+
<div class="set-content">
|
|
714
|
+
<select id="selectdisplay2" multiple>
|
|
715
|
+
<option value="A" style="display: none;" selected>A</option>
|
|
716
|
+
<option value="B" selected>B</option>
|
|
717
|
+
<option value="C">C</option>
|
|
718
|
+
</select>
|
|
719
|
+
</div>
|
|
720
|
+
|
|
721
|
+
<pre>
|
|
722
|
+
<code class="language-javascript">
|
|
723
|
+
const slim = new SlimSelect({
|
|
724
|
+
select: '#selectdisplay2'
|
|
725
|
+
});
|
|
726
|
+
</code>
|
|
727
|
+
</pre>
|
|
728
|
+
|
|
729
|
+
<pre>
|
|
730
|
+
<code class="language-html">
|
|
731
|
+
<select id="selectdisplay2" multiple>
|
|
732
|
+
<option value="A" style="display: none;" selected>A</option>
|
|
733
|
+
<option value="B" selected>B</option>
|
|
734
|
+
<option value="C">C</option>
|
|
735
|
+
</select>
|
|
736
|
+
</code>
|
|
737
|
+
</pre>
|
|
738
|
+
</div>
|
|
739
|
+
|
|
648
740
|
<div class="content">
|
|
649
741
|
<h2 class="header">allowDeselectOption</h2>
|
|
650
742
|
<p>
|
|
@@ -804,6 +896,66 @@ export default Vue.extend({
|
|
|
804
896
|
</pre>
|
|
805
897
|
</div>
|
|
806
898
|
|
|
899
|
+
<div class="content">
|
|
900
|
+
<h2 class="header">mandatory</h2>
|
|
901
|
+
<p>When using multi select you can set a mandatory on the option to prevent capability to deselect particular option. Note options with mandatory flag is not selected by default, you need select them yourselfs.</p>
|
|
902
|
+
|
|
903
|
+
<div class="set-content">
|
|
904
|
+
<select id="selectMultiMandatory" multiple></select>
|
|
905
|
+
</div>
|
|
906
|
+
|
|
907
|
+
<pre>
|
|
908
|
+
<code class="language-javascript">
|
|
909
|
+
const slim = new SlimSelect({
|
|
910
|
+
select: '#selectMultiMandatory'
|
|
911
|
+
});
|
|
912
|
+
|
|
913
|
+
const data = [
|
|
914
|
+
{ value: 'A', text: 'A', mandatory: true },
|
|
915
|
+
{ value: 'B', text: 'B' },
|
|
916
|
+
{ value: 'C', text: 'C' }
|
|
917
|
+
]
|
|
918
|
+
|
|
919
|
+
slim.setData(data)
|
|
920
|
+
slim.set(["A", "C"])
|
|
921
|
+
</code>
|
|
922
|
+
</pre>
|
|
923
|
+
|
|
924
|
+
<pre>
|
|
925
|
+
<code class="language-html">
|
|
926
|
+
<select id="selectMultiMandatory" multiple>
|
|
927
|
+
</select>
|
|
928
|
+
</code>
|
|
929
|
+
</pre>
|
|
930
|
+
|
|
931
|
+
<p>Or</p>
|
|
932
|
+
<div class="set-content">
|
|
933
|
+
<select id="selectMultiMandatory2" multiple>
|
|
934
|
+
<option value="A" data-mandatory="true" selected>A</option>
|
|
935
|
+
<option value="B" selected>B</option>
|
|
936
|
+
<option value="C">C</option>
|
|
937
|
+
</select>
|
|
938
|
+
</div>
|
|
939
|
+
|
|
940
|
+
<pre>
|
|
941
|
+
<code class="language-javascript">
|
|
942
|
+
const slim = new SlimSelect({
|
|
943
|
+
select: '#selectMultiMandatory2'
|
|
944
|
+
});
|
|
945
|
+
</code>
|
|
946
|
+
</pre>
|
|
947
|
+
|
|
948
|
+
<pre>
|
|
949
|
+
<code class="language-html">
|
|
950
|
+
<select id="selectMultiMandatory" multiple>
|
|
951
|
+
<option value="A" data-mandatory="true" selected>A</option>
|
|
952
|
+
<option value="B" selected>B</option>
|
|
953
|
+
<option value="C">C</option>
|
|
954
|
+
</select>
|
|
955
|
+
</code>
|
|
956
|
+
</pre>
|
|
957
|
+
</div>
|
|
958
|
+
|
|
807
959
|
<div class="content">
|
|
808
960
|
<h2 class="header">css class</h2>
|
|
809
961
|
<p>
|
package/src/main.ts
CHANGED
|
@@ -7,8 +7,6 @@ import Normalizer from 'prismjs/plugins/normalize-whitespace/prism-normalize-whi
|
|
|
7
7
|
import 'prismjs/plugins/toolbar/prism-toolbar'
|
|
8
8
|
import 'prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard'
|
|
9
9
|
|
|
10
|
-
import '@/docs/google-analytics.js'
|
|
11
|
-
|
|
12
10
|
import '@/docs/assets/scss/index.scss'
|
|
13
11
|
import '@/slim-select/slimselect.scss'
|
|
14
12
|
|
package/src/slim-select/data.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface Option {
|
|
|
21
21
|
class?: string
|
|
22
22
|
style?: string
|
|
23
23
|
data?: object
|
|
24
|
+
mandatory?: boolean
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
// Class is responsible for managing the data
|
|
@@ -53,7 +54,8 @@ export class Data {
|
|
|
53
54
|
disabled: (info.disabled ? info.disabled : false),
|
|
54
55
|
placeholder: (info.placeholder ? info.placeholder : false),
|
|
55
56
|
class: (info.class ? info.class : undefined),
|
|
56
|
-
data: (info.data ? info.data : {})
|
|
57
|
+
data: (info.data ? info.data : {}),
|
|
58
|
+
mandatory: (info.mandatory ? info.mandatory : false)
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -69,6 +71,7 @@ export class Data {
|
|
|
69
71
|
disabled: false,
|
|
70
72
|
placeholder: false,
|
|
71
73
|
class: undefined,
|
|
74
|
+
mandatory: data.mandatory,
|
|
72
75
|
data: {}
|
|
73
76
|
})
|
|
74
77
|
}
|
|
@@ -122,7 +125,8 @@ export class Data {
|
|
|
122
125
|
placeholder: option.dataset.placeholder === 'true',
|
|
123
126
|
class: option.className,
|
|
124
127
|
style: option.style.cssText,
|
|
125
|
-
data: option.dataset
|
|
128
|
+
data: option.dataset,
|
|
129
|
+
mandatory: (option.dataset ? option.dataset.mandatory === 'true' : false)
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
132
|
|
|
@@ -90,6 +90,16 @@ export function highlight(str: string, search: any, className: string) {
|
|
|
90
90
|
return completedString
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
export function kebabCase(str: string) {
|
|
94
|
+
const result = str.replace(
|
|
95
|
+
/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,
|
|
96
|
+
(match) => '-' + match.toLowerCase()
|
|
97
|
+
)
|
|
98
|
+
return (str[0] === str[0].toUpperCase())
|
|
99
|
+
? result.substring(1)
|
|
100
|
+
: result
|
|
101
|
+
}
|
|
102
|
+
|
|
93
103
|
// Custom events
|
|
94
104
|
(() => {
|
|
95
105
|
const w = (window as any)
|
package/src/slim-select/index.ts
CHANGED
|
@@ -32,8 +32,8 @@ interface Constructor {
|
|
|
32
32
|
// Events
|
|
33
33
|
ajax?: (value: string, func: (info: any) => void) => void
|
|
34
34
|
addable?: (value: string) => Option | string
|
|
35
|
-
beforeOnChange?: (info: Option) => void | boolean
|
|
36
|
-
onChange?: (info: Option) => void
|
|
35
|
+
beforeOnChange?: (info: Option | Option[]) => void | boolean
|
|
36
|
+
onChange?: (info: Option | Option[]) => void
|
|
37
37
|
beforeOpen?: () => void
|
|
38
38
|
afterOpen?: () => void
|
|
39
39
|
beforeClose?: () => void
|
|
@@ -53,6 +53,17 @@ export default class SlimSelect {
|
|
|
53
53
|
public afterOpen: (() => void) | null = null
|
|
54
54
|
public beforeClose: (() => void) | null = null
|
|
55
55
|
public afterClose: (() => void) | null = null
|
|
56
|
+
|
|
57
|
+
private windowScroll: (e: Event) => void = debounce((e: Event) => {
|
|
58
|
+
if (this.data.contentOpen) {
|
|
59
|
+
if (putContent(this.slim.content, this.data.contentPosition, this.data.contentOpen) === 'above') {
|
|
60
|
+
this.moveContentAbove()
|
|
61
|
+
} else {
|
|
62
|
+
this.moveContentBelow()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
56
67
|
constructor(info: Constructor) {
|
|
57
68
|
const selectElement = this.validate(info)
|
|
58
69
|
|
|
@@ -114,24 +125,12 @@ export default class SlimSelect {
|
|
|
114
125
|
}
|
|
115
126
|
|
|
116
127
|
// Add onclick listener to document to closeContent if clicked outside
|
|
117
|
-
document.addEventListener('click',
|
|
118
|
-
if (e.target && !hasClassInTree(e.target as HTMLElement, this.config.id)) {
|
|
119
|
-
this.close()
|
|
120
|
-
}
|
|
121
|
-
})
|
|
128
|
+
document.addEventListener('click', this.documentClick)
|
|
122
129
|
|
|
123
130
|
// If the user wants to show the content forcibly on a specific side,
|
|
124
131
|
// there is no need to listen for scroll events
|
|
125
132
|
if (this.config.showContent === 'auto') {
|
|
126
|
-
|
|
127
|
-
if (this.data.contentOpen) {
|
|
128
|
-
if (putContent(this.slim.content, this.data.contentPosition, this.data.contentOpen) === 'above') {
|
|
129
|
-
this.moveContentAbove()
|
|
130
|
-
} else {
|
|
131
|
-
this.moveContentBelow()
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}), false)
|
|
133
|
+
window.addEventListener('scroll', this.windowScroll, false)
|
|
135
134
|
}
|
|
136
135
|
|
|
137
136
|
// Add event callbacks after everthing has been created
|
|
@@ -194,6 +193,14 @@ export default class SlimSelect {
|
|
|
194
193
|
const newData = JSON.parse(JSON.stringify(data))
|
|
195
194
|
const selected = this.data.getSelected()
|
|
196
195
|
|
|
196
|
+
// Check newData to make sure value is set
|
|
197
|
+
// If not set from text
|
|
198
|
+
for (let i = 0; i < newData.length; i++) {
|
|
199
|
+
if (!newData[i].value && !newData[i].placeholder) {
|
|
200
|
+
newData[i].value = newData[i].text
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
197
204
|
// If its an ajax type keep selected values
|
|
198
205
|
if (this.config.isAjax && selected) {
|
|
199
206
|
if (this.config.isMultiple) {
|
|
@@ -202,8 +209,25 @@ export default class SlimSelect {
|
|
|
202
209
|
newData.unshift(r)
|
|
203
210
|
}
|
|
204
211
|
} else {
|
|
205
|
-
newData.unshift(
|
|
206
|
-
|
|
212
|
+
newData.unshift(selected)
|
|
213
|
+
|
|
214
|
+
// Look for duplicate selected if so remove it
|
|
215
|
+
for (let i = 0; i < newData.length; i++) {
|
|
216
|
+
if (!newData[i].placeholder && newData[i].value === (selected as Option).value && newData[i].text === (selected as Option).text) {
|
|
217
|
+
delete newData[i]
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Add placeholder if it doesnt already have one
|
|
222
|
+
let hasPlaceholder = false
|
|
223
|
+
for (let i = 0; i < newData.length; i++) {
|
|
224
|
+
if (newData[i].placeholder) {
|
|
225
|
+
hasPlaceholder = true
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (!hasPlaceholder) {
|
|
229
|
+
newData.unshift({ text: '', placeholder: true })
|
|
230
|
+
}
|
|
207
231
|
}
|
|
208
232
|
}
|
|
209
233
|
|
|
@@ -410,34 +434,34 @@ export default class SlimSelect {
|
|
|
410
434
|
// Take in string value and search current options
|
|
411
435
|
public search(value: string): void {
|
|
412
436
|
// Only filter data and rerender if value has changed
|
|
413
|
-
if (this.data.searchValue
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
} else {
|
|
438
|
-
this.data.search(value)
|
|
439
|
-
this.render()
|
|
437
|
+
if (this.data.searchValue === value) { return }
|
|
438
|
+
|
|
439
|
+
this.slim.search.input.value = value
|
|
440
|
+
if (this.config.isAjax) {
|
|
441
|
+
const master = this
|
|
442
|
+
this.config.isSearching = true
|
|
443
|
+
this.render()
|
|
444
|
+
|
|
445
|
+
// If ajax call it
|
|
446
|
+
if (this.ajax) {
|
|
447
|
+
this.ajax(value, (info: any) => {
|
|
448
|
+
// Only process if return callback is not false
|
|
449
|
+
master.config.isSearching = false
|
|
450
|
+
if (Array.isArray(info)) {
|
|
451
|
+
info.unshift({ text: '', placeholder: true })
|
|
452
|
+
master.setData(info)
|
|
453
|
+
master.data.search(value)
|
|
454
|
+
master.render()
|
|
455
|
+
} else if (typeof info === 'string') {
|
|
456
|
+
master.slim.options(info)
|
|
457
|
+
} else {
|
|
458
|
+
master.render()
|
|
459
|
+
}
|
|
460
|
+
})
|
|
440
461
|
}
|
|
462
|
+
} else {
|
|
463
|
+
this.data.search(value)
|
|
464
|
+
this.render()
|
|
441
465
|
}
|
|
442
466
|
}
|
|
443
467
|
|
|
@@ -462,6 +486,13 @@ export default class SlimSelect {
|
|
|
462
486
|
// If there is no slim dont do anything
|
|
463
487
|
if (!slim || !select) { return }
|
|
464
488
|
|
|
489
|
+
|
|
490
|
+
document.removeEventListener('click', this.documentClick)
|
|
491
|
+
|
|
492
|
+
if (this.config.showContent === 'auto') {
|
|
493
|
+
window.removeEventListener('scroll', this.windowScroll, false)
|
|
494
|
+
}
|
|
495
|
+
|
|
465
496
|
// Show original select
|
|
466
497
|
select.style.display = ''
|
|
467
498
|
delete select.dataset.ssid
|
|
@@ -482,4 +513,11 @@ export default class SlimSelect {
|
|
|
482
513
|
document.body.removeChild(slimContent)
|
|
483
514
|
}
|
|
484
515
|
}
|
|
516
|
+
|
|
517
|
+
private documentClick: (e: Event) => void = (e: Event) => {
|
|
518
|
+
if (e.target && !hasClassInTree(e.target as HTMLElement, this.config.id)) {
|
|
519
|
+
this.close()
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
485
523
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import SlimSelect from './index'
|
|
2
2
|
import { Option, Optgroup, dataArray } from './data'
|
|
3
|
+
import { kebabCase } from './helper'
|
|
3
4
|
|
|
4
5
|
interface Constructor {
|
|
5
6
|
select: HTMLSelectElement
|
|
@@ -133,11 +134,15 @@ export class Select {
|
|
|
133
134
|
|
|
134
135
|
public createOption(info: any): HTMLOptionElement {
|
|
135
136
|
const optionEl = document.createElement('option')
|
|
136
|
-
optionEl.value = info.value
|
|
137
|
+
optionEl.value = info.value !== '' ? info.value : info.text
|
|
137
138
|
optionEl.innerHTML = info.innerHTML || info.text
|
|
138
139
|
if (info.selected) { optionEl.selected = info.selected }
|
|
140
|
+
if (info.display === false) {
|
|
141
|
+
optionEl.style.display = 'none'
|
|
142
|
+
}
|
|
139
143
|
if (info.disabled) { optionEl.disabled = true }
|
|
140
144
|
if (info.placeholder) { optionEl.setAttribute('data-placeholder', 'true') }
|
|
145
|
+
if (info.mandatory) { optionEl.setAttribute('data-mandatory', 'true') }
|
|
141
146
|
if (info.class) {
|
|
142
147
|
info.class.split(' ').forEach((optionClass: string) => {
|
|
143
148
|
optionEl.classList.add(optionClass)
|
|
@@ -145,7 +150,7 @@ export class Select {
|
|
|
145
150
|
}
|
|
146
151
|
if (info.data && typeof info.data === 'object') {
|
|
147
152
|
Object.keys(info.data).forEach((key) => {
|
|
148
|
-
optionEl.setAttribute('data-' + key, info.data[key])
|
|
153
|
+
optionEl.setAttribute('data-' + kebabCase(key), info.data[key])
|
|
149
154
|
})
|
|
150
155
|
}
|
|
151
156
|
|
package/src/slim-select/slim.ts
CHANGED
|
@@ -293,42 +293,44 @@ export class Slim {
|
|
|
293
293
|
text.innerHTML = (optionObj.innerHTML && this.main.config.valuesUseText !== true ? optionObj.innerHTML : optionObj.text)
|
|
294
294
|
value.appendChild(text)
|
|
295
295
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
if (!this.main.config.isEnabled) { return }
|
|
296
|
+
if (!optionObj.mandatory) {
|
|
297
|
+
const deleteSpan = document.createElement('span')
|
|
298
|
+
deleteSpan.classList.add(this.main.config.valueDelete)
|
|
299
|
+
deleteSpan.innerHTML = this.main.config.deselectLabel
|
|
300
|
+
deleteSpan.onclick = (e) => {
|
|
301
|
+
e.preventDefault()
|
|
302
|
+
e.stopPropagation()
|
|
303
|
+
let shouldUpdate = false
|
|
305
304
|
|
|
306
|
-
|
|
307
|
-
|
|
305
|
+
// If no beforeOnChange is set automatically update at end
|
|
306
|
+
if (!this.main.beforeOnChange) {shouldUpdate = true}
|
|
308
307
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
308
|
+
if (this.main.beforeOnChange) {
|
|
309
|
+
const selected = this.main.data.getSelected() as Option
|
|
310
|
+
const currentValues = JSON.parse(JSON.stringify(selected))
|
|
312
311
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
312
|
+
// Remove from current selection
|
|
313
|
+
for (let i = 0; i < currentValues.length; i++) {
|
|
314
|
+
if (currentValues[i].id === optionObj.id) {
|
|
315
|
+
currentValues.splice(i, 1)
|
|
316
|
+
}
|
|
317
317
|
}
|
|
318
|
+
|
|
319
|
+
const beforeOnchange = this.main.beforeOnChange(currentValues)
|
|
320
|
+
if (beforeOnchange !== false) { shouldUpdate = true }
|
|
318
321
|
}
|
|
319
322
|
|
|
320
|
-
|
|
321
|
-
|
|
323
|
+
if (shouldUpdate) {
|
|
324
|
+
this.main.data.removeFromSelected((optionObj.id as any), 'id')
|
|
325
|
+
this.main.render()
|
|
326
|
+
this.main.select.setValue()
|
|
327
|
+
this.main.data.onDataChange() // Trigger on change callback
|
|
328
|
+
}
|
|
322
329
|
}
|
|
323
330
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
this.main.render()
|
|
327
|
-
this.main.select.setValue()
|
|
328
|
-
this.main.data.onDataChange() // Trigger on change callback
|
|
329
|
-
}
|
|
331
|
+
|
|
332
|
+
value.appendChild(deleteSpan)
|
|
330
333
|
}
|
|
331
|
-
value.appendChild(deleteSpan)
|
|
332
334
|
|
|
333
335
|
return value
|
|
334
336
|
}
|
package/tslint.json
CHANGED
package/docs/autotrack.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
(function(){var aa="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(c.get||c.set)throw new TypeError("ES3 does not support getters and setters.");a!=Array.prototype&&a!=Object.prototype&&(a[b]=c.value)},f="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function h(){h=function(){};f.Symbol||(f.Symbol=ba)}var ca=0;function ba(a){return"jscomp_symbol_"+(a||"")+ca++}
|
|
2
|
-
function k(){h();var a=f.Symbol.iterator;a||(a=f.Symbol.iterator=f.Symbol("iterator"));"function"!=typeof Array.prototype[a]&&aa(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return l(this)}});k=function(){}}function l(a){var b=0;return da(function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}})}function da(a){k();a={next:a};a[f.Symbol.iterator]=function(){return this};return a}
|
|
3
|
-
function m(a){if(!(a instanceof Array)){k();var b=a[Symbol.iterator];a=b?b.call(a):l(a);for(var c=[];!(b=a.next()).done;)c.push(b.value);a=c}return a}function ea(a,b){function c(){}c.prototype=b.prototype;a.prototype=new c;a.prototype.constructor=a;for(var d in b)if(Object.defineProperties){var e=Object.getOwnPropertyDescriptor(b,d);e&&Object.defineProperty(a,d,e)}else a[d]=b[d]}
|
|
4
|
-
var n=window.Element.prototype,p=n.matches||n.matchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector||n.msMatchesSelector||n.oMatchesSelector;function q(a,b){if(a&&1==a.nodeType&&b){if("string"==typeof b||1==b.nodeType)return a==b||r(a,b);if("length"in b)for(var c=0,d;d=b[c];c++)if(a==d||r(a,d))return!0}return!1}function r(a,b){if("string"!=typeof b)return!1;if(p)return p.call(a,b);b=a.parentNode.querySelectorAll(b);for(var c=0,d;d=b[c];c++)if(d==a)return!0;return!1}
|
|
5
|
-
function fa(a){for(var b=[];a&&a.parentNode&&1==a.parentNode.nodeType;)a=a.parentNode,b.push(a);return b}
|
|
6
|
-
function ha(a,b,c){function d(a){var d;if(g.composed&&"function"==typeof a.composedPath)for(var e=a.composedPath(),t=0,B;B=e[t];t++)1==B.nodeType&&q(B,b)&&(d=B);else a:{if((d=a.target)&&1==d.nodeType&&b)for(d=[d].concat(fa(d)),e=0;t=d[e];e++)if(q(t,b)){d=t;break a}d=void 0}d&&c.call(d,a,d)}var e=document,g={composed:!0,u:!0},g=void 0===g?{}:g;e.addEventListener(a,d,g.u);return{i:function(){e.removeEventListener(a,d,g.u)}}}
|
|
7
|
-
function ia(a){var b={};if(!a||1!=a.nodeType)return b;a=a.attributes;if(!a.length)return{};for(var c=0,d;d=a[c];c++)b[d.name]=d.value;return b}var ja=/:(80|443)$/,u=document.createElement("a"),v={};
|
|
8
|
-
function w(a){a=a&&"."!=a?a:location.href;if(v[a])return v[a];u.href=a;if("."==a.charAt(0)||"/"==a.charAt(0))return w(u.href);var b="80"==u.port||"443"==u.port?"":u.port,b="0"==b?"":b,c=u.host.replace(ja,"");return v[a]={hash:u.hash,host:c,hostname:u.hostname,href:u.href,origin:u.origin?u.origin:u.protocol+"//"+c,pathname:"/"==u.pathname.charAt(0)?u.pathname:"/"+u.pathname,port:b,protocol:u.protocol,search:u.search}}var x=[];
|
|
9
|
-
function y(a,b){var c=this;this.context=a;this.s=b;this.f=(this.c=/Task$/.test(b))?a.get(b):a[b];this.b=[];this.a=[];this.g=function(a){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];return c.a[c.a.length-1].apply(null,[].concat(m(b)))};this.c?a.set(b,this.g):a[b]=this.g}function z(a,b){a.b.push(b);A(a)}function C(a,b){b=a.b.indexOf(b);-1<b&&(a.b.splice(b,1),0<a.b.length?A(a):a.i())}function A(a){a.a=[];for(var b,c=0;b=a.b[c];c++){var d=a.a[c-1]||a.f.bind(a.context);a.a.push(b(d))}}
|
|
10
|
-
y.prototype.i=function(){var a=x.indexOf(this);-1<a&&(x.splice(a,1),this.c?this.context.set(this.s,this.f):this.context[this.s]=this.f)};function D(a,b){var c=x.filter(function(c){return c.context==a&&c.s==b})[0];c||(c=new y(a,b),x.push(c));return c}function E(a,b,c,d,e){if("function"==typeof d){var g=c.get("buildHitTask");return{buildHitTask:function(c){c.set(a,null,!0);c.set(b,null,!0);d(c,e);g(c)}}}return F({},a,b)}
|
|
11
|
-
function ka(a,b){var c=ia(a),d={};Object.keys(c).forEach(function(a){if(!a.indexOf(b)&&a!=b+"on"){var e=c[a];"true"==e&&(e=!0);"false"==e&&(e=!1);a=la(a.slice(b.length));d[a]=e}});return d}function ma(a){var b;return function(c){for(var d=[],e=0;e<arguments.length;++e)d[e-0]=arguments[e];clearTimeout(b);b=setTimeout(function(){return a.apply(null,[].concat(m(d)))},500)}}function na(a){function b(){c||(c=!0,a())}var c=!1;setTimeout(b,2E3);return b}
|
|
12
|
-
var F=Object.assign||function(a,b){for(var c=[],d=1;d<arguments.length;++d)c[d-1]=arguments[d];for(var e=0;d=c[e];e++)for(var g in d)Object.prototype.hasOwnProperty.call(d,g)&&(a[g]=d[g]);return a};function la(a){return a.replace(/[\-\_]+(\w?)/g,function(a,c){return c.toUpperCase()})}function G(a){return"object"==typeof a&&null!==a}
|
|
13
|
-
function H(a,b){var c=window.GoogleAnalyticsObject||"ga";window[c]=window[c]||function(a){for(var b=[],d=0;d<arguments.length;++d)b[d-0]=arguments[d];(window[c].q=window[c].q||[]).push(b)};window.gaDevIds=window.gaDevIds||[];0>window.gaDevIds.indexOf("i5iSjo")&&window.gaDevIds.push("i5iSjo");window[c]("provide",a,b);window.gaplugins=window.gaplugins||{};window.gaplugins[a.charAt(0).toUpperCase()+a.slice(1)]=b}function I(){this.a={}}
|
|
14
|
-
I.prototype.C=function(a,b){for(var c=[],d=1;d<arguments.length;++d)c[d-1]=arguments[d];(this.a[a]=this.a[a]||[]).forEach(function(a){return a.apply(null,[].concat(m(c)))})};var J={},K=!1;function L(a,b){this.a={};this.key=a;this.l=b||{}}ea(L,I);function M(a,b,c){a=["autotrack",a,b].join(":");J[a]||(J[a]=new L(a,c),J[a].key=a,K||(window.addEventListener("storage",N),K=!0));return J[a]}
|
|
15
|
-
L.prototype.get=function(){var a=String(window.localStorage&&window.localStorage.getItem(this.key));return"string"!=typeof a?{}:O(a,this.l)};L.prototype.set=function(a){var b=this.get();a=F(b,a);window.localStorage&&window.localStorage.setItem(this.key,JSON.stringify(a))};L.prototype.i=function(){delete J[this.key];Object.keys(J).length||(window.removeEventListener("storage",N),K=!1)};function N(a){var b=J[a.key];if(b){var c=O(a.oldValue,b.l);a=O(a.newValue,b.l);b.C("externalSet",a,c)}}
|
|
16
|
-
function O(a,b){var c;try{c=JSON.parse(a)}catch(d){c={}}return F({},b,c)}var oa={};function P(a,b,c){this.f=a;this.timeout=b||Q;this.timeZone=c;b=this.b=this.b.bind(this);z(D(a,"sendHitTask"),b);try{this.c=new Intl.DateTimeFormat("en-US",{timeZone:this.timeZone})}catch(d){}this.a=M(a.get("trackingId"),"session",{hitTime:0,isExpired:!1})}
|
|
17
|
-
P.prototype.isExpired=function(a){a=a?a:this.a.get();if(a.isExpired)return!0;var b=new Date,c=(a=a.hitTime)&&new Date(a);return a&&(b-c>6E4*this.timeout||this.c&&this.c.format(b)!=this.c.format(c))?!0:!1};P.prototype.b=function(a){var b=this;return function(c){a(c);var d=b.a.get(),e=b.isExpired(d);c=c.get("sessionControl");d.hitTime=+new Date;if("start"==c||e)d.isExpired=!1;"end"==c&&(d.isExpired=!0);b.a.set(d)}};P.prototype.i=function(){var a=this.b;C(D(this.f,"sendHitTask"),a);this.a.i();delete oa[this.f.get("trackingId")]};
|
|
18
|
-
var Q=30,R={D:1,F:2,G:3,H:4,I:5,w:6,A:7,J:8,B:9,v:10},S=Object.keys(R).length;function T(a,b){a.set("\x26_av","2.0.1");var c=a.get("\x26_au"),c=parseInt(c||"0",16).toString(2);if(c.length<S)for(var d=S-c.length;d;)c="0"+c,d--;b=S-b;c=c.substr(0,b)+1+c.substr(b+1);a.set("\x26_au",parseInt(c||"0",2).toString(16))}
|
|
19
|
-
function U(a,b){T(a,R.v);window.addEventListener&&(this.a=F({increaseThreshold:20,sessionTimeout:Q,fieldsObj:{}},b),this.c=a,this.b=pa(this),this.f=ma(this.f.bind(this)),this.h=this.h.bind(this),this.g=M(a.get("trackingId"),"plugins/max-scroll-tracker"),this.j=new P(a,this.a.sessionTimeout,this.a.timeZone),b=this.h,z(D(a,"set"),b),qa(this))}function qa(a){100>(a.g.get()[a.b]||0)&&window.addEventListener("scroll",a.f)}
|
|
20
|
-
U.prototype.f=function(){var a=document.documentElement,b=document.body,a=Math.min(100,Math.max(0,Math.round(window.pageYOffset/(Math.max(a.offsetHeight,a.scrollHeight,b.offsetHeight,b.scrollHeight)-window.innerHeight)*100)));if(this.j.isExpired())window.localStorage&&window.localStorage.removeItem(this.g.key);else if(b=this.g.get()[this.b]||0,a>b&&(100!=a&&100!=b||window.removeEventListener("scroll",this.f),b=a-b,100==a||b>=this.a.increaseThreshold)){var c={};this.g.set((c[this.b]=a,c));a={transport:"beacon",
|
|
21
|
-
eventCategory:"Max Scroll",eventAction:"increase",eventValue:b,eventLabel:String(a),nonInteraction:!0};this.a.maxScrollMetricIndex&&(a["metric"+this.a.maxScrollMetricIndex]=b);this.c.send("event",E(a,this.a.fieldsObj,this.c,this.a.hitFilter))}};U.prototype.h=function(a){var b=this;return function(c){for(var d=[],e=0;e<arguments.length;++e)d[e-0]=arguments[e];a.apply(null,[].concat(m(d)));e={};(G(d[0])?d[0]:(e[d[0]]=d[1],e)).page&&(d=b.b,b.b=pa(b),b.b!=d&&qa(b))}};
|
|
22
|
-
function pa(a){a=w(a.c.get("page")||a.c.get("location"));return a.pathname+a.search}U.prototype.remove=function(){this.j.i();window.removeEventListener("scroll",this.f);var a=this.h;C(D(this.c,"set"),a)};H("maxScrollTracker",U);
|
|
23
|
-
function V(a,b){var c=this;T(a,R.w);window.addEventListener&&(this.a=F({events:["click"],linkSelector:"a, area",shouldTrackOutboundLink:this.shouldTrackOutboundLink,fieldsObj:{},attributePrefix:"ga-"},b),this.f=a,this.c=this.c.bind(this),this.b={},this.a.events.forEach(function(a){c.b[a]=ha(a,c.a.linkSelector,c.c)}))}
|
|
24
|
-
V.prototype.c=function(a,b){if(this.a.shouldTrackOutboundLink(b,w)){var c=b.getAttribute("href")||b.getAttribute("xlink:href"),d=w(c),e={transport:"beacon",eventCategory:"Outbound Link",eventAction:a.type,eventLabel:d.href};navigator.sendBeacon||"click"!=a.type||"_blank"==b.target||a.metaKey||a.ctrlKey||a.shiftKey||a.altKey||1<a.which||window.addEventListener("click",function(a){a.defaultPrevented||(a.preventDefault(),e.hitCallback=na(function(){location.href=c}))});a=F({},this.a.fieldsObj,ka(b,this.a.attributePrefix));
|
|
25
|
-
this.f.send("event",E(e,a,this.f,this.a.hitFilter,b))}};V.prototype.shouldTrackOutboundLink=function(a,b){a=a.getAttribute("href")||a.getAttribute("xlink:href");b=b(a);return b.hostname!=location.hostname&&"http"==b.protocol.slice(0,4)};V.prototype.remove=function(){var a=this;Object.keys(this.b).forEach(function(b){a.b[b].i()})};H("outboundLinkTracker",V);
|
|
26
|
-
function W(a,b){T(a,R.B);history.pushState&&window.addEventListener&&(this.a=F({shouldTrackUrlChange:this.shouldTrackUrlChange,trackReplaceState:!1,fieldsObj:{},hitFilter:null},b),this.g=a,this.h=location.pathname+location.search,this.c=this.c.bind(this),this.f=this.f.bind(this),this.b=this.b.bind(this),a=this.c,z(D(history,"pushState"),a),a=this.f,z(D(history,"replaceState"),a),window.addEventListener("popstate",this.b))}
|
|
27
|
-
W.prototype.c=function(a){var b=this;return function(c){for(var d=[],e=0;e<arguments.length;++e)d[e-0]=arguments[e];a.apply(null,[].concat(m(d)));X(b,!0)}};W.prototype.f=function(a){var b=this;return function(c){for(var d=[],e=0;e<arguments.length;++e)d[e-0]=arguments[e];a.apply(null,[].concat(m(d)));X(b,!1)}};W.prototype.b=function(){X(this,!0)};
|
|
28
|
-
function X(a,b){setTimeout(function(){var c=a.h,d=location.pathname+location.search;c!=d&&a.a.shouldTrackUrlChange.call(a,d,c)&&(a.h=d,a.g.set({page:d,title:document.title}),(b||a.a.trackReplaceState)&&a.g.send("pageview",E({transport:"beacon"},a.a.fieldsObj,a.g,a.a.hitFilter)))},0)}W.prototype.shouldTrackUrlChange=function(a,b){return!(!a||!b)};W.prototype.remove=function(){var a=this.c;C(D(history,"pushState"),a);a=this.f;C(D(history,"replaceState"),a);window.removeEventListener("popstate",this.b)};
|
|
29
|
-
H("urlChangeTracker",W);var Y=function ra(b){return b?(b^16*Math.random()>>b/4).toString(16):"10000000-1000-4000-8000-100000000000".replace(/[018]/g,ra)}();
|
|
30
|
-
function Z(a,b){T(a,R.A);if(window.addEventListener){this.a=F({sessionTimeout:Q,fieldsObj:{}},b);this.f=a;this.j=null;this.g=this.g.bind(this);this.b=this.b.bind(this);this.h=this.h.bind(this);this.o=this.o.bind(this);this.c=M(a.get("trackingId"),"plugins/page-visibility-tracker");b=this.o;var c=this.c;(c.a.externalSet=c.a.externalSet||[]).push(b);this.m=new P(a,this.a.sessionTimeout,this.a.timeZone);b=this.g;z(D(a,"set"),b);document.addEventListener("visibilitychange",this.b);window.addEventListener("unload",
|
|
31
|
-
this.h);"visible"==document.visibilityState&&this.b()}}
|
|
32
|
-
Z.prototype.b=function(){var a=this.c.get();"visible"==this.j&&"hidden"==a.state&&a.pageId!=Y&&(a.state="visible",a.pageId=Y,this.c.set(a));var b={time:+new Date,state:document.visibilityState,pageId:Y};this.m.isExpired()?"hidden"==document.visibilityState?window.localStorage&&window.localStorage.removeItem(this.c.key):(this.f.send("pageview",E({transport:"beacon"},this.a.fieldsObj,this.f,this.a.hitFilter)),this.c.set(b)):(a.pageId==Y&&"visible"==a.state&&sa(this,a),this.c.set(b));this.j=document.visibilityState};
|
|
33
|
-
function sa(a,b,c){var d={transport:"beacon",nonInteraction:!0,eventCategory:"Page Visibility",eventAction:"track",eventLabel:"(not set)"};c&&(d.K=+new Date-c);var e=c,e=void 0===e?+new Date:e;c=!a.m.isExpired();b=b.time&&Math.round((e-b.time)/1E3);if(b=c&&0<b?b:0)d.eventValue=b,a.a.visibleMetricIndex&&(d["metric"+a.a.visibleMetricIndex]=b);a.f.send("event",E(d,a.a.fieldsObj,a.f,a.a.hitFilter))}
|
|
34
|
-
Z.prototype.g=function(a){var b=this;return function(c){for(var d=[],e=0;e<arguments.length;++e)d[e-0]=arguments[e];e={};e=G(d[0])?d[0]:(e[d[0]]=d[1],e);e.page&&e.page!==b.f.get("page")&&"visible"==b.j&&b.b();a.apply(null,[].concat(m(d)))}};Z.prototype.o=function(a,b){a.time!=b.time&&b.pageId==Y&&"visible"==b.state&&sa(this,b,a.time)};Z.prototype.h=function(){"hidden"!=this.j&&this.b()};
|
|
35
|
-
Z.prototype.remove=function(){this.m.i();var a=this.g;C(D(this.f,"set"),a);window.removeEventListener("unload",this.h);document.removeEventListener("visibilitychange",this.b)};H("pageVisibilityTracker",Z);})();
|
|
36
|
-
//# sourceMappingURL=autotrack.js.map
|