fomantic-ui 2.10.0-beta.8 → 2.10.0-beta.81
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/.eslintrc.js +6 -23
- package/.github/workflows/ci.yml +9 -9
- package/.github/workflows/depsreview.yml +1 -1
- package/.github/workflows/nightly.yml +7 -5
- package/.github/workflows/release.yml +2 -2
- package/.stylelintrc.js +1 -15
- package/CHANGELOG.md +5289 -2325
- package/README.md +8 -4
- package/changelog-setup.js +32 -10
- package/changelog-template.hbs +256 -251
- package/dist/components/accordion.css +1 -1
- package/dist/components/accordion.js +62 -73
- package/dist/components/accordion.min.css +1 -1
- package/dist/components/accordion.min.js +3 -3
- package/dist/components/ad.css +1 -1
- package/dist/components/ad.min.css +1 -1
- package/dist/components/api.js +101 -161
- package/dist/components/api.min.js +3 -3
- package/dist/components/breadcrumb.css +1 -1
- package/dist/components/breadcrumb.min.css +1 -1
- package/dist/components/button.css +5 -6
- package/dist/components/button.min.css +2 -2
- package/dist/components/calendar.css +3 -3
- package/dist/components/calendar.js +283 -332
- package/dist/components/calendar.min.css +2 -2
- package/dist/components/calendar.min.js +3 -3
- package/dist/components/card.css +1 -1
- package/dist/components/card.min.css +1 -1
- package/dist/components/checkbox.css +1 -1
- package/dist/components/checkbox.js +58 -79
- package/dist/components/checkbox.min.css +1 -1
- package/dist/components/checkbox.min.js +3 -3
- package/dist/components/comment.css +1 -1
- package/dist/components/comment.min.css +1 -1
- package/dist/components/container.css +1 -1
- package/dist/components/container.min.css +1 -1
- package/dist/components/dimmer.css +2 -2
- package/dist/components/dimmer.js +39 -52
- package/dist/components/dimmer.min.css +2 -2
- package/dist/components/dimmer.min.js +3 -3
- package/dist/components/divider.css +1 -1
- package/dist/components/divider.min.css +1 -1
- package/dist/components/dropdown.css +21 -35
- package/dist/components/dropdown.js +435 -531
- package/dist/components/dropdown.min.css +2 -2
- package/dist/components/dropdown.min.js +3 -3
- package/dist/components/embed.css +1 -1
- package/dist/components/embed.js +55 -68
- package/dist/components/embed.min.css +1 -1
- package/dist/components/embed.min.js +3 -3
- package/dist/components/emoji.css +3809 -7617
- package/dist/components/emoji.min.css +2 -2
- package/dist/components/feed.css +1 -1
- package/dist/components/feed.min.css +1 -1
- package/dist/components/flag.css +1 -1
- package/dist/components/flag.min.css +1 -1
- package/dist/components/flyout.css +1 -1
- package/dist/components/flyout.js +149 -168
- package/dist/components/flyout.min.css +1 -1
- package/dist/components/flyout.min.js +3 -3
- package/dist/components/form.css +3 -5
- package/dist/components/form.js +249 -269
- package/dist/components/form.min.css +2 -2
- package/dist/components/form.min.js +3 -3
- package/dist/components/grid.css +2 -2
- package/dist/components/grid.min.css +2 -2
- package/dist/components/header.css +6 -6
- package/dist/components/header.min.css +2 -2
- package/dist/components/icon.css +10 -37
- package/dist/components/icon.min.css +2 -2
- package/dist/components/image.css +1 -1
- package/dist/components/image.min.css +1 -1
- package/dist/components/input.css +284 -12
- package/dist/components/input.min.css +2 -2
- package/dist/components/item.css +1 -1
- package/dist/components/item.min.css +1 -1
- package/dist/components/label.css +6 -14
- package/dist/components/label.min.css +2 -2
- package/dist/components/list.css +3 -3
- package/dist/components/list.min.css +2 -2
- package/dist/components/loader.css +53 -53
- package/dist/components/loader.min.css +2 -2
- package/dist/components/menu.css +45 -60
- package/dist/components/menu.min.css +2 -2
- package/dist/components/message.css +2 -2
- package/dist/components/message.min.css +2 -2
- package/dist/components/modal.css +5 -5
- package/dist/components/modal.js +161 -170
- package/dist/components/modal.min.css +2 -2
- package/dist/components/modal.min.js +3 -3
- package/dist/components/nag.css +1 -1
- package/dist/components/nag.js +74 -88
- package/dist/components/nag.min.css +1 -1
- package/dist/components/nag.min.js +3 -3
- package/dist/components/placeholder.css +2 -2
- package/dist/components/placeholder.min.css +2 -2
- package/dist/components/popup.css +19 -73
- package/dist/components/popup.js +105 -138
- package/dist/components/popup.min.css +2 -2
- package/dist/components/popup.min.js +3 -3
- package/dist/components/progress.css +4 -13
- package/dist/components/progress.js +75 -97
- package/dist/components/progress.min.css +2 -2
- package/dist/components/progress.min.js +3 -3
- package/dist/components/rail.css +1 -1
- package/dist/components/rail.min.css +1 -1
- package/dist/components/rating.css +1 -1
- package/dist/components/rating.js +49 -61
- package/dist/components/rating.min.css +1 -1
- package/dist/components/rating.min.js +3 -3
- package/dist/components/reset.css +48 -208
- package/dist/components/reset.min.css +2 -2
- package/dist/components/reveal.css +2 -5
- package/dist/components/reveal.min.css +2 -2
- package/dist/components/search.css +2 -3
- package/dist/components/search.js +178 -198
- package/dist/components/search.min.css +2 -2
- package/dist/components/search.min.js +3 -3
- package/dist/components/segment.css +6 -6
- package/dist/components/segment.min.css +2 -2
- package/dist/components/shape.css +1 -1
- package/dist/components/shape.js +59 -69
- package/dist/components/shape.min.css +1 -1
- package/dist/components/shape.min.js +3 -3
- package/dist/components/sidebar.css +1 -1
- package/dist/components/sidebar.js +81 -101
- package/dist/components/sidebar.min.css +1 -1
- package/dist/components/sidebar.min.js +3 -3
- package/dist/components/site.css +1 -1
- package/dist/components/site.js +37 -58
- package/dist/components/site.min.css +1 -1
- package/dist/components/site.min.js +3 -3
- package/dist/components/slider.css +1 -1
- package/dist/components/slider.js +169 -183
- package/dist/components/slider.min.css +1 -1
- package/dist/components/slider.min.js +3 -3
- package/dist/components/state.js +45 -59
- package/dist/components/state.min.js +3 -3
- package/dist/components/statistic.css +1 -1
- package/dist/components/statistic.min.css +1 -1
- package/dist/components/step.css +4 -4
- package/dist/components/step.min.css +2 -2
- package/dist/components/sticky.css +1 -1
- package/dist/components/sticky.js +95 -117
- package/dist/components/sticky.min.css +1 -1
- package/dist/components/sticky.min.js +3 -3
- package/dist/components/tab.css +1 -1
- package/dist/components/tab.js +83 -115
- package/dist/components/tab.min.css +1 -1
- package/dist/components/tab.min.js +3 -3
- package/dist/components/table.css +8 -8
- package/dist/components/table.min.css +2 -2
- package/dist/components/text.css +1 -1
- package/dist/components/text.min.css +1 -1
- package/dist/components/toast.css +1 -1
- package/dist/components/toast.js +64 -74
- package/dist/components/toast.min.css +1 -1
- package/dist/components/toast.min.js +3 -3
- package/dist/components/transition.css +1 -1
- package/dist/components/transition.js +61 -85
- package/dist/components/transition.min.css +1 -1
- package/dist/components/transition.min.js +3 -3
- package/dist/components/visibility.js +120 -140
- package/dist/components/visibility.min.js +3 -3
- package/dist/semantic.css +4480 -8222
- package/dist/semantic.js +2886 -3485
- package/dist/semantic.min.css +3 -3
- package/dist/semantic.min.js +3 -3
- package/examples/attached.html +1 -1
- package/examples/components/menu.html +1 -1
- package/package.json +8 -5
- package/scripts/nightly-version.js +4 -4
- package/src/definitions/behaviors/api.js +100 -160
- package/src/definitions/behaviors/form.js +248 -268
- package/src/definitions/behaviors/state.js +44 -58
- package/src/definitions/behaviors/visibility.js +119 -139
- package/src/definitions/collections/breadcrumb.less +0 -1
- package/src/definitions/collections/form.less +3 -9
- package/src/definitions/collections/grid.less +1 -2
- package/src/definitions/collections/menu.less +106 -117
- package/src/definitions/collections/message.less +1 -2
- package/src/definitions/collections/table.less +7 -8
- package/src/definitions/elements/button.less +4 -6
- package/src/definitions/elements/container.less +0 -1
- package/src/definitions/elements/divider.less +1 -2
- package/src/definitions/elements/emoji.less +1 -1
- package/src/definitions/elements/flag.less +1 -1
- package/src/definitions/elements/header.less +4 -5
- package/src/definitions/elements/icon.less +10 -37
- package/src/definitions/elements/image.less +0 -1
- package/src/definitions/elements/input.less +4 -7
- package/src/definitions/elements/label.less +5 -14
- package/src/definitions/elements/list.less +2 -3
- package/src/definitions/elements/loader.less +10 -11
- package/src/definitions/elements/placeholder.less +1 -2
- package/src/definitions/elements/rail.less +0 -1
- package/src/definitions/elements/reveal.less +1 -5
- package/src/definitions/elements/segment.less +5 -6
- package/src/definitions/elements/step.less +3 -4
- package/src/definitions/elements/text.less +0 -1
- package/src/definitions/globals/reset.less +0 -1
- package/src/definitions/globals/site.js +36 -57
- package/src/definitions/globals/site.less +0 -1
- package/src/definitions/modules/accordion.js +61 -72
- package/src/definitions/modules/accordion.less +0 -1
- package/src/definitions/modules/calendar.js +282 -331
- package/src/definitions/modules/calendar.less +2 -3
- package/src/definitions/modules/checkbox.js +57 -78
- package/src/definitions/modules/checkbox.less +0 -1
- package/src/definitions/modules/dimmer.js +38 -51
- package/src/definitions/modules/dimmer.less +1 -2
- package/src/definitions/modules/dropdown.js +434 -530
- package/src/definitions/modules/dropdown.less +27 -38
- package/src/definitions/modules/embed.js +54 -67
- package/src/definitions/modules/embed.less +0 -1
- package/src/definitions/modules/flyout.js +148 -167
- package/src/definitions/modules/flyout.less +0 -1
- package/src/definitions/modules/modal.js +160 -169
- package/src/definitions/modules/modal.less +3 -4
- package/src/definitions/modules/nag.js +73 -87
- package/src/definitions/modules/nag.less +0 -1
- package/src/definitions/modules/popup.js +104 -137
- package/src/definitions/modules/popup.less +18 -73
- package/src/definitions/modules/progress.js +74 -96
- package/src/definitions/modules/progress.less +3 -13
- package/src/definitions/modules/rating.js +48 -60
- package/src/definitions/modules/rating.less +0 -1
- package/src/definitions/modules/search.js +177 -197
- package/src/definitions/modules/search.less +2 -4
- package/src/definitions/modules/shape.js +58 -68
- package/src/definitions/modules/shape.less +0 -1
- package/src/definitions/modules/sidebar.js +80 -100
- package/src/definitions/modules/sidebar.less +0 -1
- package/src/definitions/modules/slider.js +168 -182
- package/src/definitions/modules/slider.less +0 -1
- package/src/definitions/modules/sticky.js +94 -116
- package/src/definitions/modules/sticky.less +0 -1
- package/src/definitions/modules/tab.js +82 -114
- package/src/definitions/modules/tab.less +0 -1
- package/src/definitions/modules/toast.js +63 -73
- package/src/definitions/modules/toast.less +0 -1
- package/src/definitions/modules/transition.js +60 -84
- package/src/definitions/modules/transition.less +1 -2
- package/src/definitions/views/ad.less +0 -1
- package/src/definitions/views/card.less +0 -1
- package/src/definitions/views/comment.less +0 -1
- package/src/definitions/views/feed.less +0 -1
- package/src/definitions/views/item.less +0 -1
- package/src/definitions/views/statistic.less +0 -1
- package/src/semantic.less +1 -1
- package/src/themes/amazon/elements/button.overrides +1 -1
- package/src/themes/amazon/elements/button.variables +5 -6
- package/src/themes/amazon/globals/site.variables +2 -3
- package/src/themes/bookish/elements/header.variables +2 -2
- package/src/themes/bootstrap3/elements/button.variables +4 -5
- package/src/themes/chubby/collections/menu.variables +1 -1
- package/src/themes/chubby/elements/button.overrides +4 -4
- package/src/themes/chubby/modules/accordion.overrides +1 -1
- package/src/themes/chubby/views/comment.overrides +2 -2
- package/src/themes/chubby/views/comment.variables +2 -2
- package/src/themes/classic/collections/table.variables +2 -2
- package/src/themes/classic/elements/button.variables +11 -11
- package/src/themes/classic/modules/progress.variables +2 -2
- package/src/themes/classic/views/card.variables +2 -2
- package/src/themes/default/collections/form.variables +2 -3
- package/src/themes/default/collections/menu.variables +28 -28
- package/src/themes/default/collections/message.variables +1 -1
- package/src/themes/default/collections/table.variables +4 -4
- package/src/themes/default/elements/button.variables +9 -10
- package/src/themes/default/elements/divider.variables +1 -1
- package/src/themes/default/elements/icon.variables +2 -2
- package/src/themes/default/elements/image.variables +1 -1
- package/src/themes/default/elements/input.variables +2 -2
- package/src/themes/default/elements/label.variables +4 -4
- package/src/themes/default/elements/list.variables +1 -1
- package/src/themes/default/elements/placeholder.variables +6 -6
- package/src/themes/default/elements/segment.variables +8 -8
- package/src/themes/default/globals/reset.overrides +45 -201
- package/src/themes/default/globals/site.variables +50 -50
- package/src/themes/default/globals/variation.variables +3 -2
- package/src/themes/default/modules/accordion.variables +0 -1
- package/src/themes/default/modules/checkbox.variables +1 -1
- package/src/themes/default/modules/dimmer.variables +12 -12
- package/src/themes/default/modules/dropdown.variables +17 -16
- package/src/themes/default/modules/embed.variables +2 -2
- package/src/themes/default/modules/flyout.variables +3 -3
- package/src/themes/default/modules/modal.variables +14 -14
- package/src/themes/default/modules/nag.variables +1 -1
- package/src/themes/default/modules/rating.variables +1 -1
- package/src/themes/default/modules/search.variables +1 -1
- package/src/themes/default/modules/shape.variables +1 -1
- package/src/themes/default/modules/sidebar.variables +2 -2
- package/src/themes/default/modules/toast.variables +4 -4
- package/src/themes/default/views/card.variables +6 -7
- package/src/themes/default/views/feed.variables +4 -4
- package/src/themes/default/views/item.variables +2 -3
- package/src/themes/flat/collections/form.variables +1 -1
- package/src/themes/flat/globals/site.variables +9 -9
- package/src/themes/github/collections/form.overrides +3 -3
- package/src/themes/github/collections/form.variables +3 -3
- package/src/themes/github/collections/menu.overrides +1 -1
- package/src/themes/github/collections/menu.variables +10 -10
- package/src/themes/github/collections/message.variables +6 -6
- package/src/themes/github/elements/button.variables +17 -17
- package/src/themes/github/elements/input.variables +3 -3
- package/src/themes/github/elements/segment.variables +2 -2
- package/src/themes/github/elements/step.overrides +4 -4
- package/src/themes/github/elements/step.variables +3 -3
- package/src/themes/github/globals/site.variables +2 -2
- package/src/themes/github/modules/dropdown.variables +1 -3
- package/src/themes/gmail/collections/message.variables +2 -2
- package/src/themes/material/collections/menu.variables +1 -1
- package/src/themes/material/elements/button.overrides +4 -4
- package/src/themes/material/elements/button.variables +5 -5
- package/src/themes/material/modules/dropdown.variables +1 -1
- package/src/themes/material/modules/modal.variables +1 -1
- package/src/themes/raised/elements/button.variables +1 -1
- package/src/themes/round/elements/button.variables +12 -12
- package/src/themes/striped/modules/progress.overrides +3 -3
- package/src/themes/timeline/views/feed.variables +2 -2
- package/src/themes/twitter/elements/button.overrides +1 -1
- package/src/themes/twitter/elements/button.variables +4 -5
- package/tasks/admin/components/create.js +12 -15
- package/tasks/admin/components/init.js +11 -12
- package/tasks/admin/components/update.js +19 -20
- package/tasks/admin/distributions/create.js +30 -51
- package/tasks/admin/distributions/init.js +11 -12
- package/tasks/admin/distributions/update.js +18 -19
- package/tasks/admin/register.js +7 -7
- package/tasks/build/assets.js +1 -1
- package/tasks/build/css.js +5 -5
- package/tasks/build/javascript.js +1 -1
- package/tasks/config/admin/github.js +1 -1
- package/tasks/config/admin/templates/css-package.js +1 -1
- package/tasks/config/admin/templates/less-package.js +1 -1
- package/tasks/config/project/config.js +10 -10
- package/tasks/config/project/install.js +12 -12
- package/tasks/config/project/release.js +6 -12
- package/tasks/config/tasks.js +15 -11
- package/tasks/config/user.js +1 -4
- package/tasks/docs/metadata.js +18 -20
- package/tasks/install.js +14 -12
- package/test/meteor/assets.js +4 -4
- package/test/meteor/fonts.js +10 -11
- package/test/modules/module.spec.js +18 -18
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* # Fomantic-UI 2.10.0-beta.
|
|
2
|
+
* # Fomantic-UI 2.10.0-beta.81+4f706c2 - Dropdown
|
|
3
3
|
* https://github.com/fomantic/Fomantic-UI/
|
|
4
4
|
*
|
|
5
5
|
*
|
|
@@ -19,19 +19,19 @@
|
|
|
19
19
|
? window
|
|
20
20
|
: globalThis;
|
|
21
21
|
|
|
22
|
-
$.fn.dropdown = function (
|
|
22
|
+
$.fn.dropdown = function (...args) {
|
|
23
23
|
let $allModules = $(this);
|
|
24
|
-
|
|
24
|
+
const $document = $(document);
|
|
25
25
|
|
|
26
26
|
let time = Date.now();
|
|
27
27
|
let performance = [];
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const parameters = args[0];
|
|
30
|
+
const methodInvoked = typeof parameters === 'string';
|
|
31
|
+
const queryArguments = args.slice(1);
|
|
32
|
+
const contextCheck = function (context, win) {
|
|
33
33
|
let $context;
|
|
34
|
-
if ([window, document].
|
|
34
|
+
if ([window, document].includes(context)) {
|
|
35
35
|
$context = $(context);
|
|
36
36
|
} else {
|
|
37
37
|
$context = $(win.document).find(context);
|
|
@@ -45,26 +45,26 @@
|
|
|
45
45
|
let returnedValue;
|
|
46
46
|
|
|
47
47
|
$allModules.each(function (elementIndex) {
|
|
48
|
-
|
|
48
|
+
const settings = $.isPlainObject(parameters)
|
|
49
49
|
? $.extend(true, {}, $.fn.dropdown.settings, parameters)
|
|
50
50
|
: $.extend({}, $.fn.dropdown.settings);
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
const className = settings.className;
|
|
53
|
+
const message = settings.message;
|
|
54
|
+
const fields = settings.fields;
|
|
55
|
+
const keys = settings.keys;
|
|
56
|
+
const metadata = settings.metadata;
|
|
57
|
+
const namespace = settings.namespace;
|
|
58
|
+
const regExp = settings.regExp;
|
|
59
|
+
const selector = settings.selector;
|
|
60
|
+
const error = settings.error;
|
|
61
|
+
const templates = settings.templates;
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
const eventNamespace = '.' + namespace;
|
|
64
|
+
const moduleNamespace = 'module-' + namespace;
|
|
65
65
|
|
|
66
66
|
let $module = $(this);
|
|
67
|
-
|
|
67
|
+
const $context = contextCheck(settings.context, window);
|
|
68
68
|
let $text = $module.find(selector.text);
|
|
69
69
|
let $search = $module.find(selector.search);
|
|
70
70
|
let $sizer = $module.find(selector.sizer);
|
|
@@ -99,10 +99,9 @@
|
|
|
99
99
|
let selectObserver;
|
|
100
100
|
let menuObserver;
|
|
101
101
|
let classObserver;
|
|
102
|
-
let module;
|
|
103
102
|
let tempDisableApiCache = false;
|
|
104
103
|
|
|
105
|
-
module = {
|
|
104
|
+
const module = {
|
|
106
105
|
|
|
107
106
|
initialize: function () {
|
|
108
107
|
module.debug('Initializing dropdown', settings);
|
|
@@ -160,15 +159,13 @@
|
|
|
160
159
|
},
|
|
161
160
|
|
|
162
161
|
observeChanges: function () {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
module.observe.class();
|
|
171
|
-
}
|
|
162
|
+
selectObserver = new MutationObserver(module.event.select.mutation);
|
|
163
|
+
menuObserver = new MutationObserver(module.event.menu.mutation);
|
|
164
|
+
classObserver = new MutationObserver(module.event.class.mutation);
|
|
165
|
+
module.debug('Setting up mutation observer', selectObserver, menuObserver, classObserver);
|
|
166
|
+
module.observe.select();
|
|
167
|
+
module.observe.menu();
|
|
168
|
+
module.observe.class();
|
|
172
169
|
},
|
|
173
170
|
|
|
174
171
|
disconnect: {
|
|
@@ -221,11 +218,10 @@
|
|
|
221
218
|
elementNamespace = '.' + id;
|
|
222
219
|
module.verbose('Creating unique id for element', id);
|
|
223
220
|
},
|
|
224
|
-
userChoice: function (values) {
|
|
221
|
+
userChoice: function (values = module.get.userValues()) {
|
|
225
222
|
let $userChoices;
|
|
226
223
|
let $userChoice;
|
|
227
224
|
let html;
|
|
228
|
-
values = values || module.get.userValues();
|
|
229
225
|
if (!values) {
|
|
230
226
|
return false;
|
|
231
227
|
}
|
|
@@ -234,7 +230,7 @@
|
|
|
234
230
|
: [values];
|
|
235
231
|
$.each(values, function (index, value) {
|
|
236
232
|
if (module.get.item(value) === false) {
|
|
237
|
-
html = settings.templates.addition(module.add.variables(message.addResult, value));
|
|
233
|
+
html = settings.templates.addition(module.add.variables(message.addResult, settings.templates.escape(value, settings)));
|
|
238
234
|
$userChoice = $('<div />')
|
|
239
235
|
.html(html)
|
|
240
236
|
.attr('data-' + metadata.value, value)
|
|
@@ -254,7 +250,7 @@
|
|
|
254
250
|
return $userChoices;
|
|
255
251
|
},
|
|
256
252
|
userLabels: function (value) {
|
|
257
|
-
|
|
253
|
+
const userValues = module.get.userValues();
|
|
258
254
|
if (userValues) {
|
|
259
255
|
module.debug('Adding user labels', userValues);
|
|
260
256
|
$.each(userValues, function (index, value) {
|
|
@@ -275,10 +271,7 @@
|
|
|
275
271
|
},
|
|
276
272
|
},
|
|
277
273
|
|
|
278
|
-
search: function (query) {
|
|
279
|
-
query = query !== undefined
|
|
280
|
-
? query
|
|
281
|
-
: module.get.query();
|
|
274
|
+
search: function (query = module.get.query()) {
|
|
282
275
|
module.verbose('Searching for query', query);
|
|
283
276
|
if (settings.fireOnInit === false && module.is.initialLoad()) {
|
|
284
277
|
module.verbose('Skipping callback on initial load', settings.onSearch);
|
|
@@ -301,9 +294,9 @@
|
|
|
301
294
|
},
|
|
302
295
|
nextAvailable: function ($selected) {
|
|
303
296
|
$selected = $selected.eq(0);
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
297
|
+
const $nextAvailable = $selected.nextAll(selector.item).not(selector.unselectable).eq(0);
|
|
298
|
+
const $prevAvailable = $selected.prevAll(selector.item).not(selector.unselectable).eq(0);
|
|
299
|
+
const hasNext = $nextAvailable.length > 0;
|
|
307
300
|
if (hasNext) {
|
|
308
301
|
module.verbose('Moving selection to', $nextAvailable);
|
|
309
302
|
$nextAvailable.addClass(className.selected);
|
|
@@ -316,7 +309,7 @@
|
|
|
316
309
|
|
|
317
310
|
setup: {
|
|
318
311
|
api: function () {
|
|
319
|
-
|
|
312
|
+
const apiSettings = {
|
|
320
313
|
debug: settings.debug,
|
|
321
314
|
urlData: {
|
|
322
315
|
value: module.get.value(),
|
|
@@ -344,7 +337,7 @@
|
|
|
344
337
|
}
|
|
345
338
|
if (module.is.search() && !module.has.search()) {
|
|
346
339
|
module.verbose('Adding search input');
|
|
347
|
-
|
|
340
|
+
const labelNode = $module.prev('label');
|
|
348
341
|
$search = $('<input />')
|
|
349
342
|
.addClass(className.search)
|
|
350
343
|
.prop('autocomplete', module.is.chrome() ? 'fomantic-search' : 'off');
|
|
@@ -364,7 +357,7 @@
|
|
|
364
357
|
}
|
|
365
358
|
},
|
|
366
359
|
select: function () {
|
|
367
|
-
|
|
360
|
+
const selectValues = module.get.selectValues();
|
|
368
361
|
module.debug('Dropdown initialized on a select', selectValues);
|
|
369
362
|
if ($module.is('select')) {
|
|
370
363
|
$input = $module;
|
|
@@ -426,8 +419,8 @@
|
|
|
426
419
|
module.setup.returnedObject();
|
|
427
420
|
},
|
|
428
421
|
returnedObject: function () {
|
|
429
|
-
|
|
430
|
-
|
|
422
|
+
const $firstModules = $allModules.slice(0, elementIndex);
|
|
423
|
+
const $lastModules = $allModules.slice(elementIndex + 1);
|
|
431
424
|
// adjust all modules to use the correct reference
|
|
432
425
|
$allModules = $firstModules.add($module).add($lastModules);
|
|
433
426
|
},
|
|
@@ -539,11 +532,11 @@
|
|
|
539
532
|
});
|
|
540
533
|
// Hide submenus explicitly. On some browsers (esp. mobile), they will not automatically receive a
|
|
541
534
|
// mouseleave event
|
|
542
|
-
|
|
535
|
+
const $subMenu = $module.find(selector.menu);
|
|
543
536
|
if ($subMenu.length > 0) {
|
|
544
537
|
module.verbose('Hiding sub-menu', $subMenu);
|
|
545
538
|
$subMenu.each(function () {
|
|
546
|
-
|
|
539
|
+
const $sub = $(this);
|
|
547
540
|
if (!module.is.animating($sub)) {
|
|
548
541
|
module.animate.hide(false, $sub);
|
|
549
542
|
}
|
|
@@ -573,7 +566,7 @@
|
|
|
573
566
|
},
|
|
574
567
|
|
|
575
568
|
hideSubMenus: function () {
|
|
576
|
-
|
|
569
|
+
const $subMenus = $menu.children(selector.item).find(selector.menu);
|
|
577
570
|
module.verbose('Hiding sub menus', $subMenus);
|
|
578
571
|
$subMenus.transition('hide');
|
|
579
572
|
},
|
|
@@ -680,10 +673,10 @@
|
|
|
680
673
|
},
|
|
681
674
|
|
|
682
675
|
filter: function (query) {
|
|
683
|
-
|
|
676
|
+
const searchTerm = query !== undefined
|
|
684
677
|
? query
|
|
685
678
|
: module.get.query();
|
|
686
|
-
|
|
679
|
+
const afterFiltered = function () {
|
|
687
680
|
if (module.is.multiple()) {
|
|
688
681
|
module.filterActive();
|
|
689
682
|
}
|
|
@@ -712,7 +705,9 @@
|
|
|
712
705
|
module.remove.message();
|
|
713
706
|
}
|
|
714
707
|
if (settings.allowAdditions) {
|
|
715
|
-
module.add.userSuggestion(
|
|
708
|
+
module.add.userSuggestion(settings.preserveHTML
|
|
709
|
+
? settings.templates.escape(query)
|
|
710
|
+
: query);
|
|
716
711
|
}
|
|
717
712
|
if (module.is.searchSelection() && module.can.show() && module.is.focusedOnSearch() && !module.is.empty()) {
|
|
718
713
|
module.show();
|
|
@@ -763,12 +758,12 @@
|
|
|
763
758
|
query: query,
|
|
764
759
|
},
|
|
765
760
|
};
|
|
766
|
-
|
|
761
|
+
const apiCallbacks = {
|
|
767
762
|
onError: function (errorMessage, $module, xhr) {
|
|
768
763
|
module.add.message(message.serverError);
|
|
769
764
|
iconClicked = false;
|
|
770
765
|
focused = false;
|
|
771
|
-
callback
|
|
766
|
+
callback(...callbackParameters);
|
|
772
767
|
if (typeof settings.apiSettings.onError === 'function') {
|
|
773
768
|
settings.apiSettings.onError.call(this, errorMessage, $module, xhr);
|
|
774
769
|
}
|
|
@@ -777,7 +772,7 @@
|
|
|
777
772
|
module.add.message(message.serverError);
|
|
778
773
|
iconClicked = false;
|
|
779
774
|
focused = false;
|
|
780
|
-
callback
|
|
775
|
+
callback(...callbackParameters);
|
|
781
776
|
if (typeof settings.apiSettings.onFailure === 'function') {
|
|
782
777
|
settings.apiSettings.onFailure.call(this, response, $module, xhr);
|
|
783
778
|
}
|
|
@@ -788,14 +783,14 @@
|
|
|
788
783
|
values = [];
|
|
789
784
|
}
|
|
790
785
|
module.remove.message();
|
|
791
|
-
|
|
786
|
+
const menuConfig = {};
|
|
792
787
|
menuConfig[fields.values] = values;
|
|
793
788
|
module.setup.menu(menuConfig);
|
|
794
789
|
|
|
795
790
|
if (values.length === 0 && !settings.allowAdditions) {
|
|
796
791
|
module.add.message(message.noResults);
|
|
797
792
|
} else {
|
|
798
|
-
|
|
793
|
+
const value = module.is.multiple() ? module.get.values() : module.get.value();
|
|
799
794
|
if (value !== '') {
|
|
800
795
|
module.verbose('Value(s) present after click icon, select value(s) in items');
|
|
801
796
|
module.set.selected(value, null, true, true);
|
|
@@ -803,7 +798,7 @@
|
|
|
803
798
|
}
|
|
804
799
|
iconClicked = false;
|
|
805
800
|
focused = false;
|
|
806
|
-
callback
|
|
801
|
+
callback(...callbackParameters);
|
|
807
802
|
if (typeof settings.apiSettings.onSuccess === 'function') {
|
|
808
803
|
settings.apiSettings.onSuccess.call(this, response, $module, xhr);
|
|
809
804
|
}
|
|
@@ -820,16 +815,16 @@
|
|
|
820
815
|
},
|
|
821
816
|
|
|
822
817
|
filterItems: function (query) {
|
|
823
|
-
|
|
818
|
+
const searchTerm = module.remove.diacritics(
|
|
824
819
|
query !== undefined
|
|
825
820
|
? query
|
|
826
821
|
: module.get.query()
|
|
827
822
|
);
|
|
828
823
|
let results = null;
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
824
|
+
const escapedTerm = module.escape.string(searchTerm);
|
|
825
|
+
const regExpIgnore = settings.ignoreSearchCase ? 'i' : '';
|
|
826
|
+
const regExpFlags = regExpIgnore + 'gm';
|
|
827
|
+
const beginsWithRegExp = new RegExp('^' + escapedTerm, regExpFlags);
|
|
833
828
|
module.remove.filteredItem();
|
|
834
829
|
// avoid loop if we're matching nothing
|
|
835
830
|
if (module.has.query()) {
|
|
@@ -838,7 +833,7 @@
|
|
|
838
833
|
module.verbose('Searching for matching values', searchTerm);
|
|
839
834
|
$item
|
|
840
835
|
.each(function () {
|
|
841
|
-
|
|
836
|
+
const $choice = $(this);
|
|
842
837
|
let text;
|
|
843
838
|
let value;
|
|
844
839
|
if ($choice.hasClass(className.unfilterable)) {
|
|
@@ -876,19 +871,19 @@
|
|
|
876
871
|
.not(results)
|
|
877
872
|
.addClass(className.filtered);
|
|
878
873
|
if (settings.highlightMatches && (settings.match === 'both' || settings.match === 'text')) {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
874
|
+
const querySplit = [...query];
|
|
875
|
+
const diacriticReg = settings.ignoreDiacritics ? '[\u0300-\u036F]?' : '';
|
|
876
|
+
const htmlReg = '(?![^<]*>)';
|
|
877
|
+
const markedRegExp = new RegExp(htmlReg + '(' + querySplit.join(diacriticReg + ')(.*?)' + htmlReg + '(') + diacriticReg + ')', regExpIgnore);
|
|
878
|
+
const markedReplacer = function (...args) {
|
|
879
|
+
args = args.slice(1, querySplit.length * 2).map(function (x, i) {
|
|
885
880
|
return i & 1 ? x : '<mark>' + x + '</mark>'; // eslint-disable-line no-bitwise
|
|
886
881
|
});
|
|
887
882
|
|
|
888
883
|
return args.join('');
|
|
889
884
|
};
|
|
890
885
|
$.each(results, function (index, result) {
|
|
891
|
-
|
|
886
|
+
const $result = $(result);
|
|
892
887
|
let markedHTML = module.get.choiceText($result, true);
|
|
893
888
|
if (settings.ignoreDiacritics) {
|
|
894
889
|
markedHTML = markedHTML.normalize('NFD');
|
|
@@ -910,7 +905,7 @@
|
|
|
910
905
|
.filter(function () {
|
|
911
906
|
// First find the last divider in this divider group
|
|
912
907
|
// Dividers which are direct siblings are considered a group
|
|
913
|
-
|
|
908
|
+
const $lastDivider = $(this).nextUntil(selector.item);
|
|
914
909
|
|
|
915
910
|
return ($lastDivider.length > 0 ? $lastDivider : $(this))
|
|
916
911
|
// Count all non-filtered items until the next divider (or end of the dropdown)
|
|
@@ -924,8 +919,8 @@
|
|
|
924
919
|
},
|
|
925
920
|
|
|
926
921
|
fuzzySearch: function (query, term) {
|
|
927
|
-
|
|
928
|
-
|
|
922
|
+
const termLength = term.length;
|
|
923
|
+
const queryLength = query.length;
|
|
929
924
|
if (settings.ignoreSearchCase) {
|
|
930
925
|
query = query.toLowerCase();
|
|
931
926
|
term = term.toLowerCase();
|
|
@@ -938,9 +933,9 @@
|
|
|
938
933
|
}
|
|
939
934
|
for (let characterIndex = 0, nextCharacterIndex = 0; characterIndex < queryLength; characterIndex++) {
|
|
940
935
|
let continueSearch = false;
|
|
941
|
-
|
|
936
|
+
const queryCharacter = query.codePointAt(characterIndex);
|
|
942
937
|
while (nextCharacterIndex < termLength) {
|
|
943
|
-
if (term.
|
|
938
|
+
if (term.codePointAt(nextCharacterIndex++) === queryCharacter) {
|
|
944
939
|
continueSearch = true;
|
|
945
940
|
|
|
946
941
|
break;
|
|
@@ -958,7 +953,7 @@
|
|
|
958
953
|
query = settings.ignoreSearchCase ? query.toLowerCase() : query;
|
|
959
954
|
term = settings.ignoreSearchCase ? term.toLowerCase() : term;
|
|
960
955
|
|
|
961
|
-
return term.
|
|
956
|
+
return term.includes(query);
|
|
962
957
|
},
|
|
963
958
|
filterActive: function () {
|
|
964
959
|
if (settings.useLabels) {
|
|
@@ -986,12 +981,12 @@
|
|
|
986
981
|
},
|
|
987
982
|
|
|
988
983
|
forceSelection: function () {
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
984
|
+
const $currentlySelected = $item.not(className.filtered).filter('.' + className.selected).eq(0);
|
|
985
|
+
const $activeItem = $item.not(className.filtered).filter('.' + className.active).eq(0);
|
|
986
|
+
const $selectedItem = $currentlySelected.length > 0
|
|
992
987
|
? $currentlySelected
|
|
993
988
|
: $activeItem;
|
|
994
|
-
|
|
989
|
+
const hasSelected = $selectedItem.length > 0;
|
|
995
990
|
if (settings.allowAdditions || (hasSelected && !module.is.multiple())) {
|
|
996
991
|
module.debug('Forcing partial selection to selected item', $selectedItem);
|
|
997
992
|
module.event.item.click.call($selectedItem, {}, true);
|
|
@@ -1006,30 +1001,38 @@
|
|
|
1006
1001
|
module.clear();
|
|
1007
1002
|
}
|
|
1008
1003
|
module.debug('Creating dropdown with specified values', values);
|
|
1009
|
-
|
|
1004
|
+
const menuConfig = {};
|
|
1010
1005
|
menuConfig[fields.values] = values;
|
|
1011
1006
|
module.setup.menu(menuConfig);
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
if (
|
|
1017
|
-
|
|
1007
|
+
const findSelected = function (values) {
|
|
1008
|
+
let hasMultiple = true;
|
|
1009
|
+
$.each(values, function (index, item) {
|
|
1010
|
+
const itemType = item.type || 'item';
|
|
1011
|
+
if (item.selected === true) {
|
|
1012
|
+
module.debug('Setting initial selection to', item[fields.value]);
|
|
1013
|
+
module.set.selected(item[fields.value]);
|
|
1014
|
+
if (!module.is.multiple()) {
|
|
1015
|
+
hasMultiple = false;
|
|
1016
|
+
}
|
|
1017
|
+
} else if (itemType.includes('menu')) {
|
|
1018
|
+
hasMultiple = findSelected(item.values || []);
|
|
1018
1019
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1020
|
+
|
|
1021
|
+
return hasMultiple;
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
return hasMultiple;
|
|
1025
|
+
};
|
|
1026
|
+
findSelected(values);
|
|
1021
1027
|
|
|
1022
1028
|
if (module.has.selectInput()) {
|
|
1023
1029
|
module.disconnect.selectObserver();
|
|
1024
1030
|
$input.html('');
|
|
1025
1031
|
$input.append('<option disabled selected value></option>');
|
|
1026
1032
|
$.each(values, function (index, item) {
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
settings
|
|
1031
|
-
);
|
|
1032
|
-
$input.append('<option value="' + value + '"' + (item.selected === true ? ' selected' : '') + '>' + name + '</option>');
|
|
1033
|
+
const value = item[fields.value];
|
|
1034
|
+
const name = item[fields.name] || '';
|
|
1035
|
+
$input.append('<option value="' + settings.templates.escape(value) + '"' + (item.selected === true ? ' selected' : '') + '>' + settings.templates.escape(name, settings) + '</option>');
|
|
1033
1036
|
});
|
|
1034
1037
|
module.observe.select();
|
|
1035
1038
|
}
|
|
@@ -1038,22 +1041,26 @@
|
|
|
1038
1041
|
|
|
1039
1042
|
event: {
|
|
1040
1043
|
paste: function (event) {
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1044
|
+
const pasteValue = (event.originalEvent.clipboardData || window.clipboardData).getData('text');
|
|
1045
|
+
const tokens = pasteValue.split(settings.delimiter);
|
|
1046
|
+
const notFoundTokens = [];
|
|
1047
|
+
for (let value of tokens) {
|
|
1048
|
+
value = value.trim();
|
|
1049
|
+
const valueTrimmed = settings.preserveHTML
|
|
1050
|
+
? settings.templates.escape(value)
|
|
1051
|
+
: value;
|
|
1052
|
+
if (module.set.selected(valueTrimmed, null, false, true) === false) {
|
|
1053
|
+
notFoundTokens.push(valueTrimmed);
|
|
1047
1054
|
}
|
|
1048
|
-
}
|
|
1055
|
+
}
|
|
1049
1056
|
event.preventDefault();
|
|
1050
1057
|
if (notFoundTokens.length > 0) {
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1058
|
+
const searchEl = $search[0];
|
|
1059
|
+
const startPos = searchEl.selectionStart;
|
|
1060
|
+
const endPos = searchEl.selectionEnd;
|
|
1061
|
+
const orgText = searchEl.value;
|
|
1062
|
+
const pasteText = notFoundTokens.join(settings.delimiter);
|
|
1063
|
+
const newEndPos = startPos + pasteText.length;
|
|
1057
1064
|
$search.val(orgText.slice(0, startPos) + pasteText + orgText.slice(endPos));
|
|
1058
1065
|
searchEl.selectionStart = newEndPos;
|
|
1059
1066
|
searchEl.selectionEnd = newEndPos;
|
|
@@ -1097,7 +1104,7 @@
|
|
|
1097
1104
|
}
|
|
1098
1105
|
},
|
|
1099
1106
|
click: function (event) {
|
|
1100
|
-
|
|
1107
|
+
const $target = $(event.target);
|
|
1101
1108
|
// focus search
|
|
1102
1109
|
if ($target.is($module)) {
|
|
1103
1110
|
if (!module.is.focusedOnSearch()) {
|
|
@@ -1120,15 +1127,13 @@
|
|
|
1120
1127
|
},
|
|
1121
1128
|
blur: function (event) {
|
|
1122
1129
|
pageLostFocus = document.activeElement === this;
|
|
1123
|
-
if (module.is.searchSelection(true) && !willRefocus) {
|
|
1124
|
-
if (
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
module.remove.searchTerm();
|
|
1129
|
-
}
|
|
1130
|
-
module.hide();
|
|
1130
|
+
if (module.is.searchSelection(true) && !willRefocus && !itemActivated && !pageLostFocus) {
|
|
1131
|
+
if (settings.forceSelection) {
|
|
1132
|
+
module.forceSelection();
|
|
1133
|
+
} else if (!settings.allowAdditions && !settings.keepSearchTerm && !module.has.menuSearch()) {
|
|
1134
|
+
module.remove.searchTerm();
|
|
1131
1135
|
}
|
|
1136
|
+
module.hide();
|
|
1132
1137
|
}
|
|
1133
1138
|
willRefocus = false;
|
|
1134
1139
|
},
|
|
@@ -1181,12 +1186,12 @@
|
|
|
1181
1186
|
},
|
|
1182
1187
|
label: {
|
|
1183
1188
|
click: function (event) {
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1189
|
+
const $label = $(this);
|
|
1190
|
+
const $labels = $module.find(selector.label);
|
|
1191
|
+
const $activeLabels = $labels.filter('.' + className.active);
|
|
1192
|
+
const $nextActive = $label.nextAll('.' + className.active);
|
|
1193
|
+
const $prevActive = $label.prevAll('.' + className.active);
|
|
1194
|
+
const $range = $nextActive.length > 0
|
|
1190
1195
|
? $label.nextUntil($nextActive).add($activeLabels).add($label)
|
|
1191
1196
|
: $label.prevUntil($prevActive).add($activeLabels).add($label);
|
|
1192
1197
|
if (event.shiftKey) {
|
|
@@ -1198,13 +1203,13 @@
|
|
|
1198
1203
|
$activeLabels.removeClass(className.active);
|
|
1199
1204
|
$label.addClass(className.active);
|
|
1200
1205
|
}
|
|
1201
|
-
settings.onLabelSelect.
|
|
1206
|
+
settings.onLabelSelect.call(this, $labels.filter('.' + className.active));
|
|
1202
1207
|
event.stopPropagation();
|
|
1203
1208
|
},
|
|
1204
1209
|
},
|
|
1205
1210
|
remove: {
|
|
1206
1211
|
click: function (event) {
|
|
1207
|
-
|
|
1212
|
+
const $label = $(this).parent();
|
|
1208
1213
|
if ($label.hasClass(className.active)) {
|
|
1209
1214
|
// remove all selected labels
|
|
1210
1215
|
module.remove.activeLabels();
|
|
@@ -1217,7 +1222,7 @@
|
|
|
1217
1222
|
},
|
|
1218
1223
|
test: {
|
|
1219
1224
|
toggle: function (event) {
|
|
1220
|
-
|
|
1225
|
+
const toggleBehavior = module.is.multiple()
|
|
1221
1226
|
? module.show
|
|
1222
1227
|
: module.toggle;
|
|
1223
1228
|
if (module.is.bubbledLabelClick(event) || module.is.bubbledIconClick(event)) {
|
|
@@ -1233,20 +1238,18 @@
|
|
|
1233
1238
|
}
|
|
1234
1239
|
},
|
|
1235
1240
|
hide: function (event) {
|
|
1236
|
-
if (module.determine.eventInModule(event, module.hide)) {
|
|
1237
|
-
|
|
1238
|
-
event.preventDefault();
|
|
1239
|
-
}
|
|
1241
|
+
if (module.determine.eventInModule(event, module.hide) && element.id && $(event.target).attr('for') === element.id) {
|
|
1242
|
+
event.preventDefault();
|
|
1240
1243
|
}
|
|
1241
1244
|
},
|
|
1242
1245
|
},
|
|
1243
1246
|
class: {
|
|
1244
1247
|
mutation: function (mutations) {
|
|
1245
|
-
|
|
1248
|
+
for (const mutation of mutations) {
|
|
1246
1249
|
if (mutation.attributeName === 'class') {
|
|
1247
1250
|
module.check.disabled();
|
|
1248
1251
|
}
|
|
1249
|
-
}
|
|
1252
|
+
}
|
|
1250
1253
|
},
|
|
1251
1254
|
},
|
|
1252
1255
|
select: {
|
|
@@ -1263,16 +1266,10 @@
|
|
|
1263
1266
|
},
|
|
1264
1267
|
menu: {
|
|
1265
1268
|
mutation: function (mutations) {
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
let $removedNode = mutation.removedNodes
|
|
1271
|
-
? $(mutation.removedNodes[0])
|
|
1272
|
-
: $(false);
|
|
1273
|
-
let $changedNodes = $addedNode.add($removedNode);
|
|
1274
|
-
let isUserAddition = $changedNodes.is(selector.addition) || $changedNodes.closest(selector.addition).length > 0;
|
|
1275
|
-
let isMessage = $changedNodes.is(selector.message) || $changedNodes.closest(selector.message).length > 0;
|
|
1269
|
+
const mutation = mutations[0];
|
|
1270
|
+
const $changedNodes = $([...mutation.addedNodes, ...mutation.removedNodes]);
|
|
1271
|
+
const isUserAddition = $changedNodes.is(selector.addition) || $changedNodes.closest(selector.addition).length > 0;
|
|
1272
|
+
const isMessage = $changedNodes.is(selector.message) || $changedNodes.closest(selector.message).length > 0;
|
|
1276
1273
|
if (isUserAddition || isMessage) {
|
|
1277
1274
|
module.debug('Updating item selector cache');
|
|
1278
1275
|
module.refreshItems();
|
|
@@ -1290,12 +1287,12 @@
|
|
|
1290
1287
|
},
|
|
1291
1288
|
item: {
|
|
1292
1289
|
mouseenter: function (event) {
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1290
|
+
const $target = $(event.target);
|
|
1291
|
+
const $item = $(this);
|
|
1292
|
+
const $subMenu = $item.children(selector.menu);
|
|
1293
|
+
const $otherMenus = $item.siblings(selector.item).children(selector.menu);
|
|
1294
|
+
const hasSubMenu = $subMenu.length > 0;
|
|
1295
|
+
const isBubbledEvent = $subMenu.find($target).length > 0;
|
|
1299
1296
|
if (!isBubbledEvent && hasSubMenu) {
|
|
1300
1297
|
clearTimeout(module.itemTimer);
|
|
1301
1298
|
module.itemTimer = setTimeout(function () {
|
|
@@ -1309,7 +1306,7 @@
|
|
|
1309
1306
|
}
|
|
1310
1307
|
},
|
|
1311
1308
|
mouseleave: function (event) {
|
|
1312
|
-
|
|
1309
|
+
const $subMenu = $(this).find(selector.menu);
|
|
1313
1310
|
if ($subMenu.length > 0) {
|
|
1314
1311
|
clearTimeout(module.itemTimer);
|
|
1315
1312
|
module.itemTimer = setTimeout(function () {
|
|
@@ -1321,15 +1318,15 @@
|
|
|
1321
1318
|
}
|
|
1322
1319
|
},
|
|
1323
1320
|
click: function (event, skipRefocus) {
|
|
1324
|
-
|
|
1325
|
-
|
|
1321
|
+
const $choice = $(this);
|
|
1322
|
+
const $target = event
|
|
1326
1323
|
? $(event.target || '')
|
|
1327
1324
|
: $('');
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1325
|
+
const $subMenu = $choice.find(selector.menu);
|
|
1326
|
+
const text = module.get.choiceText($choice);
|
|
1327
|
+
const value = module.get.choiceValue($choice, text);
|
|
1328
|
+
const hasSubMenu = $subMenu.length > 0;
|
|
1329
|
+
const isBubbledEvent = $subMenu.find($target).length > 0;
|
|
1333
1330
|
if (document.activeElement.tagName.toLowerCase() !== 'input') {
|
|
1334
1331
|
$(document.activeElement).trigger('blur');
|
|
1335
1332
|
}
|
|
@@ -1363,23 +1360,23 @@
|
|
|
1363
1360
|
document: {
|
|
1364
1361
|
// label selection should occur even when the element has no focus
|
|
1365
1362
|
keydown: function (event) {
|
|
1366
|
-
|
|
1367
|
-
|
|
1363
|
+
const pressedKey = event.which;
|
|
1364
|
+
const isShortcutKey = module.is.inObject(pressedKey, keys);
|
|
1368
1365
|
if (isShortcutKey) {
|
|
1369
|
-
|
|
1366
|
+
const $label = $module.find(selector.label);
|
|
1370
1367
|
let $activeLabel = $label.filter('.' + className.active);
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1368
|
+
const activeValue = $activeLabel.data(metadata.value);
|
|
1369
|
+
const labelIndex = $label.index($activeLabel);
|
|
1370
|
+
const labelCount = $label.length;
|
|
1371
|
+
const hasActiveLabel = $activeLabel.length > 0;
|
|
1372
|
+
const hasMultipleActive = $activeLabel.length > 1;
|
|
1373
|
+
const isFirstLabel = labelIndex === 0;
|
|
1374
|
+
const isLastLabel = labelIndex + 1 === labelCount;
|
|
1375
|
+
const isSearch = module.is.searchSelection();
|
|
1376
|
+
const isFocusedOnSearch = module.is.focusedOnSearch();
|
|
1377
|
+
const isFocused = module.is.focused();
|
|
1378
|
+
const caretAtStart = isFocusedOnSearch && module.get.caretPosition(false) === 0;
|
|
1379
|
+
const isSelectedSearch = caretAtStart && module.get.caretPosition(true) !== 0;
|
|
1383
1380
|
if (isSearch && !hasActiveLabel && !isFocusedOnSearch) {
|
|
1384
1381
|
return;
|
|
1385
1382
|
}
|
|
@@ -1446,10 +1443,8 @@
|
|
|
1446
1443
|
case keys.backspace: {
|
|
1447
1444
|
if (hasActiveLabel) {
|
|
1448
1445
|
module.verbose('Removing active labels');
|
|
1449
|
-
if (isLastLabel) {
|
|
1450
|
-
|
|
1451
|
-
module.focusSearch();
|
|
1452
|
-
}
|
|
1446
|
+
if (isLastLabel && isSearch && !isFocusedOnSearch) {
|
|
1447
|
+
module.focusSearch();
|
|
1453
1448
|
}
|
|
1454
1449
|
$activeLabel.last().next(selector.siblingLabel).addClass(className.active);
|
|
1455
1450
|
module.remove.activeLabels($activeLabel);
|
|
@@ -1478,24 +1473,24 @@
|
|
|
1478
1473
|
|
|
1479
1474
|
keydown: function (event) {
|
|
1480
1475
|
let pressedKey = event.which;
|
|
1481
|
-
|
|
1476
|
+
const isShortcutKey = module.is.inObject(pressedKey, keys) || event.key === settings.delimiter;
|
|
1482
1477
|
if (isShortcutKey) {
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1478
|
+
const $currentlySelected = $item.not(selector.unselectable).filter('.' + className.selected).eq(0);
|
|
1479
|
+
const $activeItem = $menu.children('.' + className.active).eq(0);
|
|
1480
|
+
const $selectedItem = $currentlySelected.length > 0
|
|
1486
1481
|
? $currentlySelected
|
|
1487
1482
|
: $activeItem;
|
|
1488
|
-
|
|
1483
|
+
const $visibleItems = $selectedItem.length > 0
|
|
1489
1484
|
? $selectedItem.siblings(':not(.' + className.filtered + ')').addBack()
|
|
1490
1485
|
: $menu.children(':not(.' + className.filtered + ')');
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1486
|
+
const $subMenu = $selectedItem.children(selector.menu);
|
|
1487
|
+
const $parentMenu = $selectedItem.closest(selector.menu);
|
|
1488
|
+
const inVisibleMenu = $parentMenu.hasClass(className.visible) || $parentMenu.hasClass(className.animating) || $parentMenu.parent(selector.menu).length > 0;
|
|
1489
|
+
const hasSubMenu = $subMenu.length > 0;
|
|
1490
|
+
const hasSelectedItem = $selectedItem.length > 0;
|
|
1491
|
+
const selectedIsSelectable = $selectedItem.not(selector.unselectable).length > 0;
|
|
1492
|
+
const delimiterPressed = event.key === settings.delimiter && module.is.multiple();
|
|
1493
|
+
const isAdditionWithoutMenu = settings.allowAdditions && (pressedKey === keys.enter || delimiterPressed);
|
|
1499
1494
|
let $nextItem;
|
|
1500
1495
|
let isSubMenuItem;
|
|
1501
1496
|
// allow selection with the menu closed
|
|
@@ -1552,17 +1547,15 @@
|
|
|
1552
1547
|
}
|
|
1553
1548
|
|
|
1554
1549
|
// right arrow (show submenu)
|
|
1555
|
-
if (pressedKey === keys.rightArrow) {
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
event.preventDefault();
|
|
1565
|
-
}
|
|
1550
|
+
if (pressedKey === keys.rightArrow && hasSubMenu) {
|
|
1551
|
+
module.verbose('Right key pressed, opening sub-menu');
|
|
1552
|
+
module.animate.show(false, $subMenu);
|
|
1553
|
+
$selectedItem
|
|
1554
|
+
.removeClass(className.selected);
|
|
1555
|
+
$subMenu
|
|
1556
|
+
.find(selector.item).eq(0)
|
|
1557
|
+
.addClass(className.selected);
|
|
1558
|
+
event.preventDefault();
|
|
1566
1559
|
}
|
|
1567
1560
|
}
|
|
1568
1561
|
|
|
@@ -1645,22 +1638,19 @@
|
|
|
1645
1638
|
event.preventDefault();
|
|
1646
1639
|
}
|
|
1647
1640
|
}
|
|
1648
|
-
} else {
|
|
1649
|
-
|
|
1650
|
-
module.set.selectedLetter(String.fromCharCode(pressedKey));
|
|
1651
|
-
}
|
|
1641
|
+
} else if (!module.has.search()) {
|
|
1642
|
+
module.set.selectedLetter(String.fromCodePoint(pressedKey));
|
|
1652
1643
|
}
|
|
1653
1644
|
},
|
|
1654
1645
|
},
|
|
1655
1646
|
|
|
1656
1647
|
trigger: {
|
|
1657
1648
|
change: function () {
|
|
1658
|
-
|
|
1649
|
+
const inputElement = $input[0];
|
|
1659
1650
|
if (inputElement) {
|
|
1660
|
-
|
|
1651
|
+
const event = new Event('change', { bubbles: true });
|
|
1661
1652
|
module.verbose('Triggering native change event');
|
|
1662
|
-
|
|
1663
|
-
inputElement.dispatchEvent(events);
|
|
1653
|
+
inputElement.dispatchEvent(event);
|
|
1664
1654
|
}
|
|
1665
1655
|
},
|
|
1666
1656
|
},
|
|
@@ -1681,9 +1671,9 @@
|
|
|
1681
1671
|
selectActionActive = false;
|
|
1682
1672
|
},
|
|
1683
1673
|
eventInModule: function (event, callback) {
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1674
|
+
const $target = $(event.target);
|
|
1675
|
+
const inDocument = $target.closest(document.documentElement).length > 0;
|
|
1676
|
+
const inModule = $target.closest($module).length > 0;
|
|
1687
1677
|
callback = isFunction(callback)
|
|
1688
1678
|
? callback
|
|
1689
1679
|
: function () {};
|
|
@@ -1699,11 +1689,11 @@
|
|
|
1699
1689
|
return false;
|
|
1700
1690
|
},
|
|
1701
1691
|
eventOnElement: function (event, callback) {
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1692
|
+
const $target = $(event.target);
|
|
1693
|
+
const $label = $target.closest(selector.siblingLabel);
|
|
1694
|
+
const inVisibleDOM = document.body.contains(event.target);
|
|
1695
|
+
const notOnLabel = $module.find($label).length === 0 || !(module.is.multiple() && settings.useLabels);
|
|
1696
|
+
const notInMenu = $target.closest($menu).length === 0;
|
|
1707
1697
|
callback = isFunction(callback)
|
|
1708
1698
|
? callback
|
|
1709
1699
|
: function () {};
|
|
@@ -1724,10 +1714,7 @@
|
|
|
1724
1714
|
|
|
1725
1715
|
nothing: function () {},
|
|
1726
1716
|
|
|
1727
|
-
activate: function (text, value, element) {
|
|
1728
|
-
value = value !== undefined
|
|
1729
|
-
? value
|
|
1730
|
-
: text;
|
|
1717
|
+
activate: function (text, value = text, element = '') {
|
|
1731
1718
|
if (module.can.activate($(element))) {
|
|
1732
1719
|
module.set.selected(value, $(element), false, settings.keepSearchTerm);
|
|
1733
1720
|
if (!module.is.multiple() && !(!settings.collapseOnActionable && $(element).hasClass(className.actionable))) {
|
|
@@ -1736,10 +1723,7 @@
|
|
|
1736
1723
|
}
|
|
1737
1724
|
},
|
|
1738
1725
|
|
|
1739
|
-
select: function (text, value, element) {
|
|
1740
|
-
value = value !== undefined
|
|
1741
|
-
? value
|
|
1742
|
-
: text;
|
|
1726
|
+
select: function (text, value = text, element = '') {
|
|
1743
1727
|
if (module.can.activate($(element))) {
|
|
1744
1728
|
module.set.value(value, text, $(element));
|
|
1745
1729
|
if (!module.is.multiple() && !(!settings.collapseOnActionable && $(element).hasClass(className.actionable))) {
|
|
@@ -1748,10 +1732,7 @@
|
|
|
1748
1732
|
}
|
|
1749
1733
|
},
|
|
1750
1734
|
|
|
1751
|
-
combo: function (text, value, element) {
|
|
1752
|
-
value = value !== undefined
|
|
1753
|
-
? value
|
|
1754
|
-
: text;
|
|
1735
|
+
combo: function (text, value = text, element = '') {
|
|
1755
1736
|
module.set.selected(value, $(element));
|
|
1756
1737
|
module.hideAndClear();
|
|
1757
1738
|
},
|
|
@@ -1781,28 +1762,25 @@
|
|
|
1781
1762
|
return $module.data(metadata.placeholderText) || '';
|
|
1782
1763
|
},
|
|
1783
1764
|
text: function () {
|
|
1784
|
-
return settings.preserveHTML
|
|
1765
|
+
return settings.preserveHTML
|
|
1766
|
+
? $text.html()
|
|
1767
|
+
: $text.text();
|
|
1785
1768
|
},
|
|
1786
1769
|
query: function () {
|
|
1787
1770
|
return String($search.val()).trim();
|
|
1788
1771
|
},
|
|
1789
|
-
searchWidth: function (value) {
|
|
1790
|
-
value = value !== undefined
|
|
1791
|
-
? value
|
|
1792
|
-
: $search.val();
|
|
1772
|
+
searchWidth: function (value = $search.val()) {
|
|
1793
1773
|
$sizer.text(value);
|
|
1794
1774
|
|
|
1795
1775
|
// prevent rounding issues
|
|
1796
1776
|
return Math.ceil($sizer.width() + 1);
|
|
1797
1777
|
},
|
|
1798
1778
|
selectionCount: function () {
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1779
|
+
const values = module.get.values();
|
|
1780
|
+
|
|
1781
|
+
return module.is.multiple()
|
|
1802
1782
|
? (Array.isArray(values) ? values.length : 0)
|
|
1803
1783
|
: (module.get.value() !== '' ? 1 : 0);
|
|
1804
|
-
|
|
1805
|
-
return count;
|
|
1806
1784
|
},
|
|
1807
1785
|
transition: function ($subMenu) {
|
|
1808
1786
|
return settings.transition === 'auto'
|
|
@@ -1810,7 +1788,7 @@
|
|
|
1810
1788
|
: settings.transition;
|
|
1811
1789
|
},
|
|
1812
1790
|
userValues: function () {
|
|
1813
|
-
let values = module.get.values(
|
|
1791
|
+
let values = module.get.values();
|
|
1814
1792
|
if (!values) {
|
|
1815
1793
|
return false;
|
|
1816
1794
|
}
|
|
@@ -1823,12 +1801,10 @@
|
|
|
1823
1801
|
});
|
|
1824
1802
|
},
|
|
1825
1803
|
uniqueArray: function (array) {
|
|
1826
|
-
return
|
|
1827
|
-
return $.inArray(value, array) === index;
|
|
1828
|
-
});
|
|
1804
|
+
return [...new Set(array)];
|
|
1829
1805
|
},
|
|
1830
1806
|
caretPosition: function (returnEndPos) {
|
|
1831
|
-
|
|
1807
|
+
const input = $search[0];
|
|
1832
1808
|
let range;
|
|
1833
1809
|
let rangeLength;
|
|
1834
1810
|
if (returnEndPos && 'selectionEnd' in input) {
|
|
@@ -1850,27 +1826,25 @@
|
|
|
1850
1826
|
}
|
|
1851
1827
|
},
|
|
1852
1828
|
value: function () {
|
|
1853
|
-
|
|
1829
|
+
const value = $input.length > 0
|
|
1854
1830
|
? $input.val()
|
|
1855
1831
|
: $module.data(metadata.value);
|
|
1856
|
-
|
|
1832
|
+
const isEmptyMultiselect = Array.isArray(value) && value.length === 1 && value[0] === '';
|
|
1857
1833
|
|
|
1858
1834
|
// prevents the placeholder element from being selected when multiple
|
|
1859
1835
|
return value === undefined || isEmptyMultiselect
|
|
1860
1836
|
? ''
|
|
1861
1837
|
: value;
|
|
1862
1838
|
},
|
|
1863
|
-
values: function (
|
|
1864
|
-
|
|
1839
|
+
values: function () {
|
|
1840
|
+
const value = module.get.value();
|
|
1865
1841
|
if (value === '') {
|
|
1866
1842
|
return '';
|
|
1867
1843
|
}
|
|
1868
1844
|
|
|
1869
1845
|
return !module.has.selectInput() && module.is.multiple()
|
|
1870
1846
|
? (typeof value === 'string' // delimited string
|
|
1871
|
-
? (
|
|
1872
|
-
? value
|
|
1873
|
-
: module.escape.htmlEntities(value)).split(settings.delimiter)
|
|
1847
|
+
? value.split(settings.delimiter)
|
|
1874
1848
|
: '')
|
|
1875
1849
|
: value;
|
|
1876
1850
|
},
|
|
@@ -1882,7 +1856,7 @@
|
|
|
1882
1856
|
values = [values];
|
|
1883
1857
|
}
|
|
1884
1858
|
$.each(values, function (index, value) {
|
|
1885
|
-
|
|
1859
|
+
const name = module.read.remoteData(value);
|
|
1886
1860
|
module.verbose('Restoring value from session data', name, value);
|
|
1887
1861
|
if (name) {
|
|
1888
1862
|
if (!remoteValues) {
|
|
@@ -1895,10 +1869,7 @@
|
|
|
1895
1869
|
|
|
1896
1870
|
return remoteValues;
|
|
1897
1871
|
},
|
|
1898
|
-
choiceText: function ($choice, preserveHTML) {
|
|
1899
|
-
preserveHTML = preserveHTML !== undefined
|
|
1900
|
-
? preserveHTML
|
|
1901
|
-
: settings.preserveHTML;
|
|
1872
|
+
choiceText: function ($choice, preserveHTML = settings.preserveHTML) {
|
|
1902
1873
|
if ($choice) {
|
|
1903
1874
|
if ($choice.find(selector.menu).length > 0) {
|
|
1904
1875
|
module.verbose('Retrieving text of element with sub-menu');
|
|
@@ -1914,8 +1885,7 @@
|
|
|
1914
1885
|
: $choice.text() && $choice.text().trim());
|
|
1915
1886
|
}
|
|
1916
1887
|
},
|
|
1917
|
-
choiceValue: function ($choice, choiceText) {
|
|
1918
|
-
choiceText = choiceText || module.get.choiceText($choice);
|
|
1888
|
+
choiceValue: function ($choice, choiceText = module.get.choiceText($choice)) {
|
|
1919
1889
|
if (!$choice) {
|
|
1920
1890
|
return false;
|
|
1921
1891
|
}
|
|
@@ -1931,7 +1901,7 @@
|
|
|
1931
1901
|
: String(choiceText));
|
|
1932
1902
|
},
|
|
1933
1903
|
inputEvent: function () {
|
|
1934
|
-
|
|
1904
|
+
const input = $search[0];
|
|
1935
1905
|
if (input) {
|
|
1936
1906
|
return input.oninput !== undefined
|
|
1937
1907
|
? 'input'
|
|
@@ -1943,22 +1913,22 @@
|
|
|
1943
1913
|
return false;
|
|
1944
1914
|
},
|
|
1945
1915
|
selectValues: function () {
|
|
1946
|
-
|
|
1916
|
+
const select = {};
|
|
1947
1917
|
let oldGroup = [];
|
|
1948
|
-
|
|
1918
|
+
const values = [];
|
|
1949
1919
|
$module
|
|
1950
1920
|
.find('option')
|
|
1951
1921
|
.each(function () {
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1922
|
+
const $option = $(this);
|
|
1923
|
+
const name = module.escape.assumeUnescapedAmpLtGt($option.html());
|
|
1924
|
+
const disabled = $option.attr('disabled');
|
|
1925
|
+
const value = $option.attr('value') !== undefined
|
|
1956
1926
|
? $option.attr('value')
|
|
1957
1927
|
: name;
|
|
1958
|
-
|
|
1928
|
+
const text = $option.data(metadata.text) !== undefined
|
|
1959
1929
|
? $option.data(metadata.text)
|
|
1960
1930
|
: name;
|
|
1961
|
-
|
|
1931
|
+
const group = $option.parent('optgroup');
|
|
1962
1932
|
if (settings.placeholder === 'auto' && value === '') {
|
|
1963
1933
|
select.placeholder = name;
|
|
1964
1934
|
} else {
|
|
@@ -1973,7 +1943,7 @@
|
|
|
1973
1943
|
values.push({
|
|
1974
1944
|
name: name,
|
|
1975
1945
|
value: value,
|
|
1976
|
-
text:
|
|
1946
|
+
text: text,
|
|
1977
1947
|
disabled: disabled,
|
|
1978
1948
|
});
|
|
1979
1949
|
}
|
|
@@ -2007,7 +1977,7 @@
|
|
|
2007
1977
|
return $item.filter('.' + className.active);
|
|
2008
1978
|
},
|
|
2009
1979
|
selectedItem: function () {
|
|
2010
|
-
|
|
1980
|
+
const $selectedItem = $item.not(selector.unselectable).filter('.' + className.selected);
|
|
2011
1981
|
|
|
2012
1982
|
return $selectedItem.length > 0
|
|
2013
1983
|
? $selectedItem
|
|
@@ -2015,8 +1985,8 @@
|
|
|
2015
1985
|
},
|
|
2016
1986
|
itemWithAdditions: function (value) {
|
|
2017
1987
|
let $items = module.get.item(value);
|
|
2018
|
-
|
|
2019
|
-
|
|
1988
|
+
const $userItems = module.create.userChoice(value);
|
|
1989
|
+
const hasUserItems = $userItems && $userItems.length > 0;
|
|
2020
1990
|
if (hasUserItems) {
|
|
2021
1991
|
$items = $items.length > 0
|
|
2022
1992
|
? $items.add($userItems)
|
|
@@ -2027,15 +1997,13 @@
|
|
|
2027
1997
|
},
|
|
2028
1998
|
item: function (value, strict) {
|
|
2029
1999
|
let $selectedItem = false;
|
|
2030
|
-
let shouldSearch;
|
|
2031
|
-
let isMultiple;
|
|
2032
2000
|
value = value !== undefined
|
|
2033
2001
|
? value
|
|
2034
2002
|
: (module.get.values() !== undefined
|
|
2035
2003
|
? module.get.values()
|
|
2036
2004
|
: module.get.text());
|
|
2037
|
-
isMultiple = module.is.multiple() && Array.isArray(value);
|
|
2038
|
-
shouldSearch = isMultiple
|
|
2005
|
+
const isMultiple = module.is.multiple() && Array.isArray(value);
|
|
2006
|
+
const shouldSearch = isMultiple
|
|
2039
2007
|
? value.length > 0
|
|
2040
2008
|
: value !== undefined && value !== null;
|
|
2041
2009
|
strict = value === '' || value === false || value === true
|
|
@@ -2044,15 +2012,15 @@
|
|
|
2044
2012
|
if (shouldSearch) {
|
|
2045
2013
|
$item
|
|
2046
2014
|
.each(function () {
|
|
2047
|
-
|
|
2048
|
-
|
|
2015
|
+
const $choice = $(this);
|
|
2016
|
+
const optionText = module.get.choiceText($choice);
|
|
2049
2017
|
let optionValue = module.get.choiceValue($choice, optionText);
|
|
2050
2018
|
// safe early exit
|
|
2051
2019
|
if (optionValue === null || optionValue === undefined) {
|
|
2052
2020
|
return;
|
|
2053
2021
|
}
|
|
2054
2022
|
if (isMultiple) {
|
|
2055
|
-
if (
|
|
2023
|
+
if (value.map(String).includes(String(optionValue))) {
|
|
2056
2024
|
$selectedItem = $selectedItem
|
|
2057
2025
|
? $selectedItem.add($choice)
|
|
2058
2026
|
: $choice;
|
|
@@ -2069,7 +2037,7 @@
|
|
|
2069
2037
|
optionValue = optionValue.toLowerCase();
|
|
2070
2038
|
value = value.toLowerCase();
|
|
2071
2039
|
}
|
|
2072
|
-
if (
|
|
2040
|
+
if (String(optionValue) === String(value)) {
|
|
2073
2041
|
module.verbose('Found select item by value', optionValue, value);
|
|
2074
2042
|
$selectedItem = $choice;
|
|
2075
2043
|
|
|
@@ -2087,11 +2055,8 @@
|
|
|
2087
2055
|
},
|
|
2088
2056
|
|
|
2089
2057
|
check: {
|
|
2090
|
-
maxSelections: function (selectionCount) {
|
|
2058
|
+
maxSelections: function (selectionCount = module.get.selectionCount()) {
|
|
2091
2059
|
if (settings.maxSelections) {
|
|
2092
|
-
selectionCount = selectionCount !== undefined
|
|
2093
|
-
? selectionCount
|
|
2094
|
-
: module.get.selectionCount();
|
|
2095
2060
|
if (selectionCount >= settings.maxSelections) {
|
|
2096
2061
|
module.debug('Maximum selection count reached');
|
|
2097
2062
|
if (settings.useLabels) {
|
|
@@ -2126,8 +2091,8 @@
|
|
|
2126
2091
|
module.restore.defaultValue();
|
|
2127
2092
|
},
|
|
2128
2093
|
defaultText: function () {
|
|
2129
|
-
|
|
2130
|
-
|
|
2094
|
+
const defaultText = module.get.defaultText();
|
|
2095
|
+
const placeholderText = module.get.placeholderText;
|
|
2131
2096
|
if (defaultText === placeholderText) {
|
|
2132
2097
|
module.debug('Restoring default placeholder text', defaultText);
|
|
2133
2098
|
module.set.placeholderText(defaultText);
|
|
@@ -2140,7 +2105,7 @@
|
|
|
2140
2105
|
module.set.placeholderText();
|
|
2141
2106
|
},
|
|
2142
2107
|
defaultValue: function () {
|
|
2143
|
-
|
|
2108
|
+
const defaultValue = module.get.defaultValue();
|
|
2144
2109
|
if (defaultValue !== undefined) {
|
|
2145
2110
|
module.debug('Restoring default value', defaultValue);
|
|
2146
2111
|
if (defaultValue !== '') {
|
|
@@ -2180,7 +2145,7 @@
|
|
|
2180
2145
|
} else {
|
|
2181
2146
|
module.set.selected();
|
|
2182
2147
|
}
|
|
2183
|
-
|
|
2148
|
+
const value = module.get.value();
|
|
2184
2149
|
if (value && value !== '' && !(Array.isArray(value) && value.length === 0)) {
|
|
2185
2150
|
$input.removeClass(className.noselection);
|
|
2186
2151
|
} else {
|
|
@@ -2189,7 +2154,7 @@
|
|
|
2189
2154
|
module.remove.initialLoad();
|
|
2190
2155
|
},
|
|
2191
2156
|
remoteValues: function () {
|
|
2192
|
-
|
|
2157
|
+
const values = module.get.remoteValues();
|
|
2193
2158
|
module.debug('Recreating selected from session data', values);
|
|
2194
2159
|
if (values) {
|
|
2195
2160
|
if (module.is.single()) {
|
|
@@ -2207,13 +2172,7 @@
|
|
|
2207
2172
|
|
|
2208
2173
|
read: {
|
|
2209
2174
|
remoteData: function (value) {
|
|
2210
|
-
|
|
2211
|
-
if (window.Storage === undefined) {
|
|
2212
|
-
module.error(error.noStorage);
|
|
2213
|
-
|
|
2214
|
-
return;
|
|
2215
|
-
}
|
|
2216
|
-
name = sessionStorage.getItem(value + elementNamespace);
|
|
2175
|
+
const name = window.sessionStorage.getItem(value + elementNamespace);
|
|
2217
2176
|
|
|
2218
2177
|
return name !== undefined
|
|
2219
2178
|
? name
|
|
@@ -2228,12 +2187,12 @@
|
|
|
2228
2187
|
module.save.defaultValue();
|
|
2229
2188
|
},
|
|
2230
2189
|
defaultValue: function () {
|
|
2231
|
-
|
|
2190
|
+
const value = module.get.value();
|
|
2232
2191
|
module.verbose('Saving default value as', value);
|
|
2233
2192
|
$module.data(metadata.defaultValue, value);
|
|
2234
2193
|
},
|
|
2235
2194
|
defaultText: function () {
|
|
2236
|
-
|
|
2195
|
+
const text = module.get.text();
|
|
2237
2196
|
module.verbose('Saving default text as', text);
|
|
2238
2197
|
$module.data(metadata.defaultText, text);
|
|
2239
2198
|
},
|
|
@@ -2246,13 +2205,8 @@
|
|
|
2246
2205
|
}
|
|
2247
2206
|
},
|
|
2248
2207
|
remoteData: function (name, value) {
|
|
2249
|
-
if (window.Storage === undefined) {
|
|
2250
|
-
module.error(error.noStorage);
|
|
2251
|
-
|
|
2252
|
-
return;
|
|
2253
|
-
}
|
|
2254
2208
|
module.verbose('Saving remote data to session storage', value, name);
|
|
2255
|
-
sessionStorage.setItem(value + elementNamespace, name);
|
|
2209
|
+
window.sessionStorage.setItem(value + elementNamespace, name);
|
|
2256
2210
|
},
|
|
2257
2211
|
},
|
|
2258
2212
|
|
|
@@ -2278,26 +2232,23 @@
|
|
|
2278
2232
|
},
|
|
2279
2233
|
|
|
2280
2234
|
scrollPage: function (direction, $selectedItem) {
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2235
|
+
const $currentItem = $selectedItem || module.get.selectedItem();
|
|
2236
|
+
const $menu = $currentItem.closest(selector.menu);
|
|
2237
|
+
const menuHeight = $menu.outerHeight();
|
|
2238
|
+
const currentScroll = $menu.scrollTop();
|
|
2239
|
+
const itemHeight = $item.eq(0).outerHeight();
|
|
2240
|
+
const itemsPerPage = Math.floor(menuHeight / itemHeight);
|
|
2241
|
+
const newScroll = direction === 'up'
|
|
2288
2242
|
? currentScroll - (itemHeight * itemsPerPage)
|
|
2289
2243
|
: currentScroll + (itemHeight * itemsPerPage);
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
let $nextSelectedItem;
|
|
2293
|
-
let elementIndex;
|
|
2294
|
-
elementIndex = direction === 'up'
|
|
2244
|
+
const $selectableItem = $item.not(selector.unselectable);
|
|
2245
|
+
const elementIndex = direction === 'up'
|
|
2295
2246
|
? $selectableItem.index($currentItem) - itemsPerPage
|
|
2296
2247
|
: $selectableItem.index($currentItem) + itemsPerPage;
|
|
2297
|
-
isWithinRange = direction === 'up'
|
|
2248
|
+
const isWithinRange = direction === 'up'
|
|
2298
2249
|
? elementIndex >= 0
|
|
2299
2250
|
: elementIndex < $selectableItem.length;
|
|
2300
|
-
$nextSelectedItem = isWithinRange
|
|
2251
|
+
const $nextSelectedItem = isWithinRange
|
|
2301
2252
|
? $selectableItem.eq(elementIndex)
|
|
2302
2253
|
: (direction === 'up'
|
|
2303
2254
|
? $selectableItem.first()
|
|
@@ -2318,15 +2269,15 @@
|
|
|
2318
2269
|
|
|
2319
2270
|
set: {
|
|
2320
2271
|
filtered: function () {
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2272
|
+
const isMultiple = module.is.multiple();
|
|
2273
|
+
const isSearch = module.is.searchSelection();
|
|
2274
|
+
const isSearchMultiple = isMultiple && isSearch;
|
|
2275
|
+
const searchValue = isSearch
|
|
2325
2276
|
? module.get.query()
|
|
2326
2277
|
: '';
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2278
|
+
const hasSearchValue = typeof searchValue === 'string' && searchValue.length > 0;
|
|
2279
|
+
const searchWidth = module.get.searchWidth();
|
|
2280
|
+
const valueIsSet = searchValue !== '';
|
|
2330
2281
|
if (isMultiple && hasSearchValue) {
|
|
2331
2282
|
module.verbose('Adjusting input width', searchWidth);
|
|
2332
2283
|
$search.css('width', searchWidth + 'px');
|
|
@@ -2345,8 +2296,7 @@
|
|
|
2345
2296
|
loading: function () {
|
|
2346
2297
|
$module.addClass(className.loading);
|
|
2347
2298
|
},
|
|
2348
|
-
placeholderText: function (text) {
|
|
2349
|
-
text = text || module.get.placeholderText();
|
|
2299
|
+
placeholderText: function (text = module.get.placeholderText()) {
|
|
2350
2300
|
module.debug('Setting placeholder text', text);
|
|
2351
2301
|
module.set.text(text);
|
|
2352
2302
|
$text.addClass(className.placeholder);
|
|
@@ -2382,13 +2332,11 @@
|
|
|
2382
2332
|
}
|
|
2383
2333
|
},
|
|
2384
2334
|
partialSearch: function (text) {
|
|
2385
|
-
|
|
2335
|
+
const length = module.get.query().length;
|
|
2386
2336
|
$search.val(text.slice(0, length));
|
|
2387
2337
|
},
|
|
2388
|
-
scrollPosition: function ($item, forceScroll) {
|
|
2389
|
-
|
|
2390
|
-
let $menu;
|
|
2391
|
-
let hasActive;
|
|
2338
|
+
scrollPosition: function ($item, forceScroll = false) {
|
|
2339
|
+
const edgeTolerance = 5;
|
|
2392
2340
|
let offset;
|
|
2393
2341
|
let itemOffset;
|
|
2394
2342
|
let menuOffset;
|
|
@@ -2398,11 +2346,8 @@
|
|
|
2398
2346
|
let belowPage;
|
|
2399
2347
|
|
|
2400
2348
|
$item = $item || module.get.selectedItem();
|
|
2401
|
-
$menu = $item.closest(selector.menu);
|
|
2402
|
-
hasActive = $item && $item.length > 0;
|
|
2403
|
-
forceScroll = forceScroll !== undefined
|
|
2404
|
-
? forceScroll
|
|
2405
|
-
: false;
|
|
2349
|
+
const $menu = $item.closest(selector.menu);
|
|
2350
|
+
const hasActive = $item && $item.length > 0;
|
|
2406
2351
|
if (module.get.activeItem().length === 0) {
|
|
2407
2352
|
forceScroll = false;
|
|
2408
2353
|
}
|
|
@@ -2449,9 +2394,9 @@
|
|
|
2449
2394
|
}
|
|
2450
2395
|
},
|
|
2451
2396
|
selectedItem: function ($item) {
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2397
|
+
const value = module.get.choiceValue($item);
|
|
2398
|
+
const searchText = module.get.choiceText($item, false);
|
|
2399
|
+
const text = module.get.choiceText($item);
|
|
2455
2400
|
module.debug('Setting user selection to item', $item);
|
|
2456
2401
|
module.remove.activeItem();
|
|
2457
2402
|
module.set.partialSearch(searchText);
|
|
@@ -2460,8 +2405,8 @@
|
|
|
2460
2405
|
module.set.text(text);
|
|
2461
2406
|
},
|
|
2462
2407
|
selectedLetter: function (letter) {
|
|
2463
|
-
|
|
2464
|
-
|
|
2408
|
+
const $selectedItem = $item.filter('.' + className.selected);
|
|
2409
|
+
const alreadySelectedLetter = $selectedItem.length > 0 && module.has.firstLetter($selectedItem, letter);
|
|
2465
2410
|
let $nextValue = false;
|
|
2466
2411
|
let $nextItem;
|
|
2467
2412
|
// check next of the same letter
|
|
@@ -2516,11 +2461,11 @@
|
|
|
2516
2461
|
}
|
|
2517
2462
|
},
|
|
2518
2463
|
upward: function ($currentMenu) {
|
|
2519
|
-
|
|
2464
|
+
const $element = $currentMenu || $module;
|
|
2520
2465
|
$element.addClass(className.upward);
|
|
2521
2466
|
},
|
|
2522
2467
|
leftward: function ($currentMenu) {
|
|
2523
|
-
|
|
2468
|
+
const $element = $currentMenu || $menu;
|
|
2524
2469
|
$element.addClass(className.leftward);
|
|
2525
2470
|
},
|
|
2526
2471
|
value: function (value, text, $selected, preventChangeTrigger) {
|
|
@@ -2534,10 +2479,9 @@
|
|
|
2534
2479
|
} else {
|
|
2535
2480
|
$input.addClass(className.noselection);
|
|
2536
2481
|
}
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
let stringValue = value !== undefined
|
|
2482
|
+
const hasInput = $input.length > 0;
|
|
2483
|
+
const currentValue = module.get.values();
|
|
2484
|
+
const stringValue = value !== undefined
|
|
2541
2485
|
? String(value)
|
|
2542
2486
|
: value;
|
|
2543
2487
|
if (hasInput) {
|
|
@@ -2552,10 +2496,10 @@
|
|
|
2552
2496
|
module.debug('Adding user option', value);
|
|
2553
2497
|
module.add.optionValue(value);
|
|
2554
2498
|
}
|
|
2555
|
-
module.debug('Updating input value',
|
|
2499
|
+
module.debug('Updating input value', value, currentValue);
|
|
2556
2500
|
internalChange = true;
|
|
2557
2501
|
$input
|
|
2558
|
-
.val(
|
|
2502
|
+
.val(value);
|
|
2559
2503
|
if (settings.fireOnInit === false && module.is.initialLoad()) {
|
|
2560
2504
|
module.debug('Input native change event ignored on initial load');
|
|
2561
2505
|
} else if (preventChangeTrigger !== true) {
|
|
@@ -2563,8 +2507,8 @@
|
|
|
2563
2507
|
}
|
|
2564
2508
|
internalChange = false;
|
|
2565
2509
|
} else {
|
|
2566
|
-
module.verbose('Storing value in metadata',
|
|
2567
|
-
if (
|
|
2510
|
+
module.verbose('Storing value in metadata', value, $input);
|
|
2511
|
+
if (value !== currentValue) {
|
|
2568
2512
|
$module.data(metadata.value, stringValue);
|
|
2569
2513
|
}
|
|
2570
2514
|
}
|
|
@@ -2599,7 +2543,7 @@
|
|
|
2599
2543
|
preventChangeTrigger = $selectedItem;
|
|
2600
2544
|
$selectedItem = undefined;
|
|
2601
2545
|
}
|
|
2602
|
-
|
|
2546
|
+
const isMultiple = module.is.multiple();
|
|
2603
2547
|
$selectedItem = settings.allowAdditions
|
|
2604
2548
|
? $selectedItem || module.get.itemWithAdditions(value)
|
|
2605
2549
|
: $selectedItem || module.get.item(value);
|
|
@@ -2613,7 +2557,11 @@
|
|
|
2613
2557
|
if (settings.useLabels) {
|
|
2614
2558
|
module.remove.selectedItem();
|
|
2615
2559
|
if (value === undefined) {
|
|
2616
|
-
|
|
2560
|
+
const existingLabels = $module.find(selector.label);
|
|
2561
|
+
if (existingLabels.length > 0) {
|
|
2562
|
+
preventChangeTrigger = true;
|
|
2563
|
+
module.remove.labels(existingLabels, true);
|
|
2564
|
+
}
|
|
2617
2565
|
}
|
|
2618
2566
|
}
|
|
2619
2567
|
} else {
|
|
@@ -2627,15 +2575,15 @@
|
|
|
2627
2575
|
// select each item
|
|
2628
2576
|
$selectedItem
|
|
2629
2577
|
.each(function () {
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2578
|
+
const $selected = $(this);
|
|
2579
|
+
const selectedText = module.get.choiceText($selected);
|
|
2580
|
+
const selectedValue = module.get.choiceValue($selected, selectedText);
|
|
2581
|
+
|
|
2582
|
+
const isFiltered = $selected.hasClass(className.filtered);
|
|
2583
|
+
const isActive = $selected.hasClass(className.active);
|
|
2584
|
+
const isActionable = $selected.hasClass(className.actionable);
|
|
2585
|
+
const isUserValue = $selected.hasClass(className.addition);
|
|
2586
|
+
const shouldAnimate = isMultiple && $selectedItem && $selectedItem.length === 1;
|
|
2639
2587
|
if (isActionable) {
|
|
2640
2588
|
if ((!isMultiple || (!isActive || isUserValue)) && settings.apiSettings && settings.saveRemoteData) {
|
|
2641
2589
|
module.save.remoteData(selectedText, selectedValue);
|
|
@@ -2686,22 +2634,21 @@
|
|
|
2686
2634
|
|
|
2687
2635
|
add: {
|
|
2688
2636
|
label: function (value, text, shouldAnimate) {
|
|
2689
|
-
|
|
2637
|
+
const $next = module.is.searchSelection()
|
|
2690
2638
|
? $search
|
|
2691
2639
|
: $text;
|
|
2692
|
-
let escapedValue = module.escape.value(value);
|
|
2693
2640
|
let $label;
|
|
2694
2641
|
if (settings.ignoreCase) {
|
|
2695
|
-
|
|
2642
|
+
value = value.toLowerCase();
|
|
2696
2643
|
}
|
|
2697
2644
|
$label = $('<a />')
|
|
2698
2645
|
.addClass(className.label)
|
|
2699
|
-
.attr('data-' + metadata.value,
|
|
2700
|
-
.html(templates.label(
|
|
2701
|
-
$label = settings.onLabelCreate.call($label,
|
|
2646
|
+
.attr('data-' + metadata.value, value)
|
|
2647
|
+
.html(templates.label(value, text, settings));
|
|
2648
|
+
$label = settings.onLabelCreate.call($label, value, text);
|
|
2702
2649
|
|
|
2703
2650
|
if (module.has.label(value)) {
|
|
2704
|
-
module.debug('User selection already exists, skipping',
|
|
2651
|
+
module.debug('User selection already exists, skipping', value);
|
|
2705
2652
|
|
|
2706
2653
|
return;
|
|
2707
2654
|
}
|
|
@@ -2727,8 +2674,8 @@
|
|
|
2727
2674
|
}
|
|
2728
2675
|
},
|
|
2729
2676
|
message: function (message) {
|
|
2730
|
-
|
|
2731
|
-
|
|
2677
|
+
const $message = $menu.children(selector.message);
|
|
2678
|
+
const html = settings.templates.message(module.add.variables(message));
|
|
2732
2679
|
if ($message.length > 0) {
|
|
2733
2680
|
$message
|
|
2734
2681
|
.html(html);
|
|
@@ -2740,9 +2687,8 @@
|
|
|
2740
2687
|
}
|
|
2741
2688
|
},
|
|
2742
2689
|
optionValue: function (value) {
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
let hasOption = $option.length > 0;
|
|
2690
|
+
const $option = $input.find('option[value="' + CSS.escape(value) + '"]');
|
|
2691
|
+
const hasOption = $option.length > 0;
|
|
2746
2692
|
if (hasOption) {
|
|
2747
2693
|
return;
|
|
2748
2694
|
}
|
|
@@ -2753,7 +2699,7 @@
|
|
|
2753
2699
|
$input.find('option.' + className.addition).remove();
|
|
2754
2700
|
}
|
|
2755
2701
|
$('<option/>')
|
|
2756
|
-
.prop('value',
|
|
2702
|
+
.prop('value', value)
|
|
2757
2703
|
.addClass(className.addition)
|
|
2758
2704
|
.text(value)
|
|
2759
2705
|
.appendTo($input);
|
|
@@ -2762,9 +2708,9 @@
|
|
|
2762
2708
|
},
|
|
2763
2709
|
userSuggestion: function (value) {
|
|
2764
2710
|
let $addition = $menu.children(selector.addition);
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2711
|
+
const $existingItem = module.get.item(value);
|
|
2712
|
+
const alreadyHasValue = $existingItem && $existingItem.not(selector.addition).length > 0;
|
|
2713
|
+
const hasUserSuggestion = $addition.length > 0;
|
|
2768
2714
|
let html;
|
|
2769
2715
|
if (settings.useLabels && module.has.maxSelections()) {
|
|
2770
2716
|
return;
|
|
@@ -2782,7 +2728,7 @@
|
|
|
2782
2728
|
.attr('data-' + metadata.text, value)
|
|
2783
2729
|
.removeClass(className.filtered);
|
|
2784
2730
|
if (!settings.hideAdditions) {
|
|
2785
|
-
html = settings.templates.addition(module.add.variables(message.addResult, value));
|
|
2731
|
+
html = settings.templates.addition(module.add.variables(message.addResult, settings.templates.escape(value, settings)));
|
|
2786
2732
|
$addition
|
|
2787
2733
|
.html(html);
|
|
2788
2734
|
}
|
|
@@ -2801,11 +2747,10 @@
|
|
|
2801
2747
|
}
|
|
2802
2748
|
module.refreshItems();
|
|
2803
2749
|
},
|
|
2804
|
-
variables: function (message, term) {
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
let query;
|
|
2750
|
+
variables: function (message = '', term = settings.templates.escape(module.get.query())) {
|
|
2751
|
+
const hasCount = message.search('{count}') !== -1;
|
|
2752
|
+
const hasMaxCount = message.search('{maxCount}') !== -1;
|
|
2753
|
+
const hasTerm = message.search('{term}') !== -1;
|
|
2809
2754
|
module.verbose('Adding templated variables to message', message);
|
|
2810
2755
|
if (hasCount) {
|
|
2811
2756
|
message = message.replace('{count}', module.get.selectionCount());
|
|
@@ -2814,8 +2759,7 @@
|
|
|
2814
2759
|
message = message.replace('{maxCount}', settings.maxSelections);
|
|
2815
2760
|
}
|
|
2816
2761
|
if (hasTerm) {
|
|
2817
|
-
|
|
2818
|
-
message = message.replace('{term}', query);
|
|
2762
|
+
message = message.replace('{term}', term);
|
|
2819
2763
|
}
|
|
2820
2764
|
|
|
2821
2765
|
return message;
|
|
@@ -2826,7 +2770,7 @@
|
|
|
2826
2770
|
$selectedItem = undefined;
|
|
2827
2771
|
addedText = undefined;
|
|
2828
2772
|
}
|
|
2829
|
-
|
|
2773
|
+
const currentValue = module.get.values();
|
|
2830
2774
|
let newValue;
|
|
2831
2775
|
if (module.has.value(addedValue)) {
|
|
2832
2776
|
module.debug('Value already selected');
|
|
@@ -2840,7 +2784,9 @@
|
|
|
2840
2784
|
}
|
|
2841
2785
|
// extend current array
|
|
2842
2786
|
if (Array.isArray(currentValue)) {
|
|
2843
|
-
newValue = $selectedItem && $selectedItem.hasClass(className.actionable)
|
|
2787
|
+
newValue = $selectedItem && $selectedItem.hasClass(className.actionable)
|
|
2788
|
+
? currentValue
|
|
2789
|
+
: [...currentValue, addedValue];
|
|
2844
2790
|
newValue = module.get.uniqueArray(newValue);
|
|
2845
2791
|
} else {
|
|
2846
2792
|
newValue = [addedValue];
|
|
@@ -2883,11 +2829,11 @@
|
|
|
2883
2829
|
initialLoad = false;
|
|
2884
2830
|
},
|
|
2885
2831
|
upward: function ($currentMenu) {
|
|
2886
|
-
|
|
2832
|
+
const $element = $currentMenu || $module;
|
|
2887
2833
|
$element.removeClass(className.upward);
|
|
2888
2834
|
},
|
|
2889
2835
|
leftward: function ($currentMenu) {
|
|
2890
|
-
|
|
2836
|
+
const $element = $currentMenu || $menu;
|
|
2891
2837
|
$element.removeClass(className.leftward);
|
|
2892
2838
|
},
|
|
2893
2839
|
visible: function () {
|
|
@@ -2899,7 +2845,7 @@
|
|
|
2899
2845
|
filteredItem: function () {
|
|
2900
2846
|
if (settings.highlightMatches) {
|
|
2901
2847
|
$.each($item, function (index, item) {
|
|
2902
|
-
|
|
2848
|
+
const $markItem = $(item);
|
|
2903
2849
|
$markItem.html($markItem.html().replace(/<\/?mark>/g, ''));
|
|
2904
2850
|
});
|
|
2905
2851
|
}
|
|
@@ -2917,16 +2863,15 @@
|
|
|
2917
2863
|
module.remove.empty();
|
|
2918
2864
|
},
|
|
2919
2865
|
optionValue: function (value) {
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
let hasOption = $option.length > 0;
|
|
2866
|
+
const $option = $input.find('option[value="' + CSS.escape(value) + '"]');
|
|
2867
|
+
const hasOption = $option.length > 0;
|
|
2923
2868
|
if (!hasOption || !$option.hasClass(className.addition)) {
|
|
2924
2869
|
return;
|
|
2925
2870
|
}
|
|
2926
2871
|
// temporarily disconnect observer
|
|
2927
2872
|
module.disconnect.selectObserver();
|
|
2928
2873
|
$option.remove();
|
|
2929
|
-
module.verbose('Removing user addition as an <option>',
|
|
2874
|
+
module.verbose('Removing user addition as an <option>', value);
|
|
2930
2875
|
module.observe.select();
|
|
2931
2876
|
},
|
|
2932
2877
|
message: function () {
|
|
@@ -2954,9 +2899,9 @@
|
|
|
2954
2899
|
|
|
2955
2900
|
$selectedItem
|
|
2956
2901
|
.each(function () {
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2902
|
+
const $selected = $(this);
|
|
2903
|
+
const selectedText = module.get.choiceText($selected);
|
|
2904
|
+
const selectedValue = module.get.choiceValue($selected, selectedText);
|
|
2960
2905
|
if (module.is.multiple()) {
|
|
2961
2906
|
if (settings.useLabels) {
|
|
2962
2907
|
module.remove.value(selectedValue, selectedText, $selected, preventChangeTrigger);
|
|
@@ -2984,7 +2929,7 @@
|
|
|
2984
2929
|
$item.removeClass(className.selected);
|
|
2985
2930
|
},
|
|
2986
2931
|
value: function (removedValue, removedText, $removedItem, preventChangeTrigger) {
|
|
2987
|
-
|
|
2932
|
+
const values = module.get.values();
|
|
2988
2933
|
let newValue;
|
|
2989
2934
|
if (module.has.selectInput()) {
|
|
2990
2935
|
module.verbose('Input is <select> removing selected option', removedValue);
|
|
@@ -3015,9 +2960,8 @@
|
|
|
3015
2960
|
return values;
|
|
3016
2961
|
},
|
|
3017
2962
|
label: function (value, shouldAnimate) {
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
let $removedLabel = $labels.filter('[data-' + metadata.value + '="' + CSS.escape(settings.ignoreCase ? escapedValue.toLowerCase() : escapedValue) + '"]');
|
|
2963
|
+
const $labels = $module.find(selector.label);
|
|
2964
|
+
const $removedLabel = $labels.filter('[data-' + metadata.value + '="' + CSS.escape(settings.ignoreCase ? value.toLowerCase() : value) + '"]');
|
|
3021
2965
|
module.verbose('Removing label', $removedLabel);
|
|
3022
2966
|
$removedLabel.remove();
|
|
3023
2967
|
},
|
|
@@ -3031,12 +2975,12 @@
|
|
|
3031
2975
|
module.verbose('Removing labels', $labels);
|
|
3032
2976
|
$labels
|
|
3033
2977
|
.each(function () {
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
2978
|
+
const $label = $(this);
|
|
2979
|
+
const value = $label.data(metadata.value);
|
|
2980
|
+
const stringValue = value !== undefined
|
|
3037
2981
|
? String(value)
|
|
3038
2982
|
: value;
|
|
3039
|
-
|
|
2983
|
+
const isUserValue = module.is.userValue(stringValue);
|
|
3040
2984
|
if (settings.onLabelRemove.call($label, value) === false) {
|
|
3041
2985
|
module.debug('Label remove callback cancelled removal');
|
|
3042
2986
|
|
|
@@ -3088,27 +3032,21 @@
|
|
|
3088
3032
|
selectInput: function () {
|
|
3089
3033
|
return $input.is('select');
|
|
3090
3034
|
},
|
|
3091
|
-
minCharacters: function (searchTerm) {
|
|
3035
|
+
minCharacters: function (searchTerm = module.get.query()) {
|
|
3092
3036
|
if (settings.minCharacters && !iconClicked) {
|
|
3093
|
-
|
|
3094
|
-
? String(searchTerm)
|
|
3095
|
-
: String(module.get.query());
|
|
3096
|
-
|
|
3097
|
-
return searchTerm.length >= settings.minCharacters;
|
|
3037
|
+
return String(searchTerm).length >= settings.minCharacters;
|
|
3098
3038
|
}
|
|
3099
3039
|
iconClicked = false;
|
|
3100
3040
|
|
|
3101
3041
|
return true;
|
|
3102
3042
|
},
|
|
3103
3043
|
firstLetter: function ($item, letter) {
|
|
3104
|
-
let text;
|
|
3105
|
-
let firstLetter;
|
|
3106
3044
|
if (!$item || $item.length === 0 || typeof letter !== 'string') {
|
|
3107
3045
|
return false;
|
|
3108
3046
|
}
|
|
3109
|
-
text = module.get.choiceText($item, false);
|
|
3047
|
+
const text = module.get.choiceText($item, false);
|
|
3110
3048
|
letter = letter.toLowerCase();
|
|
3111
|
-
firstLetter = String(text).charAt(0).toLowerCase();
|
|
3049
|
+
const firstLetter = String(text).charAt(0).toLowerCase();
|
|
3112
3050
|
|
|
3113
3051
|
return letter == firstLetter;
|
|
3114
3052
|
},
|
|
@@ -3128,19 +3066,18 @@
|
|
|
3128
3066
|
return $menu.children(selector.message).length > 0;
|
|
3129
3067
|
},
|
|
3130
3068
|
label: function (value) {
|
|
3131
|
-
|
|
3132
|
-
let $labels = $module.find(selector.label);
|
|
3069
|
+
const $labels = $module.find(selector.label);
|
|
3133
3070
|
if (settings.ignoreCase) {
|
|
3134
|
-
|
|
3071
|
+
value = value.toLowerCase();
|
|
3135
3072
|
}
|
|
3136
3073
|
|
|
3137
|
-
return $labels.filter('[data-' + metadata.value + '="' + CSS.escape(
|
|
3074
|
+
return $labels.filter('[data-' + metadata.value + '="' + CSS.escape(value) + '"]').length > 0;
|
|
3138
3075
|
},
|
|
3139
3076
|
maxSelections: function () {
|
|
3140
3077
|
return settings.maxSelections && module.get.selectionCount() >= settings.maxSelections;
|
|
3141
3078
|
},
|
|
3142
3079
|
allResultsFiltered: function () {
|
|
3143
|
-
|
|
3080
|
+
const $normalResults = $item.not(selector.addition);
|
|
3144
3081
|
|
|
3145
3082
|
return $normalResults.filter(selector.unselectable).length === $normalResults.length;
|
|
3146
3083
|
},
|
|
@@ -3156,15 +3093,15 @@
|
|
|
3156
3093
|
: module.has.valueMatchingCase(value);
|
|
3157
3094
|
},
|
|
3158
3095
|
valueMatchingCase: function (value) {
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
? values && (
|
|
3096
|
+
const values = module.get.values();
|
|
3097
|
+
const hasValue = Array.isArray(values)
|
|
3098
|
+
? values && values.includes(value)
|
|
3162
3099
|
: values == value;
|
|
3163
3100
|
|
|
3164
3101
|
return !!hasValue;
|
|
3165
3102
|
},
|
|
3166
3103
|
valueIgnoringCase: function (value) {
|
|
3167
|
-
let values = module.get.values(
|
|
3104
|
+
let values = module.get.values();
|
|
3168
3105
|
let hasValue = false;
|
|
3169
3106
|
if (!Array.isArray(values)) {
|
|
3170
3107
|
values = [values];
|
|
@@ -3212,12 +3149,12 @@
|
|
|
3212
3149
|
: $menu.transition && $menu.transition('is animating');
|
|
3213
3150
|
},
|
|
3214
3151
|
leftward: function ($subMenu) {
|
|
3215
|
-
|
|
3152
|
+
const $selectedMenu = $subMenu || $menu;
|
|
3216
3153
|
|
|
3217
3154
|
return $selectedMenu.hasClass(className.leftward);
|
|
3218
3155
|
},
|
|
3219
3156
|
clearable: function () {
|
|
3220
|
-
|
|
3157
|
+
const hasClearableClass = $module.hasClass(className.clearable);
|
|
3221
3158
|
if (!hasClearableClass && settings.clearable) {
|
|
3222
3159
|
$module.addClass(className.clearable);
|
|
3223
3160
|
}
|
|
@@ -3288,10 +3225,10 @@
|
|
|
3288
3225
|
return $module.hasClass(className.selection);
|
|
3289
3226
|
},
|
|
3290
3227
|
userValue: function (value) {
|
|
3291
|
-
return
|
|
3228
|
+
return (module.get.userValues() || []).includes(value);
|
|
3292
3229
|
},
|
|
3293
3230
|
upward: function ($menu) {
|
|
3294
|
-
|
|
3231
|
+
const $element = $menu || $module;
|
|
3295
3232
|
|
|
3296
3233
|
return $element.hasClass(className.upward);
|
|
3297
3234
|
},
|
|
@@ -3301,14 +3238,14 @@
|
|
|
3301
3238
|
: $menu.hasClass(className.visible);
|
|
3302
3239
|
},
|
|
3303
3240
|
verticallyScrollableContext: function () {
|
|
3304
|
-
|
|
3241
|
+
const overflowY = $context[0] !== window
|
|
3305
3242
|
? $context.css('overflow-y')
|
|
3306
3243
|
: false;
|
|
3307
3244
|
|
|
3308
3245
|
return overflowY === 'auto' || overflowY === 'scroll';
|
|
3309
3246
|
},
|
|
3310
3247
|
horizontallyScrollableContext: function () {
|
|
3311
|
-
|
|
3248
|
+
const overflowX = $context[0] !== window
|
|
3312
3249
|
? $context.css('overflow-X')
|
|
3313
3250
|
: false;
|
|
3314
3251
|
|
|
@@ -3325,13 +3262,11 @@
|
|
|
3325
3262
|
);
|
|
3326
3263
|
},
|
|
3327
3264
|
openDownward: function ($subMenu) {
|
|
3328
|
-
|
|
3265
|
+
const $currentMenu = $subMenu || $menu;
|
|
3329
3266
|
let canOpenDownward;
|
|
3330
|
-
let onScreen;
|
|
3331
|
-
let calculations;
|
|
3332
3267
|
$currentMenu
|
|
3333
3268
|
.addClass(className.loading);
|
|
3334
|
-
calculations = {
|
|
3269
|
+
const calculations = {
|
|
3335
3270
|
context: {
|
|
3336
3271
|
offset: $context[0] === window
|
|
3337
3272
|
? { top: 0, left: 0 }
|
|
@@ -3350,7 +3285,7 @@
|
|
|
3350
3285
|
if (module.has.subMenu($currentMenu)) {
|
|
3351
3286
|
calculations.menu.height += $currentMenu.find(selector.menu).first().outerHeight();
|
|
3352
3287
|
}
|
|
3353
|
-
onScreen = {
|
|
3288
|
+
const onScreen = {
|
|
3354
3289
|
above: calculations.context.scrollTop <= calculations.menu.offset.top - calculations.context.offset.top - calculations.menu.height,
|
|
3355
3290
|
below: (calculations.context.scrollTop + calculations.context.height) >= calculations.menu.offset.top - calculations.context.offset.top + calculations.menu.height,
|
|
3356
3291
|
};
|
|
@@ -3369,13 +3304,12 @@
|
|
|
3369
3304
|
return canOpenDownward;
|
|
3370
3305
|
},
|
|
3371
3306
|
openRightward: function ($subMenu) {
|
|
3372
|
-
|
|
3307
|
+
const $currentMenu = $subMenu || $menu;
|
|
3373
3308
|
let canOpenRightward = true;
|
|
3374
3309
|
let isOffscreenRight = false;
|
|
3375
|
-
let calculations;
|
|
3376
3310
|
$currentMenu
|
|
3377
3311
|
.addClass(className.loading);
|
|
3378
|
-
calculations = {
|
|
3312
|
+
const calculations = {
|
|
3379
3313
|
context: {
|
|
3380
3314
|
offset: $context[0] === window
|
|
3381
3315
|
? { top: 0, left: 0 }
|
|
@@ -3421,21 +3355,20 @@
|
|
|
3421
3355
|
|
|
3422
3356
|
animate: {
|
|
3423
3357
|
show: function (callback, $subMenu) {
|
|
3424
|
-
|
|
3425
|
-
|
|
3358
|
+
const $currentMenu = $subMenu || $menu;
|
|
3359
|
+
const start = $subMenu
|
|
3426
3360
|
? function () {}
|
|
3427
3361
|
: function () {
|
|
3428
3362
|
module.hideSubMenus();
|
|
3429
3363
|
module.hideOthers();
|
|
3430
3364
|
module.set.active();
|
|
3431
3365
|
};
|
|
3432
|
-
let transition;
|
|
3433
3366
|
callback = isFunction(callback)
|
|
3434
3367
|
? callback
|
|
3435
3368
|
: function () {};
|
|
3436
3369
|
module.verbose('Doing menu show animation', $currentMenu);
|
|
3437
3370
|
module.set.direction($subMenu);
|
|
3438
|
-
transition = settings.transition.showMethod || module.get.transition($subMenu);
|
|
3371
|
+
const transition = settings.transition.showMethod || module.get.transition($subMenu);
|
|
3439
3372
|
if (module.is.selection()) {
|
|
3440
3373
|
module.set.scrollPosition(module.get.selectedItem(), true);
|
|
3441
3374
|
}
|
|
@@ -3465,14 +3398,14 @@
|
|
|
3465
3398
|
}
|
|
3466
3399
|
},
|
|
3467
3400
|
hide: function (callback, $subMenu) {
|
|
3468
|
-
|
|
3469
|
-
|
|
3401
|
+
const $currentMenu = $subMenu || $menu;
|
|
3402
|
+
const start = $subMenu
|
|
3470
3403
|
? function () {}
|
|
3471
3404
|
: function () {
|
|
3472
3405
|
module.unbind.intent();
|
|
3473
3406
|
module.remove.active();
|
|
3474
3407
|
};
|
|
3475
|
-
|
|
3408
|
+
const transition = settings.transition.hideMethod || module.get.transition($subMenu);
|
|
3476
3409
|
callback = isFunction(callback)
|
|
3477
3410
|
? callback
|
|
3478
3411
|
: function () {};
|
|
@@ -3539,46 +3472,26 @@
|
|
|
3539
3472
|
},
|
|
3540
3473
|
|
|
3541
3474
|
escape: {
|
|
3542
|
-
value: function (value) {
|
|
3543
|
-
let multipleValues = Array.isArray(value);
|
|
3544
|
-
let stringValue = typeof value === 'string';
|
|
3545
|
-
let isUnparsable = !stringValue && !multipleValues;
|
|
3546
|
-
let hasQuotes = stringValue && value.search(regExp.quote) !== -1;
|
|
3547
|
-
let values = [];
|
|
3548
|
-
if (isUnparsable || !hasQuotes) {
|
|
3549
|
-
return value;
|
|
3550
|
-
}
|
|
3551
|
-
module.debug('Encoding quote values for use in select', value);
|
|
3552
|
-
if (multipleValues) {
|
|
3553
|
-
$.each(value, function (index, value) {
|
|
3554
|
-
values.push(value.replace(regExp.quote, '"'));
|
|
3555
|
-
});
|
|
3556
|
-
|
|
3557
|
-
return values;
|
|
3558
|
-
}
|
|
3559
|
-
|
|
3560
|
-
return value.replace(regExp.quote, '"');
|
|
3561
|
-
},
|
|
3562
3475
|
string: function (text) {
|
|
3563
3476
|
text = String(text);
|
|
3564
3477
|
|
|
3565
3478
|
return text.replace(regExp.escape, '\\$&');
|
|
3566
3479
|
},
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
'
|
|
3578
|
-
'
|
|
3480
|
+
|
|
3481
|
+
// https://github.com/fomantic/Fomantic-UI/issues/2782
|
|
3482
|
+
// https://jsfiddle.net/3efL7jnt/
|
|
3483
|
+
assumeUnescapedAmpLtGt: function (string) {
|
|
3484
|
+
if (settings.preserveHTML) {
|
|
3485
|
+
return string;
|
|
3486
|
+
}
|
|
3487
|
+
|
|
3488
|
+
const unescapeMap = {
|
|
3489
|
+
'&': '&',
|
|
3490
|
+
'<': '<',
|
|
3491
|
+
'>': '>',
|
|
3579
3492
|
};
|
|
3580
3493
|
|
|
3581
|
-
return string.replace(
|
|
3494
|
+
return string.replace(/&(?:amp|lt|gt);/g, (v) => unescapeMap[v]);
|
|
3582
3495
|
},
|
|
3583
3496
|
},
|
|
3584
3497
|
|
|
@@ -3605,30 +3518,30 @@
|
|
|
3605
3518
|
return module[name];
|
|
3606
3519
|
}
|
|
3607
3520
|
},
|
|
3608
|
-
debug: function () {
|
|
3521
|
+
debug: function (...args) {
|
|
3609
3522
|
if (!settings.silent && settings.debug) {
|
|
3610
3523
|
if (settings.performance) {
|
|
3611
|
-
module.performance.log(
|
|
3524
|
+
module.performance.log(args);
|
|
3612
3525
|
} else {
|
|
3613
3526
|
module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
|
|
3614
|
-
module.debug.apply(console,
|
|
3527
|
+
module.debug.apply(console, args);
|
|
3615
3528
|
}
|
|
3616
3529
|
}
|
|
3617
3530
|
},
|
|
3618
|
-
verbose: function () {
|
|
3531
|
+
verbose: function (...args) {
|
|
3619
3532
|
if (!settings.silent && settings.verbose && settings.debug) {
|
|
3620
3533
|
if (settings.performance) {
|
|
3621
|
-
module.performance.log(
|
|
3534
|
+
module.performance.log(args);
|
|
3622
3535
|
} else {
|
|
3623
3536
|
module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
|
|
3624
|
-
module.verbose.apply(console,
|
|
3537
|
+
module.verbose.apply(console, args);
|
|
3625
3538
|
}
|
|
3626
3539
|
}
|
|
3627
3540
|
},
|
|
3628
|
-
error: function () {
|
|
3541
|
+
error: function (...args) {
|
|
3629
3542
|
if (!settings.silent) {
|
|
3630
3543
|
module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
|
|
3631
|
-
module.error.apply(console,
|
|
3544
|
+
module.error.apply(console, args);
|
|
3632
3545
|
}
|
|
3633
3546
|
},
|
|
3634
3547
|
performance: {
|
|
@@ -3643,7 +3556,7 @@
|
|
|
3643
3556
|
time = currentTime;
|
|
3644
3557
|
performance.push({
|
|
3645
3558
|
Name: message[0],
|
|
3646
|
-
Arguments:
|
|
3559
|
+
Arguments: message.slice(1),
|
|
3647
3560
|
Element: element,
|
|
3648
3561
|
'Execution Time': executionTime,
|
|
3649
3562
|
});
|
|
@@ -3664,30 +3577,22 @@
|
|
|
3664
3577
|
title += ' ' + totalTime + 'ms';
|
|
3665
3578
|
if (performance.length > 0) {
|
|
3666
3579
|
console.groupCollapsed(title);
|
|
3667
|
-
|
|
3668
|
-
console.table(performance);
|
|
3669
|
-
} else {
|
|
3670
|
-
$.each(performance, function (index, data) {
|
|
3671
|
-
console.log(data.Name + ': ' + data['Execution Time'] + 'ms');
|
|
3672
|
-
});
|
|
3673
|
-
}
|
|
3580
|
+
console.table(performance);
|
|
3674
3581
|
console.groupEnd();
|
|
3675
3582
|
}
|
|
3676
3583
|
performance = [];
|
|
3677
3584
|
},
|
|
3678
3585
|
},
|
|
3679
|
-
invoke: function (query, passedArguments, context) {
|
|
3586
|
+
invoke: function (query, passedArguments = queryArguments, context = element) {
|
|
3680
3587
|
let object = instance;
|
|
3681
3588
|
let maxDepth;
|
|
3682
3589
|
let found;
|
|
3683
3590
|
let response;
|
|
3684
|
-
passedArguments = passedArguments || queryArguments;
|
|
3685
|
-
context = context || element;
|
|
3686
3591
|
if (typeof query === 'string' && object !== undefined) {
|
|
3687
3592
|
query = query.split(/[ .]/);
|
|
3688
3593
|
maxDepth = query.length - 1;
|
|
3689
3594
|
$.each(query, function (depth, value) {
|
|
3690
|
-
|
|
3595
|
+
const camelCaseValue = depth !== maxDepth
|
|
3691
3596
|
? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
|
|
3692
3597
|
: query;
|
|
3693
3598
|
if ($.isPlainObject(object[camelCaseValue]) && (depth !== maxDepth)) {
|
|
@@ -3730,7 +3635,7 @@
|
|
|
3730
3635
|
if (instance === undefined) {
|
|
3731
3636
|
module.initialize();
|
|
3732
3637
|
}
|
|
3733
|
-
module.invoke(
|
|
3638
|
+
module.invoke(parameters);
|
|
3734
3639
|
} else {
|
|
3735
3640
|
if (instance !== undefined) {
|
|
3736
3641
|
instance.invoke('destroy');
|
|
@@ -3791,7 +3696,7 @@
|
|
|
3791
3696
|
|
|
3792
3697
|
maxSelections: false, // When set to a number, limits the number of selections to this count
|
|
3793
3698
|
useLabels: true, // whether multiple select should filter currently active selections from choices
|
|
3794
|
-
delimiter: ',', // when multiselect uses normal <input
|
|
3699
|
+
delimiter: ',', // when multiselect uses normal <input>, the values will be delimited with this character
|
|
3795
3700
|
|
|
3796
3701
|
showOnFocus: false, // show the menu on focus
|
|
3797
3702
|
allowReselection: false, // whether current value should trigger callbacks when reselected
|
|
@@ -3862,13 +3767,11 @@
|
|
|
3862
3767
|
missingMultiple: '<select> requires multiple property to be set to correctly preserve multiple values',
|
|
3863
3768
|
method: 'The method you called is not defined.',
|
|
3864
3769
|
noAPI: 'The API module is required to load resources remotely',
|
|
3865
|
-
noStorage: 'Saving remote data requires session storage',
|
|
3866
3770
|
noElement: 'This module requires ui {element}',
|
|
3867
3771
|
},
|
|
3868
3772
|
|
|
3869
3773
|
regExp: {
|
|
3870
3774
|
escape: /[\s#$()*+,.:=?@[\\\]^{|}-]/g,
|
|
3871
|
-
quote: /"/g,
|
|
3872
3775
|
},
|
|
3873
3776
|
|
|
3874
3777
|
metadata: {
|
|
@@ -3982,8 +3885,7 @@
|
|
|
3982
3885
|
return string;
|
|
3983
3886
|
}
|
|
3984
3887
|
|
|
3985
|
-
const
|
|
3986
|
-
const escape = {
|
|
3888
|
+
const escapeMap = {
|
|
3987
3889
|
'"': '"',
|
|
3988
3890
|
'&': '&',
|
|
3989
3891
|
"'": ''',
|
|
@@ -3991,14 +3893,14 @@
|
|
|
3991
3893
|
'>': '>',
|
|
3992
3894
|
};
|
|
3993
3895
|
|
|
3994
|
-
return string.replace(
|
|
3896
|
+
return String(string).replace(/["&'<>]/g, (chr) => escapeMap[chr]);
|
|
3995
3897
|
},
|
|
3996
3898
|
// generates dropdown from select values
|
|
3997
3899
|
dropdown: function (select, settings) {
|
|
3998
|
-
|
|
3900
|
+
const placeholder = select.placeholder || false;
|
|
3999
3901
|
let html = '';
|
|
4000
|
-
|
|
4001
|
-
|
|
3902
|
+
const className = settings.className;
|
|
3903
|
+
const escape = settings.templates.escape;
|
|
4002
3904
|
html += '<i class="dropdown icon"></i>';
|
|
4003
3905
|
html += placeholder
|
|
4004
3906
|
? '<div class="default text">' + escape(placeholder, settings) + '</div>'
|
|
@@ -4012,43 +3914,45 @@
|
|
|
4012
3914
|
|
|
4013
3915
|
// generates just menu from select
|
|
4014
3916
|
menu: function (response, settings) {
|
|
4015
|
-
|
|
4016
|
-
|
|
3917
|
+
const fields = settings.fields;
|
|
3918
|
+
const values = response[fields.values] || [];
|
|
4017
3919
|
let html = '';
|
|
4018
|
-
|
|
4019
|
-
|
|
3920
|
+
const className = settings.className;
|
|
3921
|
+
const escape = settings.templates.escape;
|
|
4020
3922
|
$.each(values, function (index, option) {
|
|
4021
|
-
|
|
4022
|
-
|
|
3923
|
+
const itemType = option[fields.type] || 'item';
|
|
3924
|
+
const isMenu = itemType.includes('menu');
|
|
4023
3925
|
let maybeData = '';
|
|
4024
|
-
|
|
3926
|
+
const dataObject = option[fields.data];
|
|
4025
3927
|
if (dataObject) {
|
|
4026
3928
|
let dataKey;
|
|
4027
3929
|
let dataKeyEscaped;
|
|
4028
3930
|
for (dataKey in dataObject) {
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
3931
|
+
if (Object.prototype.hasOwnProperty.call(dataObject, dataKey)) {
|
|
3932
|
+
dataKeyEscaped = String(dataKey).replace(/\W/g, '');
|
|
3933
|
+
if (!['text', 'value'].includes(dataKeyEscaped.toLowerCase())) {
|
|
3934
|
+
maybeData += ' data-' + dataKeyEscaped + '="' + escape(String(dataObject[dataKey])) + '"';
|
|
3935
|
+
}
|
|
4032
3936
|
}
|
|
4033
3937
|
}
|
|
4034
3938
|
}
|
|
4035
3939
|
if (itemType === 'item' || isMenu) {
|
|
4036
|
-
|
|
3940
|
+
const maybeText = option[fields.text]
|
|
4037
3941
|
? ' data-text="' + escape(option[fields.text]) + '"'
|
|
4038
3942
|
: '';
|
|
4039
|
-
|
|
3943
|
+
const maybeActionable = option[fields.actionable]
|
|
4040
3944
|
? className.actionable + ' '
|
|
4041
3945
|
: '';
|
|
4042
|
-
|
|
3946
|
+
const maybeDisabled = option[fields.disabled]
|
|
4043
3947
|
? className.disabled + ' '
|
|
4044
3948
|
: '';
|
|
4045
|
-
|
|
3949
|
+
const maybeDescriptionVertical = option[fields.descriptionVertical]
|
|
4046
3950
|
? className.descriptionVertical + ' '
|
|
4047
3951
|
: '';
|
|
4048
|
-
|
|
3952
|
+
const hasDescription = escape(option[fields.description] || '', settings) !== '';
|
|
4049
3953
|
html += '<div class="' + escape(maybeActionable + maybeDisabled + maybeDescriptionVertical + (option[fields.class] || className.item)) + '" data-value="' + escape(option[fields.value]) + '"' + maybeText + maybeData + '>';
|
|
4050
3954
|
if (isMenu) {
|
|
4051
|
-
html += '<i class="' + (itemType.
|
|
3955
|
+
html += '<i class="' + (itemType.includes('left') ? 'left' : '') + ' dropdown icon"></i>';
|
|
4052
3956
|
}
|
|
4053
3957
|
if (option[fields.image]) {
|
|
4054
3958
|
html += '<img class="' + escape(option[fields.imageClass] || className.image) + '" src="' + escape(option[fields.image]) + '"' + (option[fields.alt] ? ' alt="' + escape(option[fields.alt]) + '"' : '') + '>';
|
|
@@ -4074,8 +3978,8 @@
|
|
|
4074
3978
|
}
|
|
4075
3979
|
html += '</div>';
|
|
4076
3980
|
} else if (itemType === 'header') {
|
|
4077
|
-
|
|
4078
|
-
|
|
3981
|
+
const groupName = option[fields.name] || '';
|
|
3982
|
+
const groupIcon = option[fields.icon] || className.groupIcon;
|
|
4079
3983
|
if (groupName !== '' || groupIcon !== '') {
|
|
4080
3984
|
html += '<div class="' + escape(option[fields.class] || className.header) + '">';
|
|
4081
3985
|
if (groupIcon !== '') {
|
|
@@ -4095,8 +3999,8 @@
|
|
|
4095
3999
|
|
|
4096
4000
|
// generates label for multiselect
|
|
4097
4001
|
label: function (value, text, settings) {
|
|
4098
|
-
|
|
4099
|
-
|
|
4002
|
+
const className = settings.className;
|
|
4003
|
+
const escape = settings.templates.escape;
|
|
4100
4004
|
|
|
4101
4005
|
return escape(text, settings) + '<i class="' + escape(className.delete) + ' icon"></i>';
|
|
4102
4006
|
},
|