fomantic-ui 2.10.0-beta.1 → 2.10.0-beta.11
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/.all-contributorsrc +9 -0
- package/.eslintrc.js +0 -10
- package/CONTRIBUTING.md +4 -1
- package/CONTRIBUTORS.md +1 -0
- package/FAQ.md +7 -2
- package/README.md +5 -9
- package/ROADMAP.md +4 -4
- package/SECURITY.md +8 -7
- package/changelog-setup.js +64 -70
- package/dist/components/accordion.css +1 -1
- package/dist/components/accordion.js +103 -142
- package/dist/components/accordion.min.css +1 -1
- package/dist/components/accordion.min.js +2 -2
- package/dist/components/ad.css +1 -1
- package/dist/components/ad.min.css +1 -1
- package/dist/components/api.js +157 -210
- package/dist/components/api.min.js +2 -2
- package/dist/components/breadcrumb.css +1 -1
- package/dist/components/breadcrumb.min.css +1 -1
- package/dist/components/button.css +1 -2
- package/dist/components/button.min.css +2 -2
- package/dist/components/calendar.css +1 -2
- package/dist/components/calendar.js +314 -352
- package/dist/components/calendar.min.css +2 -2
- package/dist/components/calendar.min.js +2 -2
- package/dist/components/card.css +1 -1
- package/dist/components/card.min.css +1 -1
- package/dist/components/checkbox.css +1 -2
- package/dist/components/checkbox.js +85 -135
- package/dist/components/checkbox.min.css +2 -2
- package/dist/components/checkbox.min.js +2 -2
- package/dist/components/comment.css +1 -1
- package/dist/components/comment.min.css +1 -1
- package/dist/components/container.css +2 -4
- package/dist/components/container.min.css +2 -2
- package/dist/components/dimmer.css +1 -11
- package/dist/components/dimmer.js +61 -94
- package/dist/components/dimmer.min.css +2 -2
- package/dist/components/dimmer.min.js +2 -2
- package/dist/components/divider.css +1 -2
- package/dist/components/divider.min.css +2 -2
- package/dist/components/dropdown.css +30 -51
- package/dist/components/dropdown.js +736 -1055
- package/dist/components/dropdown.min.css +2 -2
- package/dist/components/dropdown.min.js +2 -2
- package/dist/components/embed.css +1 -1
- package/dist/components/embed.js +85 -114
- package/dist/components/embed.min.css +1 -1
- package/dist/components/embed.min.js +2 -2
- 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 +2 -3
- package/dist/components/flyout.js +226 -355
- package/dist/components/flyout.min.css +2 -2
- package/dist/components/flyout.min.js +2 -2
- package/dist/components/form.css +5 -95
- package/dist/components/form.js +335 -444
- package/dist/components/form.min.css +2 -2
- package/dist/components/form.min.js +2 -2
- package/dist/components/grid.css +2 -58
- package/dist/components/grid.min.css +2 -2
- package/dist/components/header.css +1 -1
- package/dist/components/header.min.css +1 -1
- package/dist/components/icon.css +4 -4
- 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 +1 -536
- 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 +1 -1
- package/dist/components/label.min.css +1 -1
- package/dist/components/list.css +1 -3
- package/dist/components/list.min.css +2 -2
- package/dist/components/loader.css +1 -1
- package/dist/components/loader.min.css +1 -1
- package/dist/components/menu.css +40 -48
- package/dist/components/menu.min.css +2 -2
- package/dist/components/message.css +1 -1
- package/dist/components/message.min.css +1 -1
- package/dist/components/modal.css +5 -9
- package/dist/components/modal.js +261 -384
- package/dist/components/modal.min.css +2 -2
- package/dist/components/modal.min.js +2 -2
- package/dist/components/nag.css +1 -1
- package/dist/components/nag.js +68 -98
- package/dist/components/nag.min.css +1 -1
- package/dist/components/nag.min.js +2 -2
- package/dist/components/placeholder.css +1 -1
- package/dist/components/placeholder.min.css +1 -1
- package/dist/components/popup.css +1 -2
- package/dist/components/popup.js +198 -271
- package/dist/components/popup.min.css +2 -2
- package/dist/components/popup.min.js +2 -2
- package/dist/components/progress.css +1 -1
- package/dist/components/progress.js +109 -144
- package/dist/components/progress.min.css +1 -1
- package/dist/components/progress.min.js +2 -2
- 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 +91 -123
- package/dist/components/rating.min.css +1 -1
- package/dist/components/rating.min.js +2 -2
- package/dist/components/reset.css +1 -1
- package/dist/components/reset.min.css +1 -1
- package/dist/components/reveal.css +1 -1
- package/dist/components/reveal.min.css +1 -1
- package/dist/components/search.css +2 -9
- package/dist/components/search.js +277 -379
- package/dist/components/search.min.css +2 -2
- package/dist/components/search.min.js +2 -2
- package/dist/components/segment.css +2 -7
- package/dist/components/segment.min.css +2 -2
- package/dist/components/shape.css +1 -2
- package/dist/components/shape.js +158 -224
- package/dist/components/shape.min.css +2 -2
- package/dist/components/shape.min.js +2 -2
- package/dist/components/sidebar.css +2 -3
- package/dist/components/sidebar.js +124 -206
- package/dist/components/sidebar.min.css +2 -2
- package/dist/components/sidebar.min.js +2 -2
- package/dist/components/site.css +9 -25
- package/dist/components/site.js +38 -57
- package/dist/components/site.min.css +2 -2
- package/dist/components/site.min.js +2 -2
- package/dist/components/slider.css +1 -1
- package/dist/components/slider.js +246 -329
- package/dist/components/slider.min.css +1 -1
- package/dist/components/slider.min.js +2 -2
- package/dist/components/state.js +70 -100
- package/dist/components/state.min.js +2 -2
- package/dist/components/statistic.css +1 -1
- package/dist/components/statistic.min.css +1 -1
- package/dist/components/step.css +1 -1
- package/dist/components/step.min.css +1 -1
- package/dist/components/sticky.css +1 -1
- package/dist/components/sticky.js +135 -180
- package/dist/components/sticky.min.css +1 -1
- package/dist/components/sticky.min.js +2 -2
- package/dist/components/tab.css +1 -1
- package/dist/components/tab.js +176 -244
- package/dist/components/tab.min.css +1 -1
- package/dist/components/tab.min.js +2 -2
- package/dist/components/table.css +3 -37
- 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 -3
- package/dist/components/toast.js +109 -147
- package/dist/components/toast.min.css +1 -1
- package/dist/components/toast.min.js +2 -2
- package/dist/components/transition.css +1 -1
- package/dist/components/transition.js +91 -146
- package/dist/components/transition.min.css +1 -1
- package/dist/components/transition.min.js +2 -2
- package/dist/components/visibility.js +146 -224
- package/dist/components/visibility.min.js +2 -2
- package/dist/semantic.css +3945 -8759
- package/dist/semantic.js +4397 -6155
- package/dist/semantic.min.css +2 -2
- package/dist/semantic.min.js +2 -2
- package/examples/assets/show-examples.js +2 -4
- package/examples/attached.html +1 -1
- package/examples/components/menu.html +1 -1
- package/gulpfile.js +5 -7
- package/package.json +3 -5
- package/scripts/nightly-version.js +7 -10
- package/src/README.md +3 -3
- package/src/definitions/behaviors/api.js +156 -209
- package/src/definitions/behaviors/form.js +334 -443
- package/src/definitions/behaviors/state.js +69 -99
- package/src/definitions/behaviors/visibility.js +145 -223
- package/src/definitions/collections/form.less +1 -13
- package/src/definitions/collections/grid.less +1 -61
- package/src/definitions/collections/menu.less +101 -107
- package/src/definitions/collections/table.less +1 -35
- package/src/definitions/elements/input.less +1 -61
- package/src/definitions/elements/segment.less +0 -6
- package/src/definitions/globals/site.js +37 -56
- package/src/definitions/globals/site.less +2 -18
- package/src/definitions/modules/accordion.js +102 -141
- package/src/definitions/modules/calendar.js +313 -351
- package/src/definitions/modules/checkbox.js +84 -134
- package/src/definitions/modules/dimmer.js +60 -93
- package/src/definitions/modules/dimmer.less +0 -9
- package/src/definitions/modules/dropdown.js +735 -1054
- package/src/definitions/modules/dropdown.less +31 -47
- package/src/definitions/modules/embed.js +84 -113
- package/src/definitions/modules/flyout.js +225 -354
- package/src/definitions/modules/modal.js +260 -383
- package/src/definitions/modules/modal.less +1 -1
- package/src/definitions/modules/nag.js +67 -97
- package/src/definitions/modules/popup.js +197 -270
- package/src/definitions/modules/progress.js +108 -143
- package/src/definitions/modules/rating.js +90 -122
- package/src/definitions/modules/search.js +276 -378
- package/src/definitions/modules/search.less +0 -3
- package/src/definitions/modules/shape.js +157 -223
- package/src/definitions/modules/sidebar.js +123 -205
- package/src/definitions/modules/slider.js +245 -328
- package/src/definitions/modules/slider.less +1 -1
- package/src/definitions/modules/sticky.js +134 -179
- package/src/definitions/modules/tab.js +175 -243
- package/src/definitions/modules/toast.js +108 -146
- package/src/definitions/modules/toast.less +1 -1
- package/src/definitions/modules/transition.js +90 -145
- package/src/theme.less +0 -13
- package/src/themes/basic/elements/icon.variables +1 -1
- package/src/themes/chubby/collections/menu.variables +1 -1
- package/src/themes/default/collections/grid.variables +0 -30
- package/src/themes/default/collections/menu.variables +23 -23
- package/src/themes/default/collections/table.variables +1 -5
- package/src/themes/default/elements/icon.variables +3 -3
- package/src/themes/default/globals/site.variables +8 -15
- package/src/themes/default/globals/variation.variables +3 -3
- package/src/themes/default/modules/dropdown.variables +1 -0
- package/src/themes/default/modules/slider.variables +1 -1
- package/src/themes/github/elements/icon.variables +1 -1
- package/src/themes/material/elements/icon.variables +1 -1
- package/tasks/README.md +1 -1
- package/tasks/admin/components/create.js +89 -122
- package/tasks/admin/components/init.js +34 -65
- package/tasks/admin/components/update.js +50 -61
- package/tasks/admin/distributions/create.js +71 -111
- package/tasks/admin/distributions/init.js +32 -63
- package/tasks/admin/distributions/update.js +49 -57
- package/tasks/admin/publish.js +1 -1
- package/tasks/admin/register.js +14 -19
- package/tasks/admin/release.js +2 -2
- package/tasks/build/assets.js +14 -18
- package/tasks/build/css.js +59 -68
- package/tasks/build/javascript.js +48 -56
- package/tasks/build.js +4 -6
- package/tasks/check-install.js +5 -8
- package/tasks/clean.js +5 -7
- package/tasks/collections/admin.js +14 -16
- package/tasks/collections/build.js +6 -8
- package/tasks/collections/docs.js +4 -6
- package/tasks/collections/install.js +2 -4
- package/tasks/collections/rtl.js +2 -4
- package/tasks/collections/various.js +2 -4
- package/tasks/config/admin/github.js +9 -19
- package/tasks/config/admin/templates/README.md +2 -2
- package/tasks/config/admin/templates/bower.json +2 -4
- package/tasks/config/admin/templates/composer.json +1 -1
- package/tasks/config/admin/templates/css-package.js +1 -4
- package/tasks/config/admin/templates/less-package.js +1 -3
- package/tasks/config/defaults.js +0 -1
- package/tasks/config/npm/gulpfile.js +4 -6
- package/tasks/config/project/config.js +27 -35
- package/tasks/config/project/install.js +64 -82
- package/tasks/config/project/release.js +7 -9
- package/tasks/config/tasks.js +10 -21
- package/tasks/config/user.js +14 -20
- package/tasks/docs/build.js +26 -31
- package/tasks/docs/metadata.js +30 -39
- package/tasks/docs/serve.js +23 -27
- package/tasks/install.js +94 -128
- package/tasks/rtl/build.js +2 -4
- package/tasks/rtl/watch.js +3 -5
- package/tasks/watch.js +13 -13
- package/test/meteor/fonts.js +1 -2
- package/test/modules/module.spec.js +16 -18
- package/types/fomantic-ui-calendar.d.ts +1 -1
- package/types/fomantic-ui-dropdown.d.ts +45 -1
- package/types/fomantic-ui-embed.d.ts +1 -1
- package/types/fomantic-ui-flyout.d.ts +1 -1
- package/types/fomantic-ui-form.d.ts +0 -7
- package/types/fomantic-ui-modal.d.ts +1 -1
- package/types/fomantic-ui-search.d.ts +12 -6
- package/types/fomantic-ui-toast.d.ts +1 -1
- package/src/themes/basic/assets/fonts/icons.woff +0 -0
- package/src/themes/default/assets/fonts/Lato-Bold.woff +0 -0
- package/src/themes/default/assets/fonts/Lato-BoldItalic.woff +0 -0
- package/src/themes/default/assets/fonts/Lato-Italic.woff +0 -0
- package/src/themes/default/assets/fonts/Lato-Regular.woff +0 -0
- package/src/themes/default/assets/fonts/LatoLatin-Bold.woff +0 -0
- package/src/themes/default/assets/fonts/LatoLatin-BoldItalic.woff +0 -0
- package/src/themes/default/assets/fonts/LatoLatin-Italic.woff +0 -0
- package/src/themes/default/assets/fonts/LatoLatin-Regular.woff +0 -0
- package/src/themes/default/assets/fonts/brand-icons.woff +0 -0
- package/src/themes/default/assets/fonts/icons.woff +0 -0
- package/src/themes/default/assets/fonts/outline-icons.woff +0 -0
- package/src/themes/github/assets/fonts/octicons.woff +0 -0
- package/src/themes/material/assets/fonts/icons.woff +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* # Fomantic-UI 2.10.0-beta.
|
2
|
+
* # Fomantic-UI 2.10.0-beta.11+6d1b302 - Search
|
3
3
|
* https://github.com/fomantic/Fomantic-UI/
|
4
4
|
*
|
5
5
|
*
|
@@ -20,49 +20,45 @@
|
|
20
20
|
: globalThis;
|
21
21
|
|
22
22
|
$.fn.search = function (parameters) {
|
23
|
-
|
24
|
-
$allModules = $(this),
|
23
|
+
let $allModules = $(this);
|
25
24
|
|
26
|
-
|
27
|
-
|
25
|
+
let time = Date.now();
|
26
|
+
let performance = [];
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
;
|
28
|
+
let query = arguments[0];
|
29
|
+
let methodInvoked = typeof query === 'string';
|
30
|
+
let queryArguments = [].slice.call(arguments, 1);
|
31
|
+
let returnedValue;
|
34
32
|
$allModules.each(function () {
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
module
|
65
|
-
;
|
33
|
+
let settings = $.isPlainObject(parameters)
|
34
|
+
? $.extend(true, {}, $.fn.search.settings, parameters)
|
35
|
+
: $.extend({}, $.fn.search.settings);
|
36
|
+
|
37
|
+
let className = settings.className;
|
38
|
+
let metadata = settings.metadata;
|
39
|
+
let regExp = settings.regExp;
|
40
|
+
let fields = settings.fields;
|
41
|
+
let selector = settings.selector;
|
42
|
+
let error = settings.error;
|
43
|
+
let namespace = settings.namespace;
|
44
|
+
|
45
|
+
let eventNamespace = '.' + namespace;
|
46
|
+
let moduleNamespace = namespace + '-module';
|
47
|
+
|
48
|
+
let $module = $(this);
|
49
|
+
let $prompt = $module.find(selector.prompt);
|
50
|
+
let $searchButton = $module.find(selector.searchButton);
|
51
|
+
let $results = $module.find(selector.results);
|
52
|
+
let $result = $module.find(selector.result);
|
53
|
+
let $category = $module.find(selector.category);
|
54
|
+
|
55
|
+
let element = this;
|
56
|
+
let instance = $module.data(moduleNamespace);
|
57
|
+
|
58
|
+
let disabledBubbled = false;
|
59
|
+
let resultsDismissed = false;
|
60
|
+
|
61
|
+
let module;
|
66
62
|
|
67
63
|
module = {
|
68
64
|
|
@@ -79,15 +75,13 @@
|
|
79
75
|
module.verbose('Storing instance of module', module);
|
80
76
|
instance = module;
|
81
77
|
$module
|
82
|
-
.data(moduleNamespace, module)
|
83
|
-
;
|
78
|
+
.data(moduleNamespace, module);
|
84
79
|
},
|
85
80
|
destroy: function () {
|
86
81
|
module.verbose('Destroying instance');
|
87
82
|
$module
|
88
83
|
.off(eventNamespace)
|
89
|
-
.removeData(moduleNamespace)
|
90
|
-
;
|
84
|
+
.removeData(moduleNamespace);
|
91
85
|
},
|
92
86
|
|
93
87
|
refresh: function () {
|
@@ -109,11 +103,9 @@
|
|
109
103
|
module.verbose('Binding events to search');
|
110
104
|
if (settings.automatic) {
|
111
105
|
$module
|
112
|
-
.on(module.get.inputEvent() + eventNamespace, selector.prompt, module.event.input)
|
113
|
-
;
|
106
|
+
.on(module.get.inputEvent() + eventNamespace, selector.prompt, module.event.input);
|
114
107
|
$prompt
|
115
|
-
.attr('autocomplete', module.is.chrome() ? 'fomantic-search' : 'off')
|
116
|
-
;
|
108
|
+
.attr('autocomplete', module.is.chrome() ? 'fomantic-search' : 'off');
|
117
109
|
}
|
118
110
|
$module
|
119
111
|
// prompt
|
@@ -126,20 +118,18 @@
|
|
126
118
|
.on('mousedown' + eventNamespace, selector.results, module.event.result.mousedown)
|
127
119
|
.on('mouseup' + eventNamespace, selector.results, module.event.result.mouseup)
|
128
120
|
.on('click' + eventNamespace, selector.result, module.event.result.click)
|
129
|
-
.on('click' + eventNamespace, selector.remove, module.event.remove.click)
|
130
|
-
;
|
121
|
+
.on('click' + eventNamespace, selector.remove, module.event.remove.click);
|
131
122
|
},
|
132
123
|
},
|
133
124
|
|
134
125
|
determine: {
|
135
126
|
searchFields: function () {
|
136
127
|
// this makes sure $.extend does not add specified search fields to default fields
|
137
|
-
// this is the only setting
|
128
|
+
// this is the only setting that should not extend defaults
|
138
129
|
if (parameters && parameters.searchFields !== undefined) {
|
139
130
|
settings.searchFields = Array.isArray(parameters.searchFields)
|
140
131
|
? parameters.searchFields
|
141
|
-
: [parameters.searchFields]
|
142
|
-
;
|
132
|
+
: [parameters.searchFields];
|
143
133
|
}
|
144
134
|
},
|
145
135
|
},
|
@@ -168,16 +158,14 @@
|
|
168
158
|
}
|
169
159
|
},
|
170
160
|
blur: function (event) {
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
module.
|
177
|
-
|
178
|
-
|
179
|
-
}
|
180
|
-
;
|
161
|
+
let pageLostFocus = document.activeElement === this;
|
162
|
+
let callback = function () {
|
163
|
+
module.cancel.query();
|
164
|
+
module.remove.focus();
|
165
|
+
module.timer = setTimeout(function () {
|
166
|
+
module.hideResults();
|
167
|
+
}, settings.hideDelay);
|
168
|
+
};
|
181
169
|
if (pageLostFocus) {
|
182
170
|
return;
|
183
171
|
}
|
@@ -195,8 +183,7 @@
|
|
195
183
|
if (!module.is.animating() && !module.is.hidden()) {
|
196
184
|
callback();
|
197
185
|
}
|
198
|
-
})
|
199
|
-
;
|
186
|
+
});
|
200
187
|
} else {
|
201
188
|
module.debug('Input blurred without user action, closing results');
|
202
189
|
callback();
|
@@ -217,22 +204,20 @@
|
|
217
204
|
},
|
218
205
|
click: function (event) {
|
219
206
|
module.debug('Search result selected');
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
;
|
235
|
-
var oldValue = module.get.value();
|
207
|
+
let $result = $(this);
|
208
|
+
let $title = $result.find(selector.title).eq(0);
|
209
|
+
let $link = $result.is('a[href]')
|
210
|
+
? $result
|
211
|
+
: $result.find('a[href]').eq(0);
|
212
|
+
let href = $link.attr('href') || false;
|
213
|
+
let target = $link.attr('target') || false;
|
214
|
+
// title is used for result lookup
|
215
|
+
let value = $title.length > 0
|
216
|
+
? $title.text()
|
217
|
+
: false;
|
218
|
+
let results = module.get.results();
|
219
|
+
let result = $result.data(metadata.result) || module.get.result(value, results);
|
220
|
+
let oldValue = module.get.value();
|
236
221
|
if (isFunction(settings.onSelect)) {
|
237
222
|
if (settings.onSelect.call(element, result, results) === false) {
|
238
223
|
module.debug('Custom onSelect callback cancelled default select action');
|
@@ -258,12 +243,10 @@
|
|
258
243
|
},
|
259
244
|
},
|
260
245
|
ensureVisible: function ($el) {
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
resultsHeight
|
266
|
-
;
|
246
|
+
let elTop;
|
247
|
+
let elBottom;
|
248
|
+
let resultsScrollTop;
|
249
|
+
let resultsHeight;
|
267
250
|
if ($el.length === 0) {
|
268
251
|
return;
|
269
252
|
}
|
@@ -280,25 +263,23 @@
|
|
280
263
|
}
|
281
264
|
},
|
282
265
|
handleKeyboard: function (event) {
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
newIndex
|
301
|
-
;
|
266
|
+
// force selector refresh
|
267
|
+
let $result = $module.find(selector.result);
|
268
|
+
let $category = $module.find(selector.category);
|
269
|
+
let $activeResult = $result.filter('.' + className.active);
|
270
|
+
let currentIndex = $result.index($activeResult);
|
271
|
+
let resultSize = $result.length;
|
272
|
+
let hasActiveResult = $activeResult.length > 0;
|
273
|
+
|
274
|
+
let keyCode = event.which;
|
275
|
+
let keys = {
|
276
|
+
backspace: 8,
|
277
|
+
enter: 13,
|
278
|
+
escape: 27,
|
279
|
+
upArrow: 38,
|
280
|
+
downArrow: 40,
|
281
|
+
};
|
282
|
+
let newIndex;
|
302
283
|
// search shortcuts
|
303
284
|
if (keyCode === keys.escape) {
|
304
285
|
if (!module.is.visible()) {
|
@@ -325,15 +306,13 @@
|
|
325
306
|
? currentIndex
|
326
307
|
: currentIndex - 1;
|
327
308
|
$category
|
328
|
-
.removeClass(className.active)
|
329
|
-
;
|
309
|
+
.removeClass(className.active);
|
330
310
|
$result
|
331
311
|
.removeClass(className.active)
|
332
312
|
.eq(newIndex)
|
333
313
|
.addClass(className.active)
|
334
314
|
.closest($category)
|
335
|
-
.addClass(className.active)
|
336
|
-
;
|
315
|
+
.addClass(className.active);
|
337
316
|
module.ensureVisible($result.eq(newIndex));
|
338
317
|
event.preventDefault();
|
339
318
|
} else if (keyCode === keys.downArrow) {
|
@@ -342,15 +321,13 @@
|
|
342
321
|
? currentIndex
|
343
322
|
: currentIndex + 1;
|
344
323
|
$category
|
345
|
-
.removeClass(className.active)
|
346
|
-
;
|
324
|
+
.removeClass(className.active);
|
347
325
|
$result
|
348
326
|
.removeClass(className.active)
|
349
327
|
.eq(newIndex)
|
350
328
|
.addClass(className.active)
|
351
329
|
.closest($category)
|
352
|
-
.addClass(className.active)
|
353
|
-
;
|
330
|
+
.addClass(className.active);
|
354
331
|
module.ensureVisible($result.eq(newIndex));
|
355
332
|
event.preventDefault();
|
356
333
|
}
|
@@ -367,44 +344,42 @@
|
|
367
344
|
|
368
345
|
setup: {
|
369
346
|
api: function (searchTerm, callback) {
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
query: searchTerm,
|
378
|
-
},
|
347
|
+
let apiSettings = {
|
348
|
+
debug: settings.debug,
|
349
|
+
on: false,
|
350
|
+
cache: settings.cache,
|
351
|
+
action: 'search',
|
352
|
+
urlData: {
|
353
|
+
query: searchTerm,
|
379
354
|
},
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
}
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
}
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
}
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
}
|
406
|
-
}
|
407
|
-
;
|
355
|
+
};
|
356
|
+
let apiCallbacks = {
|
357
|
+
onSuccess: function (response, $module, xhr) {
|
358
|
+
module.parse.response.call(element, response, searchTerm);
|
359
|
+
callback();
|
360
|
+
if (settings.apiSettings && typeof settings.apiSettings.onSuccess === 'function') {
|
361
|
+
settings.apiSettings.onSuccess.call(this, response, $module, xhr);
|
362
|
+
}
|
363
|
+
},
|
364
|
+
onFailure: function (response, $module, xhr) {
|
365
|
+
module.displayMessage(error.serverError);
|
366
|
+
callback();
|
367
|
+
if (settings.apiSettings && typeof settings.apiSettings.onFailure === 'function') {
|
368
|
+
settings.apiSettings.onFailure.call(this, response, $module, xhr);
|
369
|
+
}
|
370
|
+
},
|
371
|
+
onAbort: function (status, $module, xhr) {
|
372
|
+
if (settings.apiSettings && typeof settings.apiSettings.onAbort === 'function') {
|
373
|
+
settings.apiSettings.onAbort.call(this, status, $module, xhr);
|
374
|
+
}
|
375
|
+
},
|
376
|
+
onError: function (errorMessage, $module, xhr) {
|
377
|
+
module.error();
|
378
|
+
if (settings.apiSettings && typeof settings.apiSettings.onError === 'function') {
|
379
|
+
settings.apiSettings.onError.call(this, errorMessage, $module, xhr);
|
380
|
+
}
|
381
|
+
},
|
382
|
+
};
|
408
383
|
$.extend(true, apiSettings, settings.apiSettings, apiCallbacks);
|
409
384
|
module.verbose('Setting up API request', apiSettings);
|
410
385
|
$module.api(apiSettings);
|
@@ -437,10 +412,8 @@
|
|
437
412
|
if (!event.target) {
|
438
413
|
return;
|
439
414
|
}
|
440
|
-
|
441
|
-
|
442
|
-
isInDOM = $.contains(document.documentElement, event.target)
|
443
|
-
;
|
415
|
+
let $target = $(event.target);
|
416
|
+
let isInDOM = $.contains(document.documentElement, event.target);
|
444
417
|
|
445
418
|
return isInDOM && $target.closest(selector.message).length > 0;
|
446
419
|
},
|
@@ -461,20 +434,14 @@
|
|
461
434
|
settings.fullTextSearch = parameters.searchFullText;
|
462
435
|
module.error(settings.error.oldSearchSyntax, element);
|
463
436
|
}
|
464
|
-
if (settings.ignoreDiacritics && !String.prototype.normalize) {
|
465
|
-
settings.ignoreDiacritics = false;
|
466
|
-
module.error(error.noNormalize, element);
|
467
|
-
}
|
468
437
|
},
|
469
438
|
inputEvent: function () {
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
: 'keyup')
|
477
|
-
;
|
439
|
+
let prompt = $prompt[0];
|
440
|
+
let inputEvent = prompt !== undefined && prompt.oninput !== undefined
|
441
|
+
? 'input'
|
442
|
+
: (prompt !== undefined && prompt.onpropertychange !== undefined
|
443
|
+
? 'propertychange'
|
444
|
+
: 'keyup');
|
478
445
|
|
479
446
|
return inputEvent;
|
480
447
|
},
|
@@ -485,9 +452,7 @@
|
|
485
452
|
return $module.data(metadata.results);
|
486
453
|
},
|
487
454
|
result: function (value, results) {
|
488
|
-
|
489
|
-
result = false
|
490
|
-
;
|
455
|
+
let result = false;
|
491
456
|
value = value !== undefined
|
492
457
|
? value
|
493
458
|
: module.get.value();
|
@@ -531,8 +496,7 @@
|
|
531
496
|
value: function (value) {
|
532
497
|
module.verbose('Setting search input value', value);
|
533
498
|
$prompt
|
534
|
-
.val(value)
|
535
|
-
;
|
499
|
+
.val(value);
|
536
500
|
},
|
537
501
|
type: function (type) {
|
538
502
|
type = type || settings.type;
|
@@ -564,10 +528,8 @@
|
|
564
528
|
callback = isFunction(callback)
|
565
529
|
? callback
|
566
530
|
: function () {};
|
567
|
-
|
568
|
-
|
569
|
-
cache = module.read.cache(searchTerm)
|
570
|
-
;
|
531
|
+
let searchTerm = module.get.value();
|
532
|
+
let cache = module.read.cache(searchTerm);
|
571
533
|
callback = callback || function () {};
|
572
534
|
if (module.has.minimumCharacters()) {
|
573
535
|
if (cache) {
|
@@ -597,10 +559,8 @@
|
|
597
559
|
|
598
560
|
search: {
|
599
561
|
local: function (searchTerm) {
|
600
|
-
|
601
|
-
|
602
|
-
searchHTML
|
603
|
-
;
|
562
|
+
let results = module.search.object(searchTerm, settings.source);
|
563
|
+
let searchHTML;
|
604
564
|
module.set.loading();
|
605
565
|
module.save.results(results);
|
606
566
|
module.debug('Returned full local search results', results);
|
@@ -631,36 +591,31 @@
|
|
631
591
|
}
|
632
592
|
module.setup.api(searchTerm, callback);
|
633
593
|
$module
|
634
|
-
.api('query')
|
635
|
-
;
|
594
|
+
.api('query');
|
636
595
|
},
|
637
596
|
object: function (searchTerm, source, searchFields) {
|
638
597
|
searchTerm = module.remove.diacritics(String(searchTerm));
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
;
|
653
|
-
if (notResult && notFuzzyResult && notExactResults) {
|
654
|
-
array.push(result);
|
655
|
-
}
|
598
|
+
let results = [];
|
599
|
+
let exactResults = [];
|
600
|
+
let fuzzyResults = [];
|
601
|
+
let searchExp = searchTerm.replace(regExp.escape, '\\$&');
|
602
|
+
let matchRegExp = new RegExp(regExp.beginsWith + searchExp, settings.ignoreSearchCase ? 'i' : '');
|
603
|
+
|
604
|
+
// avoid duplicates when pushing results
|
605
|
+
let addResult = function (array, result) {
|
606
|
+
let notResult = $.inArray(result, results) === -1;
|
607
|
+
let notFuzzyResult = $.inArray(result, fuzzyResults) === -1;
|
608
|
+
let notExactResults = $.inArray(result, exactResults) === -1;
|
609
|
+
if (notResult && notFuzzyResult && notExactResults) {
|
610
|
+
array.push(result);
|
656
611
|
}
|
657
|
-
;
|
612
|
+
};
|
658
613
|
source = source || settings.source;
|
659
614
|
searchFields = searchFields !== undefined
|
660
615
|
? searchFields
|
661
616
|
: settings.searchFields;
|
662
617
|
|
663
|
-
// search fields should be array to loop correctly
|
618
|
+
// search fields should be an array to loop correctly
|
664
619
|
if (!Array.isArray(searchFields)) {
|
665
620
|
searchFields = [searchFields];
|
666
621
|
}
|
@@ -672,15 +627,13 @@
|
|
672
627
|
return [];
|
673
628
|
}
|
674
629
|
// iterate through search fields looking for matches
|
675
|
-
|
630
|
+
let lastSearchFieldIndex = searchFields.length - 1;
|
676
631
|
$.each(source, function (label, content) {
|
677
|
-
|
632
|
+
let concatenatedContent = [];
|
678
633
|
$.each(searchFields, function (index, field) {
|
679
|
-
|
680
|
-
fieldExists = typeof content[field] === 'string' || typeof content[field] === 'number'
|
681
|
-
;
|
634
|
+
let fieldExists = typeof content[field] === 'string' || typeof content[field] === 'number';
|
682
635
|
if (fieldExists) {
|
683
|
-
|
636
|
+
let text;
|
684
637
|
text = typeof content[field] === 'string'
|
685
638
|
? module.remove.diacritics(content[field])
|
686
639
|
: content[field].toString();
|
@@ -723,11 +676,10 @@
|
|
723
676
|
return term.indexOf(query) > -1;
|
724
677
|
},
|
725
678
|
wordSearch: function (query, term, matchAll) {
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
;
|
679
|
+
let allWords = query.split(/\s+/);
|
680
|
+
let w;
|
681
|
+
let wL = allWords.length;
|
682
|
+
let found = false;
|
731
683
|
for (w = 0; w < wL; w++) {
|
732
684
|
found = module.exactSearch(allWords[w], term);
|
733
685
|
if ((!found && matchAll) || (found && !matchAll)) {
|
@@ -738,10 +690,8 @@
|
|
738
690
|
return found;
|
739
691
|
},
|
740
692
|
fuzzySearch: function (query, term) {
|
741
|
-
|
742
|
-
|
743
|
-
queryLength = query.length
|
744
|
-
;
|
693
|
+
let termLength = term.length;
|
694
|
+
let queryLength = query.length;
|
745
695
|
if (typeof query !== 'string') {
|
746
696
|
return false;
|
747
697
|
}
|
@@ -755,11 +705,9 @@
|
|
755
705
|
if (queryLength === termLength) {
|
756
706
|
return query === term;
|
757
707
|
}
|
758
|
-
for (
|
759
|
-
|
760
|
-
|
761
|
-
queryCharacter = query.charCodeAt(characterIndex)
|
762
|
-
;
|
708
|
+
for (let characterIndex = 0, nextCharacterIndex = 0; characterIndex < queryLength; characterIndex++) {
|
709
|
+
let continueSearch = false;
|
710
|
+
let queryCharacter = query.charCodeAt(characterIndex);
|
763
711
|
while (nextCharacterIndex < termLength) {
|
764
712
|
if (term.charCodeAt(nextCharacterIndex++) === queryCharacter) {
|
765
713
|
continueSearch = true;
|
@@ -779,13 +727,11 @@
|
|
779
727
|
parse: {
|
780
728
|
response: function (response, searchTerm) {
|
781
729
|
if (Array.isArray(response)) {
|
782
|
-
|
730
|
+
let o = {};
|
783
731
|
o[fields.results] = response;
|
784
732
|
response = o;
|
785
733
|
}
|
786
|
-
|
787
|
-
searchHTML = module.generateResults(response)
|
788
|
-
;
|
734
|
+
let searchHTML = module.generateResults(response);
|
789
735
|
module.verbose('Parsing server response', response);
|
790
736
|
if (response !== undefined) {
|
791
737
|
if (searchTerm !== undefined && response[fields.results] !== undefined) {
|
@@ -811,10 +757,8 @@
|
|
811
757
|
|
812
758
|
has: {
|
813
759
|
minimumCharacters: function () {
|
814
|
-
|
815
|
-
|
816
|
-
numCharacters = searchTerm.length
|
817
|
-
;
|
760
|
+
let searchTerm = module.get.value();
|
761
|
+
let numCharacters = searchTerm.length;
|
818
762
|
|
819
763
|
return numCharacters >= settings.minCharacters;
|
820
764
|
},
|
@@ -822,9 +766,7 @@
|
|
822
766
|
if ($results.length === 0) {
|
823
767
|
return false;
|
824
768
|
}
|
825
|
-
|
826
|
-
html = $results.html()
|
827
|
-
;
|
769
|
+
let html = $results.html();
|
828
770
|
|
829
771
|
return html !== '';
|
830
772
|
},
|
@@ -832,9 +774,7 @@
|
|
832
774
|
|
833
775
|
clear: {
|
834
776
|
cache: function (value) {
|
835
|
-
|
836
|
-
cache = $module.data(metadata.cache)
|
837
|
-
;
|
777
|
+
let cache = $module.data(metadata.cache);
|
838
778
|
if (!value) {
|
839
779
|
module.debug('Clearing cache', value);
|
840
780
|
$module.removeData(metadata.cache);
|
@@ -851,9 +791,7 @@
|
|
851
791
|
|
852
792
|
read: {
|
853
793
|
cache: function (name) {
|
854
|
-
|
855
|
-
cache = $module.data(metadata.cache)
|
856
|
-
;
|
794
|
+
let cache = $module.data(metadata.cache);
|
857
795
|
if (settings.cache) {
|
858
796
|
module.verbose('Checking cache for generated html for query', name);
|
859
797
|
|
@@ -868,9 +806,7 @@
|
|
868
806
|
|
869
807
|
create: {
|
870
808
|
categoryResults: function (results) {
|
871
|
-
|
872
|
-
categoryResults = {}
|
873
|
-
;
|
809
|
+
let categoryResults = {};
|
874
810
|
$.each(results, function (index, result) {
|
875
811
|
if (!result.category) {
|
876
812
|
return;
|
@@ -889,11 +825,9 @@
|
|
889
825
|
return categoryResults;
|
890
826
|
},
|
891
827
|
id: function (resultIndex, categoryIndex) {
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
id
|
896
|
-
;
|
828
|
+
let resultID = resultIndex + 1; // not zero indexed
|
829
|
+
let letterID;
|
830
|
+
let id;
|
897
831
|
if (categoryIndex !== undefined) {
|
898
832
|
// start char code for "A"
|
899
833
|
letterID = String.fromCharCode(97 + categoryIndex);
|
@@ -910,8 +844,7 @@
|
|
910
844
|
if ($results.length === 0) {
|
911
845
|
$results = $('<div />')
|
912
846
|
.addClass(className.results)
|
913
|
-
.appendTo($module)
|
914
|
-
;
|
847
|
+
.appendTo($module);
|
915
848
|
}
|
916
849
|
},
|
917
850
|
},
|
@@ -919,29 +852,24 @@
|
|
919
852
|
inject: {
|
920
853
|
result: function (result, resultIndex, categoryIndex) {
|
921
854
|
module.verbose('Injecting result into results');
|
922
|
-
|
923
|
-
$
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
.children(selector.result).eq(resultIndex)
|
932
|
-
;
|
855
|
+
let $selectedResult = categoryIndex !== undefined
|
856
|
+
? $results
|
857
|
+
.children().eq(categoryIndex)
|
858
|
+
.children(selector.results)
|
859
|
+
.first()
|
860
|
+
.children(selector.result)
|
861
|
+
.eq(resultIndex)
|
862
|
+
: $results
|
863
|
+
.children(selector.result).eq(resultIndex);
|
933
864
|
module.verbose('Injecting results metadata', $selectedResult);
|
934
865
|
$selectedResult
|
935
|
-
.data(metadata.result, result)
|
936
|
-
;
|
866
|
+
.data(metadata.result, result);
|
937
867
|
},
|
938
868
|
id: function (results) {
|
939
869
|
module.debug('Injecting unique ids into results');
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
resultIndex = 0
|
944
|
-
;
|
870
|
+
// since results may be an object, we must use counters
|
871
|
+
let categoryIndex = 0;
|
872
|
+
let resultIndex = 0;
|
945
873
|
if (settings.type === 'category') {
|
946
874
|
// iterate through each category result
|
947
875
|
$.each(results, function (index, category) {
|
@@ -981,17 +909,14 @@
|
|
981
909
|
|
982
910
|
write: {
|
983
911
|
cache: function (name, value) {
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
: {}
|
988
|
-
;
|
912
|
+
let cache = $module.data(metadata.cache) !== undefined
|
913
|
+
? $module.data(metadata.cache)
|
914
|
+
: {};
|
989
915
|
if (settings.cache) {
|
990
916
|
module.verbose('Writing generated html to cache', name, value);
|
991
917
|
cache[name] = value;
|
992
918
|
$module
|
993
|
-
.data(metadata.cache, cache)
|
994
|
-
;
|
919
|
+
.data(metadata.cache, cache);
|
995
920
|
}
|
996
921
|
},
|
997
922
|
},
|
@@ -1006,8 +931,7 @@
|
|
1006
931
|
}
|
1007
932
|
if (html) {
|
1008
933
|
$results
|
1009
|
-
.html(html)
|
1010
|
-
;
|
934
|
+
.html(html);
|
1011
935
|
module.refreshResults();
|
1012
936
|
if (settings.selectFirstResult) {
|
1013
937
|
module.select.firstResult();
|
@@ -1038,21 +962,19 @@
|
|
1038
962
|
silent: settings.silent,
|
1039
963
|
duration: settings.duration,
|
1040
964
|
onShow: function () {
|
1041
|
-
|
965
|
+
let $firstResult = $module.find(selector.result).eq(0);
|
1042
966
|
module.ensureVisible($firstResult);
|
1043
967
|
},
|
1044
968
|
onComplete: function () {
|
1045
969
|
callback();
|
1046
970
|
},
|
1047
971
|
queue: true,
|
1048
|
-
})
|
1049
|
-
;
|
972
|
+
});
|
1050
973
|
} else {
|
1051
974
|
module.debug('Showing results with javascript');
|
1052
975
|
$results
|
1053
976
|
.stop()
|
1054
|
-
.fadeIn(settings.duration, settings.easing)
|
1055
|
-
;
|
977
|
+
.fadeIn(settings.duration, settings.easing);
|
1056
978
|
}
|
1057
979
|
settings.onResultsOpen.call($results);
|
1058
980
|
}
|
@@ -1075,14 +997,12 @@
|
|
1075
997
|
callback();
|
1076
998
|
},
|
1077
999
|
queue: true,
|
1078
|
-
})
|
1079
|
-
;
|
1000
|
+
});
|
1080
1001
|
} else {
|
1081
1002
|
module.debug('Hiding results with javascript');
|
1082
1003
|
$results
|
1083
1004
|
.stop()
|
1084
|
-
.fadeOut(settings.duration, settings.easing)
|
1085
|
-
;
|
1005
|
+
.fadeOut(settings.duration, settings.easing);
|
1086
1006
|
}
|
1087
1007
|
settings.onResultsClose.call($results);
|
1088
1008
|
}
|
@@ -1090,12 +1010,10 @@
|
|
1090
1010
|
|
1091
1011
|
generateResults: function (response) {
|
1092
1012
|
module.debug('Generating html from response', response);
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
html = ''
|
1098
|
-
;
|
1013
|
+
let template = settings.templates[settings.type];
|
1014
|
+
let isProperObject = $.isPlainObject(response[fields.results]) && !$.isEmptyObject(response[fields.results]);
|
1015
|
+
let isProperArray = Array.isArray(response[fields.results]) && response[fields.results].length > 0;
|
1016
|
+
let html = '';
|
1099
1017
|
if (isProperObject || isProperArray) {
|
1100
1018
|
if (settings.maxResults > 0) {
|
1101
1019
|
if (isProperObject) {
|
@@ -1107,27 +1025,24 @@
|
|
1107
1025
|
}
|
1108
1026
|
}
|
1109
1027
|
if (settings.highlightMatches) {
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1028
|
+
let results = response[fields.results];
|
1029
|
+
let regExpIgnore = settings.ignoreSearchCase ? 'i' : '';
|
1030
|
+
let querySplit = module.get.value().split('');
|
1031
|
+
let diacriticReg = settings.ignoreDiacritics ? '[\u0300-\u036F]?' : '';
|
1032
|
+
let htmlReg = '(?![^<]*>)';
|
1033
|
+
let markedRegExp = new RegExp(htmlReg + '(' + querySplit.join(diacriticReg + ')(.*?)' + htmlReg + '(') + diacriticReg + ')', regExpIgnore);
|
1034
|
+
let markedReplacer = function () {
|
1035
|
+
let args = [].slice.call(arguments, 1, querySplit.length * 2).map(function (x, i) {
|
1036
|
+
return i & 1 ? x : '<mark>' + x + '</mark>'; // eslint-disable-line no-bitwise
|
1037
|
+
});
|
1120
1038
|
|
1121
|
-
|
1122
|
-
|
1123
|
-
;
|
1039
|
+
return args.join('');
|
1040
|
+
};
|
1124
1041
|
$.each(results, function (label, content) {
|
1125
1042
|
$.each(settings.searchFields, function (index, field) {
|
1126
|
-
|
1127
|
-
fieldExists = typeof content[field] === 'string' || typeof content[field] === 'number'
|
1128
|
-
;
|
1043
|
+
let fieldExists = typeof content[field] === 'string' || typeof content[field] === 'number';
|
1129
1044
|
if (fieldExists) {
|
1130
|
-
|
1045
|
+
let markedHTML = typeof content[field] === 'string'
|
1131
1046
|
? content[field]
|
1132
1047
|
: content[field].toString();
|
1133
1048
|
if (settings.ignoreDiacritics) {
|
@@ -1140,7 +1055,7 @@
|
|
1140
1055
|
});
|
1141
1056
|
}
|
1142
1057
|
if (isFunction(template)) {
|
1143
|
-
html = template(response,
|
1058
|
+
html = template(response, settings);
|
1144
1059
|
} else {
|
1145
1060
|
module.error(error.noTemplate, false);
|
1146
1061
|
}
|
@@ -1206,11 +1121,9 @@
|
|
1206
1121
|
},
|
1207
1122
|
performance: {
|
1208
1123
|
log: function (message) {
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
previousTime
|
1213
|
-
;
|
1124
|
+
let currentTime;
|
1125
|
+
let executionTime;
|
1126
|
+
let previousTime;
|
1214
1127
|
if (settings.performance) {
|
1215
1128
|
currentTime = Date.now();
|
1216
1129
|
previousTime = time || currentTime;
|
@@ -1229,10 +1142,8 @@
|
|
1229
1142
|
}, 500);
|
1230
1143
|
},
|
1231
1144
|
display: function () {
|
1232
|
-
|
1233
|
-
|
1234
|
-
totalTime = 0
|
1235
|
-
;
|
1145
|
+
let title = settings.name + ':';
|
1146
|
+
let totalTime = 0;
|
1236
1147
|
time = false;
|
1237
1148
|
clearTimeout(module.performance.timer);
|
1238
1149
|
$.each(performance, function (index, data) {
|
@@ -1257,22 +1168,19 @@
|
|
1257
1168
|
},
|
1258
1169
|
},
|
1259
1170
|
invoke: function (query, passedArguments, context) {
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
response
|
1265
|
-
;
|
1171
|
+
let object = instance;
|
1172
|
+
let maxDepth;
|
1173
|
+
let found;
|
1174
|
+
let response;
|
1266
1175
|
passedArguments = passedArguments || queryArguments;
|
1267
1176
|
context = context || element;
|
1268
1177
|
if (typeof query === 'string' && object !== undefined) {
|
1269
1178
|
query = query.split(/[ .]/);
|
1270
1179
|
maxDepth = query.length - 1;
|
1271
1180
|
$.each(query, function (depth, value) {
|
1272
|
-
|
1181
|
+
let camelCaseValue = depth !== maxDepth
|
1273
1182
|
? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
|
1274
|
-
: query
|
1275
|
-
;
|
1183
|
+
: query;
|
1276
1184
|
if ($.isPlainObject(object[camelCaseValue]) && (depth !== maxDepth)) {
|
1277
1185
|
object = object[camelCaseValue];
|
1278
1186
|
} else if (object[camelCaseValue] !== undefined) {
|
@@ -1342,7 +1250,7 @@
|
|
1342
1250
|
// minimum characters required to search
|
1343
1251
|
minCharacters: 1,
|
1344
1252
|
|
1345
|
-
// whether to select first result after searching automatically
|
1253
|
+
// whether to select the first result after searching automatically
|
1346
1254
|
selectFirstResult: false,
|
1347
1255
|
|
1348
1256
|
// API config
|
@@ -1370,7 +1278,7 @@
|
|
1370
1278
|
// Whether search result should highlight matching strings
|
1371
1279
|
highlightMatches: false,
|
1372
1280
|
|
1373
|
-
// match results also if they contain diacritics of the same base character (for example searching for "a" will also match "á" or "â" or "à", etc...)
|
1281
|
+
// match results also if they contain diacritics of the same base character (for example, searching for "a" will also match "á" or "â" or "à", etc...)
|
1374
1282
|
ignoreDiacritics: false,
|
1375
1283
|
|
1376
1284
|
// whether to consider case sensitivity on local searching
|
@@ -1379,7 +1287,7 @@
|
|
1379
1287
|
// whether to add events to prompt automatically
|
1380
1288
|
automatic: true,
|
1381
1289
|
|
1382
|
-
// delay before hiding menu after blur
|
1290
|
+
// delay before hiding the menu after blur
|
1383
1291
|
hideDelay: 0,
|
1384
1292
|
|
1385
1293
|
// delay before searching
|
@@ -1395,7 +1303,7 @@
|
|
1395
1303
|
showNoResults: true,
|
1396
1304
|
|
1397
1305
|
// preserve possible html of resultset values
|
1398
|
-
preserveHTML:
|
1306
|
+
preserveHTML: false,
|
1399
1307
|
|
1400
1308
|
// transition settings
|
1401
1309
|
transition: 'scale',
|
@@ -1433,7 +1341,6 @@
|
|
1433
1341
|
serverError: 'There was an issue querying the server.',
|
1434
1342
|
maxResults: 'Results must be an array to use maxResults setting',
|
1435
1343
|
method: 'The method you called is not defined.',
|
1436
|
-
noNormalize: '"ignoreDiacritics" setting will be ignored. Browser does not support String().normalize(). You may consider including <https://cdn.jsdelivr.net/npm/unorm@1.4.1/lib/unorm.min.js> as a polyfill.',
|
1437
1344
|
},
|
1438
1345
|
|
1439
1346
|
metadata: {
|
@@ -1476,36 +1383,29 @@
|
|
1476
1383
|
},
|
1477
1384
|
|
1478
1385
|
templates: {
|
1479
|
-
escape: function (string,
|
1480
|
-
if (preserveHTML) {
|
1386
|
+
escape: function (string, settings) {
|
1387
|
+
if (settings !== undefined && settings.preserveHTML) {
|
1481
1388
|
return string;
|
1482
1389
|
}
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
string = string.replace(/&(?![\d#a-z]{1,12};)/gi, '&');
|
1498
|
-
string = string.replace(badChars, escapedChar);
|
1499
|
-
// FUI controlled HTML is still allowed
|
1500
|
-
string = string.replace(/<(\/)*mark>/g, '<$1mark>');
|
1501
|
-
}
|
1390
|
+
|
1391
|
+
const badChars = /["'<>]|&(?![\d#A-Za-z]{1,12};)/g;
|
1392
|
+
const escape = {
|
1393
|
+
'"': '"',
|
1394
|
+
'&': '&',
|
1395
|
+
"'": ''',
|
1396
|
+
'<': '<',
|
1397
|
+
'>': '>',
|
1398
|
+
};
|
1399
|
+
|
1400
|
+
string = String(string).replace(badChars, (chr) => escape[chr]);
|
1401
|
+
|
1402
|
+
// FUI controlled HTML is still allowed
|
1403
|
+
string = string.replace(/<(\/)*mark>/g, '<$1mark>');
|
1502
1404
|
|
1503
1405
|
return string;
|
1504
1406
|
},
|
1505
1407
|
message: function (message, type, header) {
|
1506
|
-
|
1507
|
-
html = ''
|
1508
|
-
;
|
1408
|
+
let html = '';
|
1509
1409
|
if (message !== undefined && type !== undefined) {
|
1510
1410
|
html += ''
|
1511
1411
|
+ '<div class="message ' + type + '">';
|
@@ -1519,11 +1419,10 @@
|
|
1519
1419
|
|
1520
1420
|
return html;
|
1521
1421
|
},
|
1522
|
-
category: function (response,
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
;
|
1422
|
+
category: function (response, settings) {
|
1423
|
+
let html = '';
|
1424
|
+
let fields = settings.fields;
|
1425
|
+
let escape = settings.templates.escape;
|
1527
1426
|
if (response[fields.categoryResults] !== undefined) {
|
1528
1427
|
// each category
|
1529
1428
|
$.each(response[fields.categoryResults], function (index, category) {
|
@@ -1531,7 +1430,7 @@
|
|
1531
1430
|
html += '<div class="category">';
|
1532
1431
|
|
1533
1432
|
if (category[fields.categoryName] !== undefined) {
|
1534
|
-
html += '<div class="name">' + escape(category[fields.categoryName],
|
1433
|
+
html += '<div class="name">' + escape(category[fields.categoryName], settings) + '</div>';
|
1535
1434
|
}
|
1536
1435
|
|
1537
1436
|
// each item inside category
|
@@ -1543,18 +1442,18 @@
|
|
1543
1442
|
if (result[fields.image] !== undefined) {
|
1544
1443
|
html += ''
|
1545
1444
|
+ '<div class="image">'
|
1546
|
-
+ ' <img src="' + result[fields.image].replace(/"/g, '') + (result[fields.alt] ? '
|
1445
|
+
+ ' <img src="' + result[fields.image].replace(/"/g, '') + '"' + (result[fields.alt] ? ' alt="' + result[fields.alt].replace(/"/g, '') + '"' : '') + '>'
|
1547
1446
|
+ '</div>';
|
1548
1447
|
}
|
1549
1448
|
html += '<div class="content">';
|
1550
1449
|
if (result[fields.price] !== undefined) {
|
1551
|
-
html += '<div class="price">' + escape(result[fields.price],
|
1450
|
+
html += '<div class="price">' + escape(result[fields.price], settings) + '</div>';
|
1552
1451
|
}
|
1553
1452
|
if (result[fields.title] !== undefined) {
|
1554
|
-
html += '<div class="title">' + escape(result[fields.title],
|
1453
|
+
html += '<div class="title">' + escape(result[fields.title], settings) + '</div>';
|
1555
1454
|
}
|
1556
1455
|
if (result[fields.description] !== undefined) {
|
1557
|
-
html += '<div class="description">' + escape(result[fields.description],
|
1456
|
+
html += '<div class="description">' + escape(result[fields.description], settings) + '</div>';
|
1558
1457
|
}
|
1559
1458
|
html += ''
|
1560
1459
|
+ '</div>';
|
@@ -1569,11 +1468,11 @@
|
|
1569
1468
|
html += fields.actionURL === false
|
1570
1469
|
? ''
|
1571
1470
|
+ '<div class="action">'
|
1572
|
-
+ escape(response[fields.action][fields.actionText],
|
1471
|
+
+ escape(response[fields.action][fields.actionText], settings)
|
1573
1472
|
+ '</div>'
|
1574
1473
|
: ''
|
1575
1474
|
+ '<a href="' + response[fields.action][fields.actionURL].replace(/"/g, '') + '" class="action">'
|
1576
|
-
+ escape(response[fields.action][fields.actionText],
|
1475
|
+
+ escape(response[fields.action][fields.actionText], settings)
|
1577
1476
|
+ '</a>';
|
1578
1477
|
}
|
1579
1478
|
|
@@ -1582,11 +1481,10 @@
|
|
1582
1481
|
|
1583
1482
|
return false;
|
1584
1483
|
},
|
1585
|
-
standard: function (response,
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
;
|
1484
|
+
standard: function (response, settings) {
|
1485
|
+
let html = '';
|
1486
|
+
let fields = settings.fields;
|
1487
|
+
let escape = settings.templates.escape;
|
1590
1488
|
if (response[fields.results] !== undefined) {
|
1591
1489
|
// each result
|
1592
1490
|
$.each(response[fields.results], function (index, result) {
|
@@ -1596,18 +1494,18 @@
|
|
1596
1494
|
if (result[fields.image] !== undefined) {
|
1597
1495
|
html += ''
|
1598
1496
|
+ '<div class="image">'
|
1599
|
-
+ ' <img src="' + result[fields.image].replace(/"/g, '') + (result[fields.alt] ? '
|
1497
|
+
+ ' <img src="' + result[fields.image].replace(/"/g, '') + '"' + (result[fields.alt] ? ' alt="' + result[fields.alt].replace(/"/g, '') + '"' : '') + '>'
|
1600
1498
|
+ '</div>';
|
1601
1499
|
}
|
1602
1500
|
html += '<div class="content">';
|
1603
1501
|
if (result[fields.price] !== undefined) {
|
1604
|
-
html += '<div class="price">' + escape(result[fields.price],
|
1502
|
+
html += '<div class="price">' + escape(result[fields.price], settings) + '</div>';
|
1605
1503
|
}
|
1606
1504
|
if (result[fields.title] !== undefined) {
|
1607
|
-
html += '<div class="title">' + escape(result[fields.title],
|
1505
|
+
html += '<div class="title">' + escape(result[fields.title], settings) + '</div>';
|
1608
1506
|
}
|
1609
1507
|
if (result[fields.description] !== undefined) {
|
1610
|
-
html += '<div class="description">' + escape(result[fields.description],
|
1508
|
+
html += '<div class="description">' + escape(result[fields.description], settings) + '</div>';
|
1611
1509
|
}
|
1612
1510
|
html += ''
|
1613
1511
|
+ '</div>';
|
@@ -1617,11 +1515,11 @@
|
|
1617
1515
|
html += fields.actionURL === false
|
1618
1516
|
? ''
|
1619
1517
|
+ '<div class="action">'
|
1620
|
-
+ escape(response[fields.action][fields.actionText],
|
1518
|
+
+ escape(response[fields.action][fields.actionText], settings)
|
1621
1519
|
+ '</div>'
|
1622
1520
|
: ''
|
1623
1521
|
+ '<a href="' + response[fields.action][fields.actionURL].replace(/"/g, '') + '" class="action">'
|
1624
|
-
+ escape(response[fields.action][fields.actionText],
|
1522
|
+
+ escape(response[fields.action][fields.actionText], settings)
|
1625
1523
|
+ '</a>';
|
1626
1524
|
}
|
1627
1525
|
|