j1-template 2021.2.12 → 2021.3.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.
- checksums.yaml +4 -4
- data/_layouts/compress.html +12 -4
- data/assets/data/private.json +49 -0
- data/assets/themes/j1/adapter/js/{j1scroll.js → scroller.js} +285 -304
- data/assets/themes/j1/core/js/template.js +4098 -223
- data/assets/themes/j1/core/js/template.min.js +9 -8
- data/assets/themes/j1/core/js/template.min.js.map +1 -1
- data/assets/themes/j1/modules/{j1Deepl/js/j1deepl.js → deeplAPI/js/deeplAPI.js} +36 -11
- data/assets/themes/j1/modules/deeplAPI/js/deeplAPI.min.js +18 -0
- data/assets/themes/j1/modules/{j1Scroll → scroller}/css/theme/uno.css +2 -2
- data/assets/themes/j1/modules/{j1Scroll → scroller}/css/theme/uno.min.css +0 -0
- data/assets/themes/j1/modules/scroller/js/scroller.js +346 -0
- data/assets/themes/j1/modules/scroller/js/scroller.min.js +15 -0
- data/lib/j1/version.rb +1 -1
- data/lib/starter_web/Gemfile +1 -1
- data/lib/starter_web/_config.yml +6 -2
- data/lib/starter_web/_data/modules/{j1scroll.yml → scroller.yml} +30 -5
- data/lib/starter_web/_data/private.default.yml +8 -1
- data/lib/starter_web/_data/private.yml +8 -1
- data/lib/starter_web/_data/resources.yml +14 -35
- data/lib/starter_web/_includes/attributes.asciidoc +1 -1
- data/lib/starter_web/_plugins/lunr_index.rb +1 -1
- data/lib/starter_web/index.html +2 -1
- data/lib/starter_web/package.json +1 -1
- data/lib/starter_web/pages/public/blog/navigator/index.html +1 -1
- data/lib/starter_web/pages/public/manuals/dropdown-help.adoc +743 -743
- data/lib/starter_web/utilsrv/_defaults/package.json +1 -1
- data/lib/starter_web/utilsrv/package.json +1 -1
- metadata +11 -12
- data/assets/themes/j1/modules/j1Deepl/js/j1deepl.min.js +0 -18
- data/assets/themes/j1/modules/j1Scroll/js/j1scroll.js +0 -280
- data/assets/themes/j1/modules/j1Scroll/js/j1scroll.min.js +0 -15
- data/assets/themes/j1/modules/showOnScroll/js/showOnScroll.js +0 -73
- data/assets/themes/j1/modules/showOnScroll/js/showOnScroll.min.js +0 -15
@@ -1,743 +1,743 @@
|
|
1
|
-
---
|
2
|
-
title: Manuals
|
3
|
-
tagline: MsDropdown
|
4
|
-
date: 2021-03-07 00:00:00
|
5
|
-
description: >
|
6
|
-
The template comes with a Web included, a skeleton for
|
7
|
-
a new website created with J1 Template. This Web is called
|
8
|
-
the "Starter web", a general-purpose scaffold to be modified
|
9
|
-
for your needs.
|
10
|
-
|
11
|
-
categories: [ Manuals ]
|
12
|
-
tags: [ MsDropdown ]
|
13
|
-
|
14
|
-
comments: true
|
15
|
-
fam_menu_id: page_ctrl_simple
|
16
|
-
|
17
|
-
permalink: /pages/public/manuals/msDropdown/
|
18
|
-
regenerate: false
|
19
|
-
|
20
|
-
resources: [ clipboard, rouge ]
|
21
|
-
resource_options:
|
22
|
-
- attic:
|
23
|
-
padding_top: 400
|
24
|
-
padding_bottom: 50
|
25
|
-
opacity: 0.5
|
26
|
-
slides:
|
27
|
-
- url: /assets/images/modules/attics/matthew-dockery-1920x1280.jpg
|
28
|
-
alt: Photo by Matthew Dockery on Unsplash
|
29
|
-
badge:
|
30
|
-
type: unsplash
|
31
|
-
author: Matthew Dockery
|
32
|
-
href: https://unsplash.com/@matt_dockery
|
33
|
-
---
|
34
|
-
|
35
|
-
== MsDropdown properties
|
36
|
-
|
37
|
-
=== Attributes
|
38
|
-
|
39
|
-
Besides selectedIndex, options, name, size, multiple, etc attributes/properties,
|
40
|
-
msDropdown reads below attributes too.
|
41
|
-
|
42
|
-
.msDropdown attributes
|
43
|
-
[cols="4a,8a", options="header", width="100%", role="rtable mt-3"]
|
44
|
-
|===
|
45
|
-
|Name |Description
|
46
|
-
|
47
|
-
|`autofocus`
|
48
|
-
|As the name suggests, this attribute lets you choose that a form control
|
49
|
-
should have autofocus when the page is loaded. Only one element can have
|
50
|
-
autofocus.
|
51
|
-
|
52
|
-
|`disabled`
|
53
|
-
|If this property is enabled, you won't be able to interact with the
|
54
|
-
element.
|
55
|
-
|
56
|
-
|`form`
|
57
|
-
|It returns the name of the <form> element to associate the <select>
|
58
|
-
with. This is readonly property.
|
59
|
-
|
60
|
-
|`name`
|
61
|
-
|It returns the name of the <select> element.
|
62
|
-
|
63
|
-
|`required`
|
64
|
-
|A Boolean attribute indicating that an option with a non-empty string
|
65
|
-
value must be selected. Here is a surprise; you can change the default
|
66
|
-
message too. Just set the
|
67
|
-
`data-error-message="Your custom message here"` in `<select>`.
|
68
|
-
|
69
|
-
|===
|
70
|
-
|
71
|
-
=== Data attributes
|
72
|
-
|
73
|
-
.msDropdown Data attributes
|
74
|
-
[cols="4a,8a", options="header", width="100%", role="rtable mt-3"]
|
75
|
-
|===
|
76
|
-
|Name |Description
|
77
|
-
|
78
|
-
|`data-main-css`
|
79
|
-
|This is the main CSS class. Default value is `ms-dd`
|
80
|
-
|
81
|
-
|`data-show-icon`
|
82
|
-
|If you are in need to hide the icon on the header. The default value
|
83
|
-
is: `true`
|
84
|
-
|
85
|
-
|`data-event`
|
86
|
-
|To interact msDropdown with an event. The default value is: `click`
|
87
|
-
|
88
|
-
|`data-child-width`
|
89
|
-
|Sometimes you need a list of children bigger than the dropdown. This can
|
90
|
-
help. The default value is: `null` or whatever is defined in the CSS.
|
91
|
-
|
92
|
-
|`data-child-height`
|
93
|
-
|By default, it shows all the options listed in the dropdown. If you
|
94
|
-
need to show some rows you can use this attribute. The default value is:
|
95
|
-
`null`
|
96
|
-
|
97
|
-
|`data-enable-checkbox`
|
98
|
-
|If you enable this; multiple will automatically set to true. It shows a
|
99
|
-
checkbox with each list item. The default value is: `false`
|
100
|
-
|
101
|
-
|`data-checkbox-name-suffix`
|
102
|
-
|If the checkbox is enabled; there is an extra field will be posted
|
103
|
-
with the form. Say <select> name is "tech" and checkbox is enabled,
|
104
|
-
tech_mscheck[] will be posted as an array. The default value is:
|
105
|
-
`{select_name}_mscheck`
|
106
|
-
|
107
|
-
|`data-enable-auto-filter`
|
108
|
-
|It lets you search by typing any key when msDropdown is open. Just like
|
109
|
-
auto-suggest. The default value is: `true`
|
110
|
-
|
111
|
-
|`data-visible-rows`
|
112
|
-
|If you set this attribute, it calculates the max height of the items
|
113
|
-
and sets the child height based on the number provided in value. You can
|
114
|
-
also achieve this by using the data-child-height property, only that set
|
115
|
-
in pixels. The default value is: `null`
|
116
|
-
|
117
|
-
|`data-show-plus-item-counter`
|
118
|
-
|If multiple is true and you select more than one item; it shows a text
|
119
|
-
+N. N denotes numbers here. The default value is: `true`
|
120
|
-
|
121
|
-
|`data-error-message`
|
122
|
-
|If `required` is enabled in <select> it shows a required message. Guess
|
123
|
-
what? You can change that by setting this attribute. The default value
|
124
|
-
is: `Please select an item from this list`
|
125
|
-
|===
|
126
|
-
|
127
|
-
=== Option attributes
|
128
|
-
|
129
|
-
Besides value, text, selected, disabled, class, and style attributes/properties.
|
130
|
-
msDropdown reads the below attributes too.
|
131
|
-
|
132
|
-
.msDropdown Option attributes
|
133
|
-
[cols="4a,8a", options="header", width="100%", role="rtable mt-3"]
|
134
|
-
|===
|
135
|
-
|Name |Description
|
136
|
-
|
137
|
-
|`data-image`
|
138
|
-
|This attribute is used to display an image in an item
|
139
|
-
|
140
|
-
|`data-title`
|
141
|
-
|If you need to display any text on hover of an item
|
142
|
-
|
143
|
-
|`data-description`
|
144
|
-
|To display a description along with the text in the next line.
|
145
|
-
|
146
|
-
|`data-image-css`
|
147
|
-
|You may use this if you want to display an image using CSS.
|
148
|
-
|
149
|
-
|===
|
150
|
-
|
151
|
-
== MsDropdown API
|
152
|
-
|
153
|
-
It's always good to explore more and more. Let's do it then.
|
154
|
-
|
155
|
-
=== Set and get properties
|
156
|
-
|
157
|
-
.msDropdown properties
|
158
|
-
[cols="4a,8a", options="header", width="100%", role="rtable mt-3"]
|
159
|
-
|===
|
160
|
-
|Name |Description
|
161
|
-
|
162
|
-
|`selectedIndex`
|
163
|
-
|This property is used to set and get the selected index. +
|
164
|
-
|
165
|
-
[source, js]
|
166
|
-
----
|
167
|
-
let ddSelect = document.getElementById("tech").msDropdown;
|
168
|
-
//To set the value
|
169
|
-
ddSelect.selectedIndex = 3;
|
170
|
-
|
171
|
-
//To get get value
|
172
|
-
let index = ddSelect.selectedIndex;
|
173
|
-
----
|
174
|
-
|
175
|
-
|`options`
|
176
|
-
|This returns `<option>` (HTMLOptionsCollection) elements. You can set
|
177
|
-
the length of option with this property too. +
|
178
|
-
|
179
|
-
|`length`
|
180
|
-
|To set and get the length of the options.
|
181
|
-
|
182
|
-
|`value`
|
183
|
-
|Returns the selected value
|
184
|
-
|
185
|
-
|`selectedText (readonly)`
|
186
|
-
|This returns the selected text of the dropdown.
|
187
|
-
|
188
|
-
|`disabled`
|
189
|
-
|To make dropdown enable or disabled. You won't be able to interact with
|
190
|
-
msDropdown when it is disabled.
|
191
|
-
|
192
|
-
|`form (readonly)`
|
193
|
-
|This returns the associated `<form>` else null.
|
194
|
-
|
195
|
-
|`multiple`
|
196
|
-
|This property is used to set or get the multiple. You may be able to
|
197
|
-
select more than one item if multiple is true.
|
198
|
-
|
199
|
-
|`name`
|
200
|
-
|This returns the name of the <select>. I should mention here; msDropdown
|
201
|
-
borrows the name from the original dropdown to work the "required"
|
202
|
-
attribute.
|
203
|
-
|
204
|
-
|`required`
|
205
|
-
|A Boolean attribute indicating that an option with a non-empty string
|
206
|
-
value must be selected. Here is a surprise; you can change the default
|
207
|
-
message too. Just set the
|
208
|
-
`data-error-message="Your custom message here"` in `<select>`.
|
209
|
-
|
210
|
-
|`size`
|
211
|
-
|If the size is greater than 1, It will be converted as a list. The size
|
212
|
-
determines the number of rows to show.
|
213
|
-
|
214
|
-
|`selectedOptions (readonly)`
|
215
|
-
|It returns the selected <option>.
|
216
|
-
|
217
|
-
|`children (readonly)`
|
218
|
-
|It returns the list of options.
|
219
|
-
|
220
|
-
|`uiData (readonly)`
|
221
|
-
|It returns the selected data. You may find the following properties in
|
222
|
-
this one object. `isArray` will be true if data,UI, index etc will be
|
223
|
-
return as an array. +
|
224
|
-
|
225
|
-
[source, js]
|
226
|
-
----
|
227
|
-
{data: {
|
228
|
-
"image": "../dist/images/icons/icon_games.gif",
|
229
|
-
"title": "",
|
230
|
-
"description": "",
|
231
|
-
"value": "games",
|
232
|
-
"text": "Games",
|
233
|
-
"className": "",
|
234
|
-
"imageCss": "",
|
235
|
-
"index": 2,
|
236
|
-
"selected": true,
|
237
|
-
"disabled": false,
|
238
|
-
"internalStyle": ""
|
239
|
-
},
|
240
|
-
ui: <li>,
|
241
|
-
index: 2,
|
242
|
-
option: <options>,
|
243
|
-
isArray:false
|
244
|
-
}
|
245
|
-
----
|
246
|
-
|
247
|
-
|`version (readonly)`
|
248
|
-
|This returns the current version of the msDropdown.
|
249
|
-
|
250
|
-
|===
|
251
|
-
|
252
|
-
=== Access or set these properties
|
253
|
-
|
254
|
-
Here is an example. The below dropdown id is "tech". Each element has a
|
255
|
-
new property called "msDropdown" once it's converted to msDropdown/image
|
256
|
-
dropdown. You can access all the public properties and methods from that
|
257
|
-
one.
|
258
|
-
|
259
|
-
[source, js]
|
260
|
-
----
|
261
|
-
let ddSelect = document.getElementById("tech").msDropdown;
|
262
|
-
----
|
263
|
-
|
264
|
-
Select a property:
|
265
|
-
|
266
|
-
Reminder: I've made `ddSelect` as a global variable on this page. You
|
267
|
-
can play with that in `console`.
|
268
|
-
|
269
|
-
selectedIndex options length selectedText disabled form multiple name
|
270
|
-
required size selectedOptions children uiData
|
271
|
-
|
272
|
-
Try to copy-paste the below code in the console. You can set and get all
|
273
|
-
the properties.
|
274
|
-
|
275
|
-
[source, js]
|
276
|
-
----
|
277
|
-
ddSelect.selectedIndex = 0;
|
278
|
-
----
|
279
|
-
|
280
|
-
=== Public methods
|
281
|
-
|
282
|
-
.Public methods
|
283
|
-
[cols="4a,8a", options="header", width="100%", role="rtable mt-3"]
|
284
|
-
|===
|
285
|
-
|Name |Description
|
286
|
-
|
287
|
-
|`setSettingAttribute`
|
288
|
-
|Set the settings attributes, and you have an option to remake the
|
289
|
-
msDropdown by passing `true` in the last argument. +
|
290
|
-
|
291
|
-
[source, js]
|
292
|
-
----
|
293
|
-
/**
|
294
|
-
*
|
295
|
-
* @param key
|
296
|
-
* @param value
|
297
|
-
* @param shouldRefresh
|
298
|
-
*/
|
299
|
-
setSettingAttribute(key, value, shouldRefresh);
|
300
|
-
----
|
301
|
-
|
302
|
-
Below are available keys and default values: +
|
303
|
-
[source, js]
|
304
|
-
----
|
305
|
-
{
|
306
|
-
byJson: {
|
307
|
-
data: null, selectedIndex: 0, name: null,
|
308
|
-
size: 0, multiple: false, width: 250
|
309
|
-
},
|
310
|
-
mainCss: 'ms-dd',
|
311
|
-
rowHeight: null,
|
312
|
-
visibleRows: null,
|
313
|
-
showIcon: true,
|
314
|
-
zIndex: 9999,
|
315
|
-
event:'click',
|
316
|
-
style: '',
|
317
|
-
childWidth:null,
|
318
|
-
childHeight:null,
|
319
|
-
enableCheckbox:false,
|
320
|
-
checkboxNameSuffix:'_mscheck',
|
321
|
-
showPlusItemCounter:true,
|
322
|
-
enableAutoFilter:true,
|
323
|
-
showListCounter:false,
|
324
|
-
errorMessage:'Please select an item from this list',
|
325
|
-
on: {create: null,open: null,close: null,add: null,remove: null,
|
326
|
-
change: null,blur: null,click: null,dblclick: null,mousemove: null,
|
327
|
-
mouseover: null,mouseout: null,focus: null,mousedown: null,mouseup: null}
|
328
|
-
}
|
329
|
-
----
|
330
|
-
|
331
|
-
|`add`
|
332
|
-
|Add an item to select. You can pass second param as index; where you
|
333
|
-
want to insert this item. +
|
334
|
-
|
335
|
-
[source, js]
|
336
|
-
----
|
337
|
-
/**
|
338
|
-
* Object can be pass as below
|
339
|
-
* new Option("Label", "value") or
|
340
|
-
* {text:"Label", value:"value"}
|
341
|
-
* or Label as string
|
342
|
-
* or full object ie {text:"", value:"", description:'', image:'', className:'' title:'', imageCss:''}
|
343
|
-
* @param obj {option \| object}
|
344
|
-
* @param index {int}
|
345
|
-
*/
|
346
|
-
add(item, index);
|
347
|
-
|
348
|
-
// You may use any of the below example
|
349
|
-
//
|
350
|
-
ddSelect.add("HashtagCms");
|
351
|
-
ddSelect.add(new Option("HashtagCms", "https://www.hashtagcms.org"));
|
352
|
-
ddSelect.add({text:"HashtagCms", value:"https://www.hashtagcms.org"});
|
353
|
-
ddSelect.add({text:"HashtagCms", value:"https://www.hashtagcms.org", description:"Laravel open-source CMS"});
|
354
|
-
----
|
355
|
-
|
356
|
-
|`remove`
|
357
|
-
|Remove an item from <select>. And it returns the removed item with
|
358
|
-
uiData. +
|
359
|
-
|
360
|
-
[source, js]
|
361
|
-
----
|
362
|
-
/**
|
363
|
-
* @param index {int}
|
364
|
-
* @return uiData
|
365
|
-
*/
|
366
|
-
remove(index)
|
367
|
-
----
|
368
|
-
|
369
|
-
|`next`
|
370
|
-
|Move to the next index/item +
|
371
|
-
|
372
|
-
[source, js]
|
373
|
-
----
|
374
|
-
next()
|
375
|
-
----
|
376
|
-
|
377
|
-
|`previous`
|
378
|
-
|Move to the previous index/item +
|
379
|
-
|
380
|
-
[source, js]
|
381
|
-
----
|
382
|
-
previous()
|
383
|
-
----
|
384
|
-
|
385
|
-
|`open`
|
386
|
-
|Open the dropdown +
|
387
|
-
|
388
|
-
[source, js]
|
389
|
-
----
|
390
|
-
open()
|
391
|
-
----
|
392
|
-
|
393
|
-
|`close`
|
394
|
-
|Close the dropdown +
|
395
|
-
|
396
|
-
[source, js]
|
397
|
-
----
|
398
|
-
close()
|
399
|
-
----
|
400
|
-
|
401
|
-
|`namedItem`
|
402
|
-
|If you have given any name of an option, will be returned. say, <option
|
403
|
-
name="cd"></option> +
|
404
|
-
|
405
|
-
[source, js]
|
406
|
-
----
|
407
|
-
/**
|
408
|
-
* @param name {string}
|
409
|
-
* @param withData {boolean}
|
410
|
-
*/
|
411
|
-
namedItem(name, withData)
|
412
|
-
----
|
413
|
-
|
414
|
-
|`item`
|
415
|
-
|Return `<option>` element based on the index that you have passed in the
|
416
|
-
argument. `uiData` will also be returned if you pass withData=true +
|
417
|
-
|
418
|
-
[source, js]
|
419
|
-
----
|
420
|
-
/**
|
421
|
-
* @param index {int}
|
422
|
-
* @param withData {boolean}
|
423
|
-
*/
|
424
|
-
item(index, withData)
|
425
|
-
----
|
426
|
-
|
427
|
-
|`visible`
|
428
|
-
|Show hide or get status of visibility. +
|
429
|
-
|
430
|
-
[source, js]
|
431
|
-
----
|
432
|
-
/**
|
433
|
-
* @param isShow
|
434
|
-
* @return {boolean}
|
435
|
-
*/
|
436
|
-
visible
|
437
|
-
----
|
438
|
-
|
439
|
-
| `showRows` \| `visibleRows`
|
440
|
-
|Calculate first item height and set child height. +
|
441
|
-
|
442
|
-
[source, js]
|
443
|
-
----
|
444
|
-
/**
|
445
|
-
* @param numberOfRows {int}
|
446
|
-
*/
|
447
|
-
showRows(numberOfRows)
|
448
|
-
----
|
449
|
-
|
450
|
-
|`on`
|
451
|
-
|Add an event on the dropdown. Below are possible event types you can
|
452
|
-
pass in the argument:
|
453
|
-
|
454
|
-
`create` \| `open` \| `close` \| `add` \| `remove` \| `change` \|
|
455
|
-
`blur` \| `click` \| `dblclick` \| `mousemove` \| `mouseover` \|
|
456
|
-
`mouseout` \| `focus` \| `mousedown` \| `mouseup` +
|
457
|
-
|
458
|
-
[source, js]
|
459
|
-
----
|
460
|
-
/**
|
461
|
-
* @param type {string}
|
462
|
-
* @param fn {function}
|
463
|
-
*/
|
464
|
-
on(type, fn)
|
465
|
-
----
|
466
|
-
|
467
|
-
.Example
|
468
|
-
[source, js]
|
469
|
-
----
|
470
|
-
ddSelect.on("change", function() {console.log(ddSelect.uiData});
|
471
|
-
----
|
472
|
-
|
473
|
-
|`off`
|
474
|
-
|Remove event listener. +
|
475
|
-
|
476
|
-
[source, js]
|
477
|
-
----
|
478
|
-
/**
|
479
|
-
* @param type {string}
|
480
|
-
* @param fn {function}
|
481
|
-
*/
|
482
|
-
off(type, fn);
|
483
|
-
----
|
484
|
-
|
485
|
-
|`updateUiAndValue`
|
486
|
-
|In case there UI is not updated. You can call this method. +
|
487
|
-
|
488
|
-
[source, js]
|
489
|
-
----
|
490
|
-
updateUiAndValue()
|
491
|
-
----
|
492
|
-
|
493
|
-
|`refresh`
|
494
|
-
|Recreatea a msDropdown. +
|
495
|
-
|
496
|
-
[source, js]
|
497
|
-
----
|
498
|
-
refresh()
|
499
|
-
----
|
500
|
-
|
501
|
-
|`destroy`
|
502
|
-
|Remove msDropdown and returns back to the original dropdown. +
|
503
|
-
|
504
|
-
[source, js]
|
505
|
-
----
|
506
|
-
destroy()
|
507
|
-
----
|
508
|
-
|
509
|
-
|===
|
510
|
-
|
511
|
-
|
512
|
-
== Examples
|
513
|
-
|
514
|
-
|
515
|
-
=== Simple dropdown
|
516
|
-
|
517
|
-
Email FAQ Games Music Phone Graph Secured Video CD
|
518
|
-
|
519
|
-
There are two ways that you can apply msDropdown on <select> element
|
520
|
-
|
521
|
-
. You can add `is="ms-dropdown"`attributes. Like we have in the
|
522
|
-
below example.
|
523
|
-
|
524
|
-
[source, html]
|
525
|
-
----
|
526
|
-
<select class="tech" name="tech" is="ms-dropdown">
|
527
|
-
<option value="" selected>Please select one</option>
|
528
|
-
<option data-image="./dist/images/icons/icon_email.gif" value="email">Email</option>
|
529
|
-
<option data-image="./dist/images/icons/icon_faq.gif" value="faq">FAQ</option>
|
530
|
-
<option data-image="./dist/images/icons/icon_games.gif" value="games">Games</option>
|
531
|
-
<option data-image="./dist/images/icons/icon_music.gif" value="music">Music</option>
|
532
|
-
<option data-image="./dist/images/icons/icon_phone.gif" value="phone">Phone</option>
|
533
|
-
<option data-image="./dist/images/icons/icon_sales.gif" value="graph">Graph</option>
|
534
|
-
<option data-image="./dist/images/icons/icon_secure.gif" value="secured">Secured</option>
|
535
|
-
<option data-image="./dist/images/icons/icon_video.gif" value="video">Video</option>
|
536
|
-
<option data-image="./dist/images/icons/icon_cd.gif" name="cd" value="cd">CD</option>
|
537
|
-
</select>
|
538
|
-
----
|
539
|
-
|
540
|
-
[start=2]
|
541
|
-
. You don't need the below code if you have already included
|
542
|
-
`dd.min.js` in the bottom of the page. Like I've mentioned in the
|
543
|
-
installation section. +
|
544
|
-
|
545
|
-
In case you want to convert later by script, you can use the below code.
|
546
|
-
You may use a CSS selector too. +
|
547
|
-
|
548
|
-
[source, js]
|
549
|
-
----
|
550
|
-
MsDropdown.make('#select_element');
|
551
|
-
//or
|
552
|
-
new MsDropdown('.select_elements');
|
553
|
-
----
|
554
|
-
|
555
|
-
=== Dropdown with description
|
556
|
-
|
557
|
-
Did you notice? There is an extra attribute `data-description` in `<option>`.
|
558
|
-
|
559
|
-
[source, html]
|
560
|
-
----
|
561
|
-
<select id="payments" name="payments" is="ms-dropdown" data-enable-auto-filter="false" required>
|
562
|
-
<option value="" data-description="Choose your payment gateway">Payment Gateway</option>
|
563
|
-
<option value="amex" data-image="./dist/images/icons/Amex-56.png" data-description="My life. My card...">Amex</option>
|
564
|
-
<option value="Discover" data-image="./dist/images/icons/Discover-56.png" data-description="It pays to Discover...">Discover</option>
|
565
|
-
<option value="Mastercard" data-image="./dist/images/icons/Mastercard-56.png" data-title="For everything else..." data-description="For everything else...">Mastercard</option>
|
566
|
-
<option value="cash" data-image="./dist/images/icons/Cash-56.png" data-description="Pay at your doorstep...">Cash on delivery</option>
|
567
|
-
<option value="Visa" data-image="./dist/images/icons/Visa-56.png" data-description="All you need...">Visa</option>
|
568
|
-
<option value="Paypal" data-image="./dist/images/icons/Paypal-56.png" data-description="Pay and get paid...">Paypal</option>
|
569
|
-
</select>
|
570
|
-
----
|
571
|
-
|
572
|
-
=== Dropdown with checkboxes
|
573
|
-
|
574
|
-
Email FAQ Games Music Phone Graph Secured Video CD
|
575
|
-
|
576
|
-
[source, html]
|
577
|
-
----
|
578
|
-
<select name="tech_with_checkbox" is="ms-dropdown" data-enable-checkbox="true">
|
579
|
-
<option data-image="./dist/images/icons/icon_email.gif" value="email">Email</option>
|
580
|
-
<option data-image="./dist/images/icons/icon_faq.gif" value="faq">FAQ</option>
|
581
|
-
<option data-image="./dist/images/icons/icon_games.gif" selected value="games">Games</option>
|
582
|
-
<option data-image="./dist/images/icons/icon_music.gif" value="music">Music</option>
|
583
|
-
<option data-image="./dist/images/icons/icon_phone.gif" value="phone">Phone</option>
|
584
|
-
<option data-image="./dist/images/icons/icon_sales.gif" value="graph">Graph</option>
|
585
|
-
<option data-image="./dist/images/icons/icon_secure.gif" value="secured">Secured</option>
|
586
|
-
<option data-image="./dist/images/icons/icon_video.gif" value="video">Video</option>
|
587
|
-
<option data-image="./dist/images/icons/icon_cd.gif" name="cd" value="cd">CD</option>
|
588
|
-
</select>
|
589
|
-
----
|
590
|
-
|
591
|
-
=== Option groups
|
592
|
-
|
593
|
-
[source, html]
|
594
|
-
----
|
595
|
-
<select is="ms-dropdown" name="car_group">
|
596
|
-
<optgroup label="Mercedes Benz">
|
597
|
-
<option>Mercedes-Benz GLA</option>
|
598
|
-
<option>Mercedes-Benz S-Class</option>
|
599
|
-
<option>Mercedes-Benz E-Class</option>
|
600
|
-
<option>Mercedes-Benz GLS</option>
|
601
|
-
</optgroup>
|
602
|
-
<optgroup label="Jaguar">
|
603
|
-
<option>Jaguar F-TYPE</option>
|
604
|
-
<option selected>Jaguar XE</option>
|
605
|
-
<option>Jaguar F-Pace</option>
|
606
|
-
<option>Jaguar I-Pace</option>
|
607
|
-
<option>Jaguar XF</option>
|
608
|
-
</optgroup>
|
609
|
-
</select>
|
610
|
-
----
|
611
|
-
|
612
|
-
=== Dropdown with CSS images
|
613
|
-
|
614
|
-
[source, html]
|
615
|
-
----
|
616
|
-
<select name="countries" id="countries" is="ms-dropdown" data-child-height="315">
|
617
|
-
<option value='ad' data-image-css="flag ad" data-title="Andorra">Andorra</option>
|
618
|
-
<option value='ae' data-image-css="flag ae" data-title="United Arab Emirates">United Arab Emirates</option>
|
619
|
-
<option value='af' data-image-css="flag af" data-title="Afghanistan">Afghanistan</option>
|
620
|
-
...
|
621
|
-
<option value='zr' data-image-css="flag zr" data-title="Zaire (former)">Zaire (former)</option>
|
622
|
-
<option value='zw' data-image-css="flag zw" data-title="Zimbabwe">Zimbabwe</option>
|
623
|
-
</select>
|
624
|
-
----
|
625
|
-
|
626
|
-
=== Dropdown as a list
|
627
|
-
|
628
|
-
Please select one Email FAQ Games Music Phone Graph Secured Video CD
|
629
|
-
|
630
|
-
[source, html]
|
631
|
-
----
|
632
|
-
<select name="gameList[]" is="ms-dropdown" multiple size="5">
|
633
|
-
<option value="" selected>Please select one</option>
|
634
|
-
<option data-image="./dist/images/icons/icon_email.gif" value="email">Email</option>
|
635
|
-
<option data-image="./dist/images/icons/icon_faq.gif" value="faq">FAQ</option>
|
636
|
-
<option data-image="./dist/images/icons/icon_games.gif" value="games">Games</option>
|
637
|
-
<option data-image="./dist/images/icons/icon_music.gif" value="music">Music</option>
|
638
|
-
<option data-image="./dist/images/icons/icon_phone.gif" value="phone">Phone</option>
|
639
|
-
<option data-image="./dist/images/icons/icon_sales.gif" value="graph">Graph</option>
|
640
|
-
<option data-image="./dist/images/icons/icon_secure.gif" value="secured">Secured</option>
|
641
|
-
<option data-image="./dist/images/icons/icon_video.gif" value="video">Video</option>
|
642
|
-
<option data-image="./dist/images/icons/icon_cd.gif" name="cd" value="cd">CD</option>
|
643
|
-
</select>
|
644
|
-
----
|
645
|
-
|
646
|
-
=== Create Dropdown from JSON object
|
647
|
-
|
648
|
-
[source, js]
|
649
|
-
----
|
650
|
-
[
|
651
|
-
{description:'Choose your payment gateway', value:'', text:'Payment Gateway'},
|
652
|
-
{image:'/assets/mywork/web-components/image-dropdown/images/icons/Amex-56.png', description:'My life. My card...', value:'amex', text:'Amex'},
|
653
|
-
{image:'/assets/mywork/web-components/image-dropdown/images/icons/Discover-56.png', description:'It pays to Discover...', value:'Discover', text:'Discover'},
|
654
|
-
{image:'/assets/mywork/web-components/image-dropdown/images/icons/Mastercard-56.png', title:'For everything else...', description:'For everything else...', value:'Mastercard', text:'Mastercard'},
|
655
|
-
{image:'/assets/mywork/web-components/image-dropdown/images/icons/Cash-56.png', description:'Sorry not available...', value:'cash', text:'Cash on delivery', disabled:true},
|
656
|
-
{image:'/assets/mywork/web-components/image-dropdown/images/icons/Visa-56.png', description:'All you need...', value:'Visa', text:'Visa'},
|
657
|
-
{image:'/assets/mywork/web-components/image-dropdown/images/icons/Paypal-56.png', description:'Pay and get paid...', value:'Paypal', text:'Paypal'}
|
658
|
-
];
|
659
|
-
----
|
660
|
-
|
661
|
-
Below method is being called on "Click here to convert by above json"
|
662
|
-
button.
|
663
|
-
|
664
|
-
[source, html]
|
665
|
-
----
|
666
|
-
<script>
|
667
|
-
function makeDd() {
|
668
|
-
'use strict';
|
669
|
-
//get the data from above json string
|
670
|
-
let json = new function (`return ${document.getElementById('json_data').innerHTML}`)();
|
671
|
-
//clean the holder
|
672
|
-
document.getElementById("json_dropdown").innerHTML = "";
|
673
|
-
|
674
|
-
//convert to msDropdown
|
675
|
-
MsDropdown.make("#json_dropdown", {
|
676
|
-
byJson: {
|
677
|
-
data: json, selectedIndex: 0, name: "json_dropdown",
|
678
|
-
size: 0, multiple: false, width: 450
|
679
|
-
},
|
680
|
-
enableAutoFilter:false
|
681
|
-
});
|
682
|
-
//or we can use like this too.
|
683
|
-
/*new MsDropdown(document.getElementById("json_dropdown"), {
|
684
|
-
byJson: {
|
685
|
-
data: json, name: "json_dropdown"
|
686
|
-
}
|
687
|
-
});*/
|
688
|
-
}
|
689
|
-
</script>
|
690
|
-
----
|
691
|
-
|
692
|
-
=== What are the settings params
|
693
|
-
|
694
|
-
If you are creating with the help of JavaScript you might need this.
|
695
|
-
So, how do you create it? Syntax is below
|
696
|
-
|
697
|
-
[source, js]
|
698
|
-
----
|
699
|
-
//Style 1
|
700
|
-
MsDropdown.make("element", {...settings});
|
701
|
-
|
702
|
-
//Style 2
|
703
|
-
new MsDropdown(document.getElementById("element_id"), {...settings});
|
704
|
-
----
|
705
|
-
|
706
|
-
And what are the settings params you can pass to the msDropdown? It is
|
707
|
-
similar to the data-attributes, those I've mentioned above in this
|
708
|
-
document. Only difference is that you passed as a camelCase key without
|
709
|
-
the "data-". For example if you want to set child width, you passed in
|
710
|
-
attribute as `data-child-width="300px"` whereas you need to pass in
|
711
|
-
settings as `childWidth:'300px'`
|
712
|
-
|
713
|
-
So, here is an example what you can pass in settings.
|
714
|
-
|
715
|
-
[source, js]
|
716
|
-
----
|
717
|
-
MsDropdown.make("element", {
|
718
|
-
byJson: {
|
719
|
-
data: null, selectedIndex: 0, name: null,
|
720
|
-
size: 0, multiple: false, width: 250
|
721
|
-
},
|
722
|
-
mainCss: 'ms-dd',
|
723
|
-
rowHeight: null,
|
724
|
-
visibleRows: null,
|
725
|
-
showIcon: true,
|
726
|
-
zIndex: 9999,
|
727
|
-
event:'click',
|
728
|
-
style: '',
|
729
|
-
childWidth:null,
|
730
|
-
childHeight:null,
|
731
|
-
enableCheckbox:false,
|
732
|
-
checkboxNameSuffix:'_mscheck',
|
733
|
-
showPlusItemCounter:true,
|
734
|
-
enableAutoFilter:true,
|
735
|
-
showListCounter:false,
|
736
|
-
errorMessage:'Please select an item from this list',
|
737
|
-
on: { create: null,open: null,close: null,add: null,remove: null,
|
738
|
-
change: null,blur: null,click: null,dblclick: null,mousemove: null,
|
739
|
-
mouseover: null,mouseout: null,focus: null,mousedown: null,
|
740
|
-
mouseup: null
|
741
|
-
}
|
742
|
-
});
|
743
|
-
----
|
1
|
+
---
|
2
|
+
title: Manuals
|
3
|
+
tagline: MsDropdown
|
4
|
+
date: 2021-03-07 00:00:00
|
5
|
+
description: >
|
6
|
+
The template comes with a Web included, a skeleton for
|
7
|
+
a new website created with J1 Template. This Web is called
|
8
|
+
the "Starter web", a general-purpose scaffold to be modified
|
9
|
+
for your needs.
|
10
|
+
|
11
|
+
categories: [ Manuals ]
|
12
|
+
tags: [ MsDropdown ]
|
13
|
+
|
14
|
+
comments: true
|
15
|
+
fam_menu_id: page_ctrl_simple
|
16
|
+
|
17
|
+
permalink: /pages/public/manuals/msDropdown/
|
18
|
+
regenerate: false
|
19
|
+
|
20
|
+
resources: [ clipboard, rouge ]
|
21
|
+
resource_options:
|
22
|
+
- attic:
|
23
|
+
padding_top: 400
|
24
|
+
padding_bottom: 50
|
25
|
+
opacity: 0.5
|
26
|
+
slides:
|
27
|
+
- url: /assets/images/modules/attics/matthew-dockery-1920x1280.jpg
|
28
|
+
alt: Photo by Matthew Dockery on Unsplash
|
29
|
+
badge:
|
30
|
+
type: unsplash
|
31
|
+
author: Matthew Dockery
|
32
|
+
href: https://unsplash.com/@matt_dockery
|
33
|
+
---
|
34
|
+
|
35
|
+
== MsDropdown properties
|
36
|
+
|
37
|
+
=== Attributes
|
38
|
+
|
39
|
+
Besides selectedIndex, options, name, size, multiple, etc attributes/properties,
|
40
|
+
msDropdown reads below attributes too.
|
41
|
+
|
42
|
+
.msDropdown attributes
|
43
|
+
[cols="4a,8a", options="header", width="100%", role="rtable mt-3"]
|
44
|
+
|===
|
45
|
+
|Name |Description
|
46
|
+
|
47
|
+
|`autofocus`
|
48
|
+
|As the name suggests, this attribute lets you choose that a form control
|
49
|
+
should have autofocus when the page is loaded. Only one element can have
|
50
|
+
autofocus.
|
51
|
+
|
52
|
+
|`disabled`
|
53
|
+
|If this property is enabled, you won't be able to interact with the
|
54
|
+
element.
|
55
|
+
|
56
|
+
|`form`
|
57
|
+
|It returns the name of the <form> element to associate the <select>
|
58
|
+
with. This is readonly property.
|
59
|
+
|
60
|
+
|`name`
|
61
|
+
|It returns the name of the <select> element.
|
62
|
+
|
63
|
+
|`required`
|
64
|
+
|A Boolean attribute indicating that an option with a non-empty string
|
65
|
+
value must be selected. Here is a surprise; you can change the default
|
66
|
+
message too. Just set the
|
67
|
+
`data-error-message="Your custom message here"` in `<select>`.
|
68
|
+
|
69
|
+
|===
|
70
|
+
|
71
|
+
=== Data attributes
|
72
|
+
|
73
|
+
.msDropdown Data attributes
|
74
|
+
[cols="4a,8a", options="header", width="100%", role="rtable mt-3"]
|
75
|
+
|===
|
76
|
+
|Name |Description
|
77
|
+
|
78
|
+
|`data-main-css`
|
79
|
+
|This is the main CSS class. Default value is `ms-dd`
|
80
|
+
|
81
|
+
|`data-show-icon`
|
82
|
+
|If you are in need to hide the icon on the header. The default value
|
83
|
+
is: `true`
|
84
|
+
|
85
|
+
|`data-event`
|
86
|
+
|To interact msDropdown with an event. The default value is: `click`
|
87
|
+
|
88
|
+
|`data-child-width`
|
89
|
+
|Sometimes you need a list of children bigger than the dropdown. This can
|
90
|
+
help. The default value is: `null` or whatever is defined in the CSS.
|
91
|
+
|
92
|
+
|`data-child-height`
|
93
|
+
|By default, it shows all the options listed in the dropdown. If you
|
94
|
+
need to show some rows you can use this attribute. The default value is:
|
95
|
+
`null`
|
96
|
+
|
97
|
+
|`data-enable-checkbox`
|
98
|
+
|If you enable this; multiple will automatically set to true. It shows a
|
99
|
+
checkbox with each list item. The default value is: `false`
|
100
|
+
|
101
|
+
|`data-checkbox-name-suffix`
|
102
|
+
|If the checkbox is enabled; there is an extra field will be posted
|
103
|
+
with the form. Say <select> name is "tech" and checkbox is enabled,
|
104
|
+
tech_mscheck[] will be posted as an array. The default value is:
|
105
|
+
`{select_name}_mscheck`
|
106
|
+
|
107
|
+
|`data-enable-auto-filter`
|
108
|
+
|It lets you search by typing any key when msDropdown is open. Just like
|
109
|
+
auto-suggest. The default value is: `true`
|
110
|
+
|
111
|
+
|`data-visible-rows`
|
112
|
+
|If you set this attribute, it calculates the max height of the items
|
113
|
+
and sets the child height based on the number provided in value. You can
|
114
|
+
also achieve this by using the data-child-height property, only that set
|
115
|
+
in pixels. The default value is: `null`
|
116
|
+
|
117
|
+
|`data-show-plus-item-counter`
|
118
|
+
|If multiple is true and you select more than one item; it shows a text
|
119
|
+
+N. N denotes numbers here. The default value is: `true`
|
120
|
+
|
121
|
+
|`data-error-message`
|
122
|
+
|If `required` is enabled in <select> it shows a required message. Guess
|
123
|
+
what? You can change that by setting this attribute. The default value
|
124
|
+
is: `Please select an item from this list`
|
125
|
+
|===
|
126
|
+
|
127
|
+
=== Option attributes
|
128
|
+
|
129
|
+
Besides value, text, selected, disabled, class, and style attributes/properties.
|
130
|
+
msDropdown reads the below attributes too.
|
131
|
+
|
132
|
+
.msDropdown Option attributes
|
133
|
+
[cols="4a,8a", options="header", width="100%", role="rtable mt-3"]
|
134
|
+
|===
|
135
|
+
|Name |Description
|
136
|
+
|
137
|
+
|`data-image`
|
138
|
+
|This attribute is used to display an image in an item
|
139
|
+
|
140
|
+
|`data-title`
|
141
|
+
|If you need to display any text on hover of an item
|
142
|
+
|
143
|
+
|`data-description`
|
144
|
+
|To display a description along with the text in the next line.
|
145
|
+
|
146
|
+
|`data-image-css`
|
147
|
+
|You may use this if you want to display an image using CSS.
|
148
|
+
|
149
|
+
|===
|
150
|
+
|
151
|
+
== MsDropdown API
|
152
|
+
|
153
|
+
It's always good to explore more and more. Let's do it then.
|
154
|
+
|
155
|
+
=== Set and get properties
|
156
|
+
|
157
|
+
.msDropdown properties
|
158
|
+
[cols="4a,8a", options="header", width="100%", role="rtable mt-3"]
|
159
|
+
|===
|
160
|
+
|Name |Description
|
161
|
+
|
162
|
+
|`selectedIndex`
|
163
|
+
|This property is used to set and get the selected index. +
|
164
|
+
|
165
|
+
[source, js]
|
166
|
+
----
|
167
|
+
let ddSelect = document.getElementById("tech").msDropdown;
|
168
|
+
//To set the value
|
169
|
+
ddSelect.selectedIndex = 3;
|
170
|
+
|
171
|
+
//To get get value
|
172
|
+
let index = ddSelect.selectedIndex;
|
173
|
+
----
|
174
|
+
|
175
|
+
|`options`
|
176
|
+
|This returns `<option>` (HTMLOptionsCollection) elements. You can set
|
177
|
+
the length of option with this property too. +
|
178
|
+
|
179
|
+
|`length`
|
180
|
+
|To set and get the length of the options.
|
181
|
+
|
182
|
+
|`value`
|
183
|
+
|Returns the selected value
|
184
|
+
|
185
|
+
|`selectedText (readonly)`
|
186
|
+
|This returns the selected text of the dropdown.
|
187
|
+
|
188
|
+
|`disabled`
|
189
|
+
|To make dropdown enable or disabled. You won't be able to interact with
|
190
|
+
msDropdown when it is disabled.
|
191
|
+
|
192
|
+
|`form (readonly)`
|
193
|
+
|This returns the associated `<form>` else null.
|
194
|
+
|
195
|
+
|`multiple`
|
196
|
+
|This property is used to set or get the multiple. You may be able to
|
197
|
+
select more than one item if multiple is true.
|
198
|
+
|
199
|
+
|`name`
|
200
|
+
|This returns the name of the <select>. I should mention here; msDropdown
|
201
|
+
borrows the name from the original dropdown to work the "required"
|
202
|
+
attribute.
|
203
|
+
|
204
|
+
|`required`
|
205
|
+
|A Boolean attribute indicating that an option with a non-empty string
|
206
|
+
value must be selected. Here is a surprise; you can change the default
|
207
|
+
message too. Just set the
|
208
|
+
`data-error-message="Your custom message here"` in `<select>`.
|
209
|
+
|
210
|
+
|`size`
|
211
|
+
|If the size is greater than 1, It will be converted as a list. The size
|
212
|
+
determines the number of rows to show.
|
213
|
+
|
214
|
+
|`selectedOptions (readonly)`
|
215
|
+
|It returns the selected <option>.
|
216
|
+
|
217
|
+
|`children (readonly)`
|
218
|
+
|It returns the list of options.
|
219
|
+
|
220
|
+
|`uiData (readonly)`
|
221
|
+
|It returns the selected data. You may find the following properties in
|
222
|
+
this one object. `isArray` will be true if data,UI, index etc will be
|
223
|
+
return as an array. +
|
224
|
+
|
225
|
+
[source, js]
|
226
|
+
----
|
227
|
+
{data: {
|
228
|
+
"image": "../dist/images/icons/icon_games.gif",
|
229
|
+
"title": "",
|
230
|
+
"description": "",
|
231
|
+
"value": "games",
|
232
|
+
"text": "Games",
|
233
|
+
"className": "",
|
234
|
+
"imageCss": "",
|
235
|
+
"index": 2,
|
236
|
+
"selected": true,
|
237
|
+
"disabled": false,
|
238
|
+
"internalStyle": ""
|
239
|
+
},
|
240
|
+
ui: <li>,
|
241
|
+
index: 2,
|
242
|
+
option: <options>,
|
243
|
+
isArray:false
|
244
|
+
}
|
245
|
+
----
|
246
|
+
|
247
|
+
|`version (readonly)`
|
248
|
+
|This returns the current version of the msDropdown.
|
249
|
+
|
250
|
+
|===
|
251
|
+
|
252
|
+
=== Access or set these properties
|
253
|
+
|
254
|
+
Here is an example. The below dropdown id is "tech". Each element has a
|
255
|
+
new property called "msDropdown" once it's converted to msDropdown/image
|
256
|
+
dropdown. You can access all the public properties and methods from that
|
257
|
+
one.
|
258
|
+
|
259
|
+
[source, js]
|
260
|
+
----
|
261
|
+
let ddSelect = document.getElementById("tech").msDropdown;
|
262
|
+
----
|
263
|
+
|
264
|
+
Select a property:
|
265
|
+
|
266
|
+
Reminder: I've made `ddSelect` as a global variable on this page. You
|
267
|
+
can play with that in `console`.
|
268
|
+
|
269
|
+
selectedIndex options length selectedText disabled form multiple name
|
270
|
+
required size selectedOptions children uiData
|
271
|
+
|
272
|
+
Try to copy-paste the below code in the console. You can set and get all
|
273
|
+
the properties.
|
274
|
+
|
275
|
+
[source, js]
|
276
|
+
----
|
277
|
+
ddSelect.selectedIndex = 0;
|
278
|
+
----
|
279
|
+
|
280
|
+
=== Public methods
|
281
|
+
|
282
|
+
.Public methods
|
283
|
+
[cols="4a,8a", options="header", width="100%", role="rtable mt-3"]
|
284
|
+
|===
|
285
|
+
|Name |Description
|
286
|
+
|
287
|
+
|`setSettingAttribute`
|
288
|
+
|Set the settings attributes, and you have an option to remake the
|
289
|
+
msDropdown by passing `true` in the last argument. +
|
290
|
+
|
291
|
+
[source, js]
|
292
|
+
----
|
293
|
+
/**
|
294
|
+
*
|
295
|
+
* @param key
|
296
|
+
* @param value
|
297
|
+
* @param shouldRefresh
|
298
|
+
*/
|
299
|
+
setSettingAttribute(key, value, shouldRefresh);
|
300
|
+
----
|
301
|
+
|
302
|
+
Below are available keys and default values: +
|
303
|
+
[source, js]
|
304
|
+
----
|
305
|
+
{
|
306
|
+
byJson: {
|
307
|
+
data: null, selectedIndex: 0, name: null,
|
308
|
+
size: 0, multiple: false, width: 250
|
309
|
+
},
|
310
|
+
mainCss: 'ms-dd',
|
311
|
+
rowHeight: null,
|
312
|
+
visibleRows: null,
|
313
|
+
showIcon: true,
|
314
|
+
zIndex: 9999,
|
315
|
+
event:'click',
|
316
|
+
style: '',
|
317
|
+
childWidth:null,
|
318
|
+
childHeight:null,
|
319
|
+
enableCheckbox:false,
|
320
|
+
checkboxNameSuffix:'_mscheck',
|
321
|
+
showPlusItemCounter:true,
|
322
|
+
enableAutoFilter:true,
|
323
|
+
showListCounter:false,
|
324
|
+
errorMessage:'Please select an item from this list',
|
325
|
+
on: {create: null,open: null,close: null,add: null,remove: null,
|
326
|
+
change: null,blur: null,click: null,dblclick: null,mousemove: null,
|
327
|
+
mouseover: null,mouseout: null,focus: null,mousedown: null,mouseup: null}
|
328
|
+
}
|
329
|
+
----
|
330
|
+
|
331
|
+
|`add`
|
332
|
+
|Add an item to select. You can pass second param as index; where you
|
333
|
+
want to insert this item. +
|
334
|
+
|
335
|
+
[source, js]
|
336
|
+
----
|
337
|
+
/**
|
338
|
+
* Object can be pass as below
|
339
|
+
* new Option("Label", "value") or
|
340
|
+
* {text:"Label", value:"value"}
|
341
|
+
* or Label as string
|
342
|
+
* or full object ie {text:"", value:"", description:'', image:'', className:'' title:'', imageCss:''}
|
343
|
+
* @param obj {option \| object}
|
344
|
+
* @param index {int}
|
345
|
+
*/
|
346
|
+
add(item, index);
|
347
|
+
|
348
|
+
// You may use any of the below example
|
349
|
+
//
|
350
|
+
ddSelect.add("HashtagCms");
|
351
|
+
ddSelect.add(new Option("HashtagCms", "https://www.hashtagcms.org"));
|
352
|
+
ddSelect.add({text:"HashtagCms", value:"https://www.hashtagcms.org"});
|
353
|
+
ddSelect.add({text:"HashtagCms", value:"https://www.hashtagcms.org", description:"Laravel open-source CMS"});
|
354
|
+
----
|
355
|
+
|
356
|
+
|`remove`
|
357
|
+
|Remove an item from <select>. And it returns the removed item with
|
358
|
+
uiData. +
|
359
|
+
|
360
|
+
[source, js]
|
361
|
+
----
|
362
|
+
/**
|
363
|
+
* @param index {int}
|
364
|
+
* @return uiData
|
365
|
+
*/
|
366
|
+
remove(index)
|
367
|
+
----
|
368
|
+
|
369
|
+
|`next`
|
370
|
+
|Move to the next index/item +
|
371
|
+
|
372
|
+
[source, js]
|
373
|
+
----
|
374
|
+
next()
|
375
|
+
----
|
376
|
+
|
377
|
+
|`previous`
|
378
|
+
|Move to the previous index/item +
|
379
|
+
|
380
|
+
[source, js]
|
381
|
+
----
|
382
|
+
previous()
|
383
|
+
----
|
384
|
+
|
385
|
+
|`open`
|
386
|
+
|Open the dropdown +
|
387
|
+
|
388
|
+
[source, js]
|
389
|
+
----
|
390
|
+
open()
|
391
|
+
----
|
392
|
+
|
393
|
+
|`close`
|
394
|
+
|Close the dropdown +
|
395
|
+
|
396
|
+
[source, js]
|
397
|
+
----
|
398
|
+
close()
|
399
|
+
----
|
400
|
+
|
401
|
+
|`namedItem`
|
402
|
+
|If you have given any name of an option, will be returned. say, <option
|
403
|
+
name="cd"></option> +
|
404
|
+
|
405
|
+
[source, js]
|
406
|
+
----
|
407
|
+
/**
|
408
|
+
* @param name {string}
|
409
|
+
* @param withData {boolean}
|
410
|
+
*/
|
411
|
+
namedItem(name, withData)
|
412
|
+
----
|
413
|
+
|
414
|
+
|`item`
|
415
|
+
|Return `<option>` element based on the index that you have passed in the
|
416
|
+
argument. `uiData` will also be returned if you pass withData=true +
|
417
|
+
|
418
|
+
[source, js]
|
419
|
+
----
|
420
|
+
/**
|
421
|
+
* @param index {int}
|
422
|
+
* @param withData {boolean}
|
423
|
+
*/
|
424
|
+
item(index, withData)
|
425
|
+
----
|
426
|
+
|
427
|
+
|`visible`
|
428
|
+
|Show hide or get status of visibility. +
|
429
|
+
|
430
|
+
[source, js]
|
431
|
+
----
|
432
|
+
/**
|
433
|
+
* @param isShow
|
434
|
+
* @return {boolean}
|
435
|
+
*/
|
436
|
+
visible
|
437
|
+
----
|
438
|
+
|
439
|
+
| `showRows` \| `visibleRows`
|
440
|
+
|Calculate first item height and set child height. +
|
441
|
+
|
442
|
+
[source, js]
|
443
|
+
----
|
444
|
+
/**
|
445
|
+
* @param numberOfRows {int}
|
446
|
+
*/
|
447
|
+
showRows(numberOfRows)
|
448
|
+
----
|
449
|
+
|
450
|
+
|`on`
|
451
|
+
|Add an event on the dropdown. Below are possible event types you can
|
452
|
+
pass in the argument:
|
453
|
+
|
454
|
+
`create` \| `open` \| `close` \| `add` \| `remove` \| `change` \|
|
455
|
+
`blur` \| `click` \| `dblclick` \| `mousemove` \| `mouseover` \|
|
456
|
+
`mouseout` \| `focus` \| `mousedown` \| `mouseup` +
|
457
|
+
|
458
|
+
[source, js]
|
459
|
+
----
|
460
|
+
/**
|
461
|
+
* @param type {string}
|
462
|
+
* @param fn {function}
|
463
|
+
*/
|
464
|
+
on(type, fn)
|
465
|
+
----
|
466
|
+
|
467
|
+
.Example
|
468
|
+
[source, js]
|
469
|
+
----
|
470
|
+
ddSelect.on("change", function() {console.log(ddSelect.uiData});
|
471
|
+
----
|
472
|
+
|
473
|
+
|`off`
|
474
|
+
|Remove event listener. +
|
475
|
+
|
476
|
+
[source, js]
|
477
|
+
----
|
478
|
+
/**
|
479
|
+
* @param type {string}
|
480
|
+
* @param fn {function}
|
481
|
+
*/
|
482
|
+
off(type, fn);
|
483
|
+
----
|
484
|
+
|
485
|
+
|`updateUiAndValue`
|
486
|
+
|In case there UI is not updated. You can call this method. +
|
487
|
+
|
488
|
+
[source, js]
|
489
|
+
----
|
490
|
+
updateUiAndValue()
|
491
|
+
----
|
492
|
+
|
493
|
+
|`refresh`
|
494
|
+
|Recreatea a msDropdown. +
|
495
|
+
|
496
|
+
[source, js]
|
497
|
+
----
|
498
|
+
refresh()
|
499
|
+
----
|
500
|
+
|
501
|
+
|`destroy`
|
502
|
+
|Remove msDropdown and returns back to the original dropdown. +
|
503
|
+
|
504
|
+
[source, js]
|
505
|
+
----
|
506
|
+
destroy()
|
507
|
+
----
|
508
|
+
|
509
|
+
|===
|
510
|
+
|
511
|
+
|
512
|
+
== Examples
|
513
|
+
|
514
|
+
|
515
|
+
=== Simple dropdown
|
516
|
+
|
517
|
+
Email FAQ Games Music Phone Graph Secured Video CD
|
518
|
+
|
519
|
+
There are two ways that you can apply msDropdown on <select> element
|
520
|
+
|
521
|
+
. You can add `is="ms-dropdown"`attributes. Like we have in the
|
522
|
+
below example.
|
523
|
+
|
524
|
+
[source, html]
|
525
|
+
----
|
526
|
+
<select class="tech" name="tech" is="ms-dropdown">
|
527
|
+
<option value="" selected>Please select one</option>
|
528
|
+
<option data-image="./dist/images/icons/icon_email.gif" value="email">Email</option>
|
529
|
+
<option data-image="./dist/images/icons/icon_faq.gif" value="faq">FAQ</option>
|
530
|
+
<option data-image="./dist/images/icons/icon_games.gif" value="games">Games</option>
|
531
|
+
<option data-image="./dist/images/icons/icon_music.gif" value="music">Music</option>
|
532
|
+
<option data-image="./dist/images/icons/icon_phone.gif" value="phone">Phone</option>
|
533
|
+
<option data-image="./dist/images/icons/icon_sales.gif" value="graph">Graph</option>
|
534
|
+
<option data-image="./dist/images/icons/icon_secure.gif" value="secured">Secured</option>
|
535
|
+
<option data-image="./dist/images/icons/icon_video.gif" value="video">Video</option>
|
536
|
+
<option data-image="./dist/images/icons/icon_cd.gif" name="cd" value="cd">CD</option>
|
537
|
+
</select>
|
538
|
+
----
|
539
|
+
|
540
|
+
[start=2]
|
541
|
+
. You don't need the below code if you have already included
|
542
|
+
`dd.min.js` in the bottom of the page. Like I've mentioned in the
|
543
|
+
installation section. +
|
544
|
+
|
545
|
+
In case you want to convert later by script, you can use the below code.
|
546
|
+
You may use a CSS selector too. +
|
547
|
+
|
548
|
+
[source, js]
|
549
|
+
----
|
550
|
+
MsDropdown.make('#select_element');
|
551
|
+
//or
|
552
|
+
new MsDropdown('.select_elements');
|
553
|
+
----
|
554
|
+
|
555
|
+
=== Dropdown with description
|
556
|
+
|
557
|
+
Did you notice? There is an extra attribute `data-description` in `<option>`.
|
558
|
+
|
559
|
+
[source, html]
|
560
|
+
----
|
561
|
+
<select id="payments" name="payments" is="ms-dropdown" data-enable-auto-filter="false" required>
|
562
|
+
<option value="" data-description="Choose your payment gateway">Payment Gateway</option>
|
563
|
+
<option value="amex" data-image="./dist/images/icons/Amex-56.png" data-description="My life. My card...">Amex</option>
|
564
|
+
<option value="Discover" data-image="./dist/images/icons/Discover-56.png" data-description="It pays to Discover...">Discover</option>
|
565
|
+
<option value="Mastercard" data-image="./dist/images/icons/Mastercard-56.png" data-title="For everything else..." data-description="For everything else...">Mastercard</option>
|
566
|
+
<option value="cash" data-image="./dist/images/icons/Cash-56.png" data-description="Pay at your doorstep...">Cash on delivery</option>
|
567
|
+
<option value="Visa" data-image="./dist/images/icons/Visa-56.png" data-description="All you need...">Visa</option>
|
568
|
+
<option value="Paypal" data-image="./dist/images/icons/Paypal-56.png" data-description="Pay and get paid...">Paypal</option>
|
569
|
+
</select>
|
570
|
+
----
|
571
|
+
|
572
|
+
=== Dropdown with checkboxes
|
573
|
+
|
574
|
+
Email FAQ Games Music Phone Graph Secured Video CD
|
575
|
+
|
576
|
+
[source, html]
|
577
|
+
----
|
578
|
+
<select name="tech_with_checkbox" is="ms-dropdown" data-enable-checkbox="true">
|
579
|
+
<option data-image="./dist/images/icons/icon_email.gif" value="email">Email</option>
|
580
|
+
<option data-image="./dist/images/icons/icon_faq.gif" value="faq">FAQ</option>
|
581
|
+
<option data-image="./dist/images/icons/icon_games.gif" selected value="games">Games</option>
|
582
|
+
<option data-image="./dist/images/icons/icon_music.gif" value="music">Music</option>
|
583
|
+
<option data-image="./dist/images/icons/icon_phone.gif" value="phone">Phone</option>
|
584
|
+
<option data-image="./dist/images/icons/icon_sales.gif" value="graph">Graph</option>
|
585
|
+
<option data-image="./dist/images/icons/icon_secure.gif" value="secured">Secured</option>
|
586
|
+
<option data-image="./dist/images/icons/icon_video.gif" value="video">Video</option>
|
587
|
+
<option data-image="./dist/images/icons/icon_cd.gif" name="cd" value="cd">CD</option>
|
588
|
+
</select>
|
589
|
+
----
|
590
|
+
|
591
|
+
=== Option groups
|
592
|
+
|
593
|
+
[source, html]
|
594
|
+
----
|
595
|
+
<select is="ms-dropdown" name="car_group">
|
596
|
+
<optgroup label="Mercedes Benz">
|
597
|
+
<option>Mercedes-Benz GLA</option>
|
598
|
+
<option>Mercedes-Benz S-Class</option>
|
599
|
+
<option>Mercedes-Benz E-Class</option>
|
600
|
+
<option>Mercedes-Benz GLS</option>
|
601
|
+
</optgroup>
|
602
|
+
<optgroup label="Jaguar">
|
603
|
+
<option>Jaguar F-TYPE</option>
|
604
|
+
<option selected>Jaguar XE</option>
|
605
|
+
<option>Jaguar F-Pace</option>
|
606
|
+
<option>Jaguar I-Pace</option>
|
607
|
+
<option>Jaguar XF</option>
|
608
|
+
</optgroup>
|
609
|
+
</select>
|
610
|
+
----
|
611
|
+
|
612
|
+
=== Dropdown with CSS images
|
613
|
+
|
614
|
+
[source, html]
|
615
|
+
----
|
616
|
+
<select name="countries" id="countries" is="ms-dropdown" data-child-height="315">
|
617
|
+
<option value='ad' data-image-css="flag ad" data-title="Andorra">Andorra</option>
|
618
|
+
<option value='ae' data-image-css="flag ae" data-title="United Arab Emirates">United Arab Emirates</option>
|
619
|
+
<option value='af' data-image-css="flag af" data-title="Afghanistan">Afghanistan</option>
|
620
|
+
...
|
621
|
+
<option value='zr' data-image-css="flag zr" data-title="Zaire (former)">Zaire (former)</option>
|
622
|
+
<option value='zw' data-image-css="flag zw" data-title="Zimbabwe">Zimbabwe</option>
|
623
|
+
</select>
|
624
|
+
----
|
625
|
+
|
626
|
+
=== Dropdown as a list
|
627
|
+
|
628
|
+
Please select one Email FAQ Games Music Phone Graph Secured Video CD
|
629
|
+
|
630
|
+
[source, html]
|
631
|
+
----
|
632
|
+
<select name="gameList[]" is="ms-dropdown" multiple size="5">
|
633
|
+
<option value="" selected>Please select one</option>
|
634
|
+
<option data-image="./dist/images/icons/icon_email.gif" value="email">Email</option>
|
635
|
+
<option data-image="./dist/images/icons/icon_faq.gif" value="faq">FAQ</option>
|
636
|
+
<option data-image="./dist/images/icons/icon_games.gif" value="games">Games</option>
|
637
|
+
<option data-image="./dist/images/icons/icon_music.gif" value="music">Music</option>
|
638
|
+
<option data-image="./dist/images/icons/icon_phone.gif" value="phone">Phone</option>
|
639
|
+
<option data-image="./dist/images/icons/icon_sales.gif" value="graph">Graph</option>
|
640
|
+
<option data-image="./dist/images/icons/icon_secure.gif" value="secured">Secured</option>
|
641
|
+
<option data-image="./dist/images/icons/icon_video.gif" value="video">Video</option>
|
642
|
+
<option data-image="./dist/images/icons/icon_cd.gif" name="cd" value="cd">CD</option>
|
643
|
+
</select>
|
644
|
+
----
|
645
|
+
|
646
|
+
=== Create Dropdown from JSON object
|
647
|
+
|
648
|
+
[source, js]
|
649
|
+
----
|
650
|
+
[
|
651
|
+
{description:'Choose your payment gateway', value:'', text:'Payment Gateway'},
|
652
|
+
{image:'/assets/mywork/web-components/image-dropdown/images/icons/Amex-56.png', description:'My life. My card...', value:'amex', text:'Amex'},
|
653
|
+
{image:'/assets/mywork/web-components/image-dropdown/images/icons/Discover-56.png', description:'It pays to Discover...', value:'Discover', text:'Discover'},
|
654
|
+
{image:'/assets/mywork/web-components/image-dropdown/images/icons/Mastercard-56.png', title:'For everything else...', description:'For everything else...', value:'Mastercard', text:'Mastercard'},
|
655
|
+
{image:'/assets/mywork/web-components/image-dropdown/images/icons/Cash-56.png', description:'Sorry not available...', value:'cash', text:'Cash on delivery', disabled:true},
|
656
|
+
{image:'/assets/mywork/web-components/image-dropdown/images/icons/Visa-56.png', description:'All you need...', value:'Visa', text:'Visa'},
|
657
|
+
{image:'/assets/mywork/web-components/image-dropdown/images/icons/Paypal-56.png', description:'Pay and get paid...', value:'Paypal', text:'Paypal'}
|
658
|
+
];
|
659
|
+
----
|
660
|
+
|
661
|
+
Below method is being called on "Click here to convert by above json"
|
662
|
+
button.
|
663
|
+
|
664
|
+
[source, html]
|
665
|
+
----
|
666
|
+
<script>
|
667
|
+
function makeDd() {
|
668
|
+
'use strict';
|
669
|
+
//get the data from above json string
|
670
|
+
let json = new function (`return ${document.getElementById('json_data').innerHTML}`)();
|
671
|
+
//clean the holder
|
672
|
+
document.getElementById("json_dropdown").innerHTML = "";
|
673
|
+
|
674
|
+
//convert to msDropdown
|
675
|
+
MsDropdown.make("#json_dropdown", {
|
676
|
+
byJson: {
|
677
|
+
data: json, selectedIndex: 0, name: "json_dropdown",
|
678
|
+
size: 0, multiple: false, width: 450
|
679
|
+
},
|
680
|
+
enableAutoFilter:false
|
681
|
+
});
|
682
|
+
//or we can use like this too.
|
683
|
+
/*new MsDropdown(document.getElementById("json_dropdown"), {
|
684
|
+
byJson: {
|
685
|
+
data: json, name: "json_dropdown"
|
686
|
+
}
|
687
|
+
});*/
|
688
|
+
}
|
689
|
+
</script>
|
690
|
+
----
|
691
|
+
|
692
|
+
=== What are the settings params
|
693
|
+
|
694
|
+
If you are creating with the help of JavaScript you might need this.
|
695
|
+
So, how do you create it? Syntax is below
|
696
|
+
|
697
|
+
[source, js]
|
698
|
+
----
|
699
|
+
//Style 1
|
700
|
+
MsDropdown.make("element", {...settings});
|
701
|
+
|
702
|
+
//Style 2
|
703
|
+
new MsDropdown(document.getElementById("element_id"), {...settings});
|
704
|
+
----
|
705
|
+
|
706
|
+
And what are the settings params you can pass to the msDropdown? It is
|
707
|
+
similar to the data-attributes, those I've mentioned above in this
|
708
|
+
document. Only difference is that you passed as a camelCase key without
|
709
|
+
the "data-". For example if you want to set child width, you passed in
|
710
|
+
attribute as `data-child-width="300px"` whereas you need to pass in
|
711
|
+
settings as `childWidth:'300px'`
|
712
|
+
|
713
|
+
So, here is an example what you can pass in settings.
|
714
|
+
|
715
|
+
[source, js]
|
716
|
+
----
|
717
|
+
MsDropdown.make("element", {
|
718
|
+
byJson: {
|
719
|
+
data: null, selectedIndex: 0, name: null,
|
720
|
+
size: 0, multiple: false, width: 250
|
721
|
+
},
|
722
|
+
mainCss: 'ms-dd',
|
723
|
+
rowHeight: null,
|
724
|
+
visibleRows: null,
|
725
|
+
showIcon: true,
|
726
|
+
zIndex: 9999,
|
727
|
+
event:'click',
|
728
|
+
style: '',
|
729
|
+
childWidth:null,
|
730
|
+
childHeight:null,
|
731
|
+
enableCheckbox:false,
|
732
|
+
checkboxNameSuffix:'_mscheck',
|
733
|
+
showPlusItemCounter:true,
|
734
|
+
enableAutoFilter:true,
|
735
|
+
showListCounter:false,
|
736
|
+
errorMessage:'Please select an item from this list',
|
737
|
+
on: { create: null,open: null,close: null,add: null,remove: null,
|
738
|
+
change: null,blur: null,click: null,dblclick: null,mousemove: null,
|
739
|
+
mouseover: null,mouseout: null,focus: null,mousedown: null,
|
740
|
+
mouseup: null
|
741
|
+
}
|
742
|
+
});
|
743
|
+
----
|