@qhealth-design-system/core 1.16.3 → 1.16.5
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/CHANGELOG.md +4 -0
- package/package.json +1 -10
- package/src/components/_global/css/admin/component.scss +19 -23
- package/src/components/_global/css/tags/component.scss +0 -4
- package/src/components/_global/html/scripts.html +9 -16
- package/src/components/_global/js/select_boxes/global.js +36 -0
- package/src/components/_template/html/component-page.html +25 -31
- package/src/components/a-z_listing/js/global.js +60 -48
- package/src/components/card_no_action/css/component.scss +128 -158
- package/src/components/prefooter/css/component.scss +62 -0
- package/src/components/prefooter/js/manifest.json +9 -0
- package/src/components/promo_panel/js/global.js +19 -18
- package/src/data/current.json +3 -15
- package/src/html/component-a-z_listing.html +13 -41
- package/src/html/component-abstract.html +536 -40
- package/src/html/component-accordion.html +537 -41
- package/src/html/component-banner.html +537 -40
- package/src/html/component-banner_advanced.html +14 -41
- package/src/html/component-banner_basic.html +13 -40
- package/src/html/component-banner_intermediate.html +14 -41
- package/src/html/component-basic_search.html +10 -26
- package/src/html/component-body.html +541 -52
- package/src/html/component-breadcrumbs.html +538 -43
- package/src/html/component-btn.html +471 -69
- package/src/html/component-callout.html +536 -40
- package/src/html/component-card_feature.html +691 -308
- package/src/html/component-card_multi_action.html +651 -217
- package/src/html/component-card_no_action.html +163 -289
- package/src/html/component-card_single_action.html +1251 -324
- package/src/html/component-code.html +13 -40
- package/src/html/component-file_upload.html +13 -41
- package/src/html/component-footer.html +537 -41
- package/src/html/component-forms.html +4 -5
- package/src/html/component-global-elements.html +720 -152
- package/src/html/component-global_alert.html +536 -41
- package/src/html/component-header.html +537 -42
- package/src/html/component-horizontal_rule.html +459 -65
- package/src/html/component-in_page_navigation.html +544 -48
- package/src/html/component-internal_navigation.html +537 -41
- package/src/html/component-left_hand_navigation.html +13 -41
- package/src/html/component-loading_spinner.html +13 -42
- package/src/html/component-main_navigation.html +537 -41
- package/src/html/component-mega_main_navigation.html +537 -42
- package/src/html/component-multi_column.html +536 -40
- package/src/html/component-overflow_menu.html +12 -35
- package/src/html/component-page_alert.html +536 -40
- package/src/html/component-page_footer_info.html +583 -0
- package/src/html/component-pagination.html +459 -65
- package/src/html/component-promo_panel.html +13 -43
- package/src/html/component-tab.html +13 -41
- package/src/html/component-tag_list.html +495 -77
- package/src/html/component-toggle_tip.html +2 -3
- package/src/html/component-tool_tip.html +2 -3
- package/src/html/component-video_player.html +13 -41
- package/src/html/components.html +306 -88
- package/src/html/home.html +1807 -628
- package/src/html/index.html +9 -22
- package/src/html/inner-with-nav.html +551 -137
- package/src/html/inner.html +570 -59
- package/src/index.js +1 -13
- package/src/styles/global.scss +4 -10
- package/src/components/_global/css/slick/component.scss +0 -25
- package/src/components/_global/js/forms/global.js +0 -335
- package/src/components/_global/js/slick/global.js +0 -153
- package/src/components/_global/js/user_location/global.js +0 -116
- package/src/components/data_table/css/component.scss +0 -832
- package/src/components/data_table/html/component.hbs +0 -20
- package/src/components/data_table/js/global.js +0 -387
- package/src/components/data_table/js/manifest.json +0 -112
- package/src/components/updated_date/css/component.scss +0 -24
- package/src/components/updated_date/js/manifest.json +0 -9
- package/src/components/widgets/css/component.scss +0 -130
- package/src/components/widgets/html/component.hbs +0 -8
- package/src/components/widgets/html/default.html +0 -3
- package/src/components/widgets/js/current.json +0 -471
- package/src/components/widgets/js/manifest.json +0 -9
- package/src/components/widgets/js/site.json +0 -350
- package/src/externals/dsComponentLoader.js +0 -410
- package/src/externals/fb-typeahead.bundle.min.js +0 -6
- package/src/externals/funnelback.autocompletion-2.6.0.js +0 -678
- package/src/html/component-data_table.html +0 -85
- package/src/html/component-updated_date.html +0 -88
- package/src/html/component-widgets.html +0 -90
- /package/src/components/{updated_date → prefooter}/html/component.hbs +0 -0
|
@@ -1,678 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Funnelback auto-completion plugin
|
|
3
|
-
* version 2.6.1
|
|
4
|
-
*
|
|
5
|
-
* author: Liliana Nowak
|
|
6
|
-
* Copyright Funnelback, 2015-2019
|
|
7
|
-
*
|
|
8
|
-
* @requires jQuery https://jquery.com@1.10.2
|
|
9
|
-
* @requires Typeahead https://twitter.github.io/typeahead.js@0.11.1
|
|
10
|
-
* @requires Handlebars https://handlebarsjs.com@4.0.5
|
|
11
|
-
*/
|
|
12
|
-
(function($) {
|
|
13
|
-
'use strict';
|
|
14
|
-
|
|
15
|
-
var autocompletion = function(element, options) {
|
|
16
|
-
// Global references
|
|
17
|
-
this.$element = $(element);
|
|
18
|
-
this.options = options;
|
|
19
|
-
|
|
20
|
-
this.init();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Default options
|
|
24
|
-
autocompletion.defaults = {
|
|
25
|
-
// set configuration
|
|
26
|
-
datasets : null, // {set1: {url: ''}, set2: {...}, set3: {...}}
|
|
27
|
-
/*
|
|
28
|
-
defaultCall : { // 'string'|[]|{}; use to trigger auto-completion when input value is empty and length=0
|
|
29
|
-
params : {}, // {}; list of parameters added to request
|
|
30
|
-
url : '' // 'string'; URL to call request
|
|
31
|
-
transform : customFunctionToMapData,// function(set, data); transform function used to map response data
|
|
32
|
-
},
|
|
33
|
-
defaultCall : '', // 'string'; query to replace empty value and call request
|
|
34
|
-
defaultCall : [], // [{value: '', label: ''}, {value: '', label: ''}]; list of hardcoded data to fulfill dropdown menu
|
|
35
|
-
defaultCall : {
|
|
36
|
-
data : [], // []; list of hardcoded data
|
|
37
|
-
transform : function // function(set, data); transform function used to map hardcoded data
|
|
38
|
-
},
|
|
39
|
-
*/
|
|
40
|
-
callback : null, // function(set, suggestions); callback function applied to suggestions before returning them to typeahead plugin
|
|
41
|
-
debounceDelay : 300, // integer; the debounce delay in milliseconds between the time the user stops typing a letter and the time the request is done\
|
|
42
|
-
group : false, // true|false; enable grouping suggestions based on parameter itemGroup
|
|
43
|
-
groupOrder : [], // []; list of group headers used to sort grouped suggestions in that order
|
|
44
|
-
facets : { // {}; list of parameters applied when default search-based auto-completion is enabled
|
|
45
|
-
blacklist : [], // []; list of facet categories names not to displayed
|
|
46
|
-
whitelist : [], // []; list of facet categories names to display
|
|
47
|
-
show : 2, // integer; maximum number of facets values to display per facet category; if not set will display all facet category values
|
|
48
|
-
url : null, // string; the target URL to apply facets parameters to; By default it'll be current location
|
|
49
|
-
},
|
|
50
|
-
itemGroup : 'category', // 'string'; the name of field used to group suggestions and display as group header in dropdown
|
|
51
|
-
itemLabel : 'value', // 'string'; the name of a field to be displayed in input field
|
|
52
|
-
template : { // {notFound: '', pending: '', header: '', footer: '', group: '', suggestion: ''}
|
|
53
|
-
group: function(context) { return $('<div>').html(String(context.label)); },
|
|
54
|
-
suggestion: function(context) { return $('<div>').html(String(context.label)); }
|
|
55
|
-
},
|
|
56
|
-
templateMerge : true, // true|false; to wrap notFound and pending template with header and footer template
|
|
57
|
-
transform : _processSetData, // function(set, suggestion, index); transform function used to map response data
|
|
58
|
-
|
|
59
|
-
// URL settings
|
|
60
|
-
collection : null, // 'string'; the collection name
|
|
61
|
-
dataType : 'json', // 'json'|'jsonp'; the type of data returned back from the server
|
|
62
|
-
alpha : '0.5', // 'string'; adjust the balance between length and relevancy for spelling based suggestions
|
|
63
|
-
format : 'extended', // 'simple|extended'; mapping into 'json' or 'json++'
|
|
64
|
-
params : null, // {}; custom URL parameters
|
|
65
|
-
profile : '_default', // 'string'; the profile name
|
|
66
|
-
program : '/s/suggest.json', // 'string'; program/URL used to generate auto-completion suggestions
|
|
67
|
-
show : 10, // integer; maximum number of suggestions to diplay in dropdown per set
|
|
68
|
-
sort : 0, // integer; set the auto-completion suggestions sort order when program='/s/suggest.json'
|
|
69
|
-
queryKey : 'partial_query', // 'string'; the name of URL parameter to run search query
|
|
70
|
-
queryVal : '%QUERY', // 'string'; the value to be replaced in url with the URI encoded query
|
|
71
|
-
|
|
72
|
-
// display settings
|
|
73
|
-
length : 3, // integer; the minimum character length to trigger query completion
|
|
74
|
-
horizontal : false, // true|false; if true, display datasets in columns, else one below the other
|
|
75
|
-
scrollable : false, // true|false; to limit height of a menu dropdown to maxheight by adding vertical scroll
|
|
76
|
-
|
|
77
|
-
// logs
|
|
78
|
-
logging : true,
|
|
79
|
-
interactionLog : '/s/log',
|
|
80
|
-
|
|
81
|
-
//typeahead settings
|
|
82
|
-
typeahead: {
|
|
83
|
-
classNames : {}, // {}; to override any of default classes, more https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md#class-names
|
|
84
|
-
highlight : true, // true|false; when suggestions are rendered, pattern matches for the current query in text nodes will be wrapped in a strong element with its class set to {{classNames.highlight}}
|
|
85
|
-
hint : false, // true|false; to show a hint in input field,
|
|
86
|
-
events : { // {eventName: function}; events get triggered on the input element during the life-cycle of a typeahead
|
|
87
|
-
select : function(event, suggestion) {
|
|
88
|
-
_selectItem(suggestion, $(event.target));
|
|
89
|
-
},
|
|
90
|
-
afterselect: function(event, suggestion) {
|
|
91
|
-
if (suggestion.extra.action_t == 'E') $(event.target).focus();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/* Public methods */
|
|
98
|
-
|
|
99
|
-
autocompletion.prototype.init = function() {
|
|
100
|
-
this.option(this.options);
|
|
101
|
-
|
|
102
|
-
if (_isEnabled(this.options)) this.initTypeahead();
|
|
103
|
-
else this.destroy();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
autocompletion.prototype.destroy = function () {
|
|
107
|
-
this.destroyTypeahead;
|
|
108
|
-
|
|
109
|
-
this.$element = null;
|
|
110
|
-
this.options = {};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
autocompletion.prototype.option = function(key, val) {
|
|
114
|
-
if (arguments.length === 0) {
|
|
115
|
-
return this.options;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
var that = this, options = $.isObject(key) ? key : {}, parts;
|
|
119
|
-
if ($.isString(key)) {
|
|
120
|
-
if (arguments.length === 1 || !$.isDefinied(val)) {
|
|
121
|
-
return $.dataVals($.extend({}, that.options), key);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
options[key] = val;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
for (var k in options) _setOption(k, options[k]);
|
|
128
|
-
|
|
129
|
-
function _setOption(key, val) {
|
|
130
|
-
if (key === 'datasets') that.options[key] = _mapOptions(that.options, val);
|
|
131
|
-
if (key === 'debug') _debug = val;
|
|
132
|
-
if (key === 'horizontal' && val) {
|
|
133
|
-
that.setTypeaheadClass('menu', 'tt-horizontal');
|
|
134
|
-
|
|
135
|
-
that.options.typeahead.events.render = function(event) {
|
|
136
|
-
_renderSetWidth(that.getTypeaheadMenu(), 'tt-horizontal', 'tt-dataset');
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
if (key === 'scrollable' && val) that.setTypeaheadClass('menu', 'tt-scrollable');
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
autocompletion.prototype.horizontal = function(val) {
|
|
144
|
-
return this.option('horizontal', val);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
autocompletion.prototype.scrollable = function(val) {
|
|
148
|
-
return this.option('scrollable', val);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Typeahead
|
|
152
|
-
autocompletion.prototype.initTypeahead = function() {
|
|
153
|
-
var that = this, data = [];
|
|
154
|
-
|
|
155
|
-
$.each(that.options.datasets, function(name, set) {
|
|
156
|
-
data.push(_getSetData(set, name));
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
that.$element.typeahead({
|
|
160
|
-
minLength : parseInt(that.options.length),
|
|
161
|
-
hint : that.options.typeahead.hint,
|
|
162
|
-
highlight : that.options.typeahead.highlight,
|
|
163
|
-
classNames: that.options.typeahead.classNames
|
|
164
|
-
}, data);
|
|
165
|
-
|
|
166
|
-
if (that.options.typeahead.events) {
|
|
167
|
-
$.each(that.options.typeahead.events, function(eventName, func) {
|
|
168
|
-
that.$element.on('typeahead:' + eventName, func);
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (that.options.horizontal) {
|
|
173
|
-
var data = that.$element.data(), menu = that.getTypeaheadMenu();
|
|
174
|
-
|
|
175
|
-
/*
|
|
176
|
-
* 37 - code for left arrow key
|
|
177
|
-
* 38 - code for up arrow key
|
|
178
|
-
* 39 - code for right arrow key
|
|
179
|
-
* 40 - code for down arrow key
|
|
180
|
-
*/
|
|
181
|
-
data.ttTypeahead._onDownKeyed = function() {
|
|
182
|
-
_navCursorUD(40, menu, that.$element);
|
|
183
|
-
};
|
|
184
|
-
data.ttTypeahead._onUpKeyed = function() {
|
|
185
|
-
_navCursorUD(38, menu, that.$element);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
var cols = menu.children('.tt-dataset');
|
|
189
|
-
if (cols.size() > 1) {
|
|
190
|
-
data.ttTypeahead._onLeftKeyed = function() {
|
|
191
|
-
_navCursorLR(37, cols, that.$element);
|
|
192
|
-
};
|
|
193
|
-
data.ttTypeahead._onRightKeyed = function() {
|
|
194
|
-
_navCursorLR(39, cols, that.$element);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
that.$element.on('keydown', function(event) {
|
|
199
|
-
var code = event.keyCode || event.which;
|
|
200
|
-
if (code == 38 || code == 40) return false;
|
|
201
|
-
if ((code == 37 || code == 39) && $.exist(_navCols.cursor)) return false;
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Log interactions
|
|
206
|
-
if (!that.options.logging) return;
|
|
207
|
-
that.$element.on('typeahead:select', function(event, suggestion) {
|
|
208
|
-
logInteraction(that.options, suggestion, $(event.target), 'select');
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
autocompletion.prototype.destroyTypeahead = function() {
|
|
213
|
-
this.$element.typeahead('destroy');
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
autocompletion.prototype.getTypeaheadMenu = function() {
|
|
217
|
-
return this.$element.siblings('.tt-menu');
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
autocompletion.prototype.setTypeaheadClass = function(name, className) {
|
|
221
|
-
if (!$.exist(this.options.typeahead.classNames[name], true)) this.options.typeahead.classNames[name] = 'tt-' + name; // default class
|
|
222
|
-
this.options.typeahead.classNames[name] += ' ' + className;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/* Private variables */
|
|
226
|
-
var _debug = false,
|
|
227
|
-
_mapKeys = ['collection', 'callback', 'dataType', 'alpha', 'facets', 'transform', 'format', 'group', 'groupOrder', 'itemGroup', 'itemLabel', 'params', 'profile', 'program', 'show', 'sort', 'queryKey', 'queryVal', 'template', 'templateMerge', 'debounceDelay'],
|
|
228
|
-
_navCols = {cursor : null, query : ''};
|
|
229
|
-
|
|
230
|
-
/* Private methods */
|
|
231
|
-
|
|
232
|
-
// Check if there is enough data to trigger auto-completion
|
|
233
|
-
function _isEnabled(options) {
|
|
234
|
-
var bState = false;
|
|
235
|
-
|
|
236
|
-
if (!$.isObject(options.datasets)) return bState;
|
|
237
|
-
|
|
238
|
-
$.each(options.datasets, function(name, set) {
|
|
239
|
-
if ($.exist(set.collection, true)) bState = true;
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
return bState;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Map global options per dataset
|
|
246
|
-
function _mapOptions(options, datasets) {
|
|
247
|
-
var map = {};
|
|
248
|
-
$.each(_mapKeys, function(i, key) { map[key] = options[key] });
|
|
249
|
-
$.each(datasets, function(name, set) { datasets[name] = $.extend(true, {}, map, set) });
|
|
250
|
-
return datasets;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Handle set
|
|
254
|
-
function _getSetData(set, name) {
|
|
255
|
-
var engine = new Bloodhound({
|
|
256
|
-
datumTokenizer : Bloodhound.tokenizers.obj.whitespace('value'),
|
|
257
|
-
queryTokenizer : Bloodhound.tokenizers.whitespace,
|
|
258
|
-
remote : getBloodhoundRemote()
|
|
259
|
-
});
|
|
260
|
-
engine.initialize();
|
|
261
|
-
|
|
262
|
-
return {
|
|
263
|
-
name : name,
|
|
264
|
-
limit : 10000, // hack to display all returned data
|
|
265
|
-
source : source,
|
|
266
|
-
display : displayVal,
|
|
267
|
-
templates : _renderSetTemplate(set)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function displayVal(suggestion) {
|
|
271
|
-
return $.isFunction(set.itemLabel) ? set.itemLabel.call(undefined, suggestion) : $.dataVals(suggestion, set.itemLabel);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function getBloodhoundRemote() {
|
|
275
|
-
var remote = {
|
|
276
|
-
url : set.url ? set.url : _getSetUrl(set),
|
|
277
|
-
filter : function (response) {
|
|
278
|
-
var query = getQuery($(this).get(0).transport.lastReq);
|
|
279
|
-
return _handleSetData(set, $.map(response, function(suggestion, i) { return set.transform(set, suggestion, i, name, query) }));
|
|
280
|
-
},
|
|
281
|
-
rateLimitWait: set.debounceDelay
|
|
282
|
-
};
|
|
283
|
-
if (set.dataType === 'jsonp') {
|
|
284
|
-
remote['prepare'] = function(query, settings) {
|
|
285
|
-
settings.dataType = 'jsonp';
|
|
286
|
-
settings.url = settings.url.replace(set.queryVal, query);
|
|
287
|
-
return settings;
|
|
288
|
-
};
|
|
289
|
-
} else {
|
|
290
|
-
remote['wildcard'] = set.queryVal;
|
|
291
|
-
}
|
|
292
|
-
return remote;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function getQuery(str) {
|
|
296
|
-
if (!$.exist(str, true)) return str;
|
|
297
|
-
str = decodeURIComponent(str);
|
|
298
|
-
return str.substring(str.lastIndexOf(set.queryKey + '=') + (set.queryKey.length + 1), str.lastIndexOf('GET'));
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function displayVal(suggestion) {
|
|
302
|
-
return $.isFunction(set.itemLabel) ? set.itemLabel.call(undefined, suggestion) : $.dataVals(suggestion, set.itemLabel);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function source(query, sync, async) {
|
|
306
|
-
if (query.length < 1 && set.defaultCall) {
|
|
307
|
-
if ($.isString(set.defaultCall)) {
|
|
308
|
-
query = set.defaultCall;
|
|
309
|
-
}
|
|
310
|
-
else if ($.isArray(set.defaultCall)) {
|
|
311
|
-
sync(_handleSetData(set, set.defaultCall));
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
else if ($.exist(set.defaultCall.data)) {
|
|
315
|
-
sync(_handleSetData(set, set.defaultCall.transform(set, set.defaultCall.data)));
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
else if ($.exist(set.defaultCall.url, true)) {
|
|
319
|
-
$.get(set.defaultCall.url, set.defaultCall.params, function(data) {
|
|
320
|
-
async(_handleSetData(set.defaultCall.transform(set, data)));
|
|
321
|
-
return;
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
engine.search(query, sync, async);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// Returned request URL based on provided parameters
|
|
331
|
-
function _getSetUrl(set) {
|
|
332
|
-
var params = {collection: set.collection};
|
|
333
|
-
|
|
334
|
-
if ($.exist(set.format, true)) params['fmt'] = set.format == 'simple' ? 'json' : 'json++';
|
|
335
|
-
if ($.exist(set.alpha, true)) params['alpha'] = set.alpha;
|
|
336
|
-
if ($.exist(set.profile, true)) params['profile'] = set.profile;
|
|
337
|
-
if ($.exist(set.show, true)) params['show'] = set.show;
|
|
338
|
-
if ($.exist(set.sort, true)) params['sort'] = set.sort;
|
|
339
|
-
if ($.isObject(set.param)) params = $.extend(true, {}, params, set.params);
|
|
340
|
-
|
|
341
|
-
return set.program + '?' + $.param(params) + '&' + set.queryKey + '=' + set.queryVal;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
// Group results into categories
|
|
345
|
-
function _groupSetData(set, results) {
|
|
346
|
-
var grouped = {'':[]}, i, len;
|
|
347
|
-
|
|
348
|
-
if ($.exist(set.groupOrder)) {
|
|
349
|
-
for (i = 0, len = set.groupOrder.length; i < len; i++) {
|
|
350
|
-
grouped[set.groupOrder[i]] = [{label: set.groupOrder[i]}];
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
for (i = 0, len = results.length; i < len; i++) {
|
|
355
|
-
if (!$.exist(grouped[results[i][set.itemGroup]])) grouped[results[i][set.itemGroup]] = [{label: results[i][set.itemGroup]}];
|
|
356
|
-
grouped[results[i][set.itemGroup]].push(results[i]);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
results = [];
|
|
360
|
-
$.each(grouped, function(groupName, group) {
|
|
361
|
-
if (group.length > 1) {
|
|
362
|
-
if (!$.exist(groupName, true)) group.splice(0, 1);
|
|
363
|
-
$.merge(results, group);
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
return results;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// Limit number of returned results
|
|
371
|
-
// Trigger grouping them or apply custom callback
|
|
372
|
-
function _handleSetData(set, results) {
|
|
373
|
-
results = results.slice(0, set.show);
|
|
374
|
-
if (set.callback && $.isFunction(set.callback)) results = set.callback.call(undefined, set, results) || [];
|
|
375
|
-
if (!set.group) return results;
|
|
376
|
-
return _groupSetData(set, results);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function _processSetData(set, suggestion, i, name, query) {
|
|
380
|
-
return $.autocompletion.processSetData(set, suggestion, i, name, query);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
// Adjust columns width depends on columns number
|
|
384
|
-
// If column has assigned CSS "width" property with "!important" declaration, this will be respected
|
|
385
|
-
function _renderSetWidth(menu, classWrapper, className) {
|
|
386
|
-
var cols = 0, colsW = 0, styles, parts, menuW = menu.width();
|
|
387
|
-
className = '.' + className;
|
|
388
|
-
classWrapper = '.' + classWrapper;
|
|
389
|
-
|
|
390
|
-
$.each(menu.children(className), function() {
|
|
391
|
-
parts = $(this).attr('class').split(' ');
|
|
392
|
-
styles = $.cssStyle(classWrapper + ' .' + parts[1]) || $.cssStyle(classWrapper + ' .' + parts.join('.'));
|
|
393
|
-
|
|
394
|
-
if (styles.width && styles.width.indexOf('important') && styles.width.indexOf('auto') < 0 && styles.width.indexOf('initial') < 0 && styles.width.indexOf('inherit') < 0) {
|
|
395
|
-
if (styles.width.indexOf('%') > 0) colsW += menuW * parseFloat(styles.width) / 100;
|
|
396
|
-
else colsW += parseFloat(styles.width);
|
|
397
|
-
}
|
|
398
|
-
else if ($.hasContent($(this))) cols++;
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
if (cols) {
|
|
402
|
-
menuW -= colsW + 0.5;
|
|
403
|
-
var minW = parseFloat(menu.children(className).css('min-width')), colW = menuW / cols;
|
|
404
|
-
if (minW <= colW) menu.children(className).css('width', colW + 'px');
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// Pre-compile templates using Handlebars
|
|
409
|
-
function _renderSetTemplate(set) {
|
|
410
|
-
_setSetTemplateHeader(set);
|
|
411
|
-
|
|
412
|
-
if (!set.template || $.isEmptyObject(set.template)) return {};
|
|
413
|
-
|
|
414
|
-
$.each(set.template, function(k, obj) {
|
|
415
|
-
if ($.isObject(obj)) set.template[k] = obj.prop('outerHTML');
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
if (set.templateMerge) {
|
|
419
|
-
templateMerge('notFound');
|
|
420
|
-
templateMerge('pending');
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
$.each(set.template, function(k, obj) {
|
|
424
|
-
if ($.isString(obj)) set.template[k] = Handlebars.compile(obj);
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
return set.template;
|
|
428
|
-
|
|
429
|
-
function templateMerge(temp) {
|
|
430
|
-
if (set.template[temp] && $.isString(set.template[temp])) {
|
|
431
|
-
if (set.template.header && $.isString(set.template.header)) set.template[temp] = set.template.header + set.template[temp];
|
|
432
|
-
if (set.template.footer && $.isString(set.template.footer)) set.template[temp] += set.template.footer;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
// Set default template to display column header if column name is defined
|
|
438
|
-
function _setSetTemplateHeader(set) {
|
|
439
|
-
if (!set.template.header && $.exist(set.name, true)) set.template.header = '<h5 class="tt-category">' + set.name + '</h5>';
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
// Handle selected item based on "action_t" parameter
|
|
443
|
-
function _selectItem(item, target) {
|
|
444
|
-
if ($.exist(item.extra)) {
|
|
445
|
-
switch(item.extra.action_t) {
|
|
446
|
-
case 'C':
|
|
447
|
-
eval(item.extra.action); break;
|
|
448
|
-
case 'U':
|
|
449
|
-
document.location = item.extra.action; break;
|
|
450
|
-
case 'E':
|
|
451
|
-
target.typeahead('val', item.extra.action); break;
|
|
452
|
-
case undefined:
|
|
453
|
-
case '':
|
|
454
|
-
case 'S':
|
|
455
|
-
case 'Q':
|
|
456
|
-
default:
|
|
457
|
-
formSend(item.value); break;
|
|
458
|
-
}
|
|
459
|
-
} else {
|
|
460
|
-
formSend(item.value);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
function formSend(val) { // Submit form on select
|
|
464
|
-
target.val(val);
|
|
465
|
-
target.closest('form').submit();
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
function _getSelectableLabel(item) {
|
|
470
|
-
return $.exist(item.data()) ? item.data().ttSelectableDisplay : item.text();
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/* Handle Typeahead navigation */
|
|
474
|
-
|
|
475
|
-
// Navigate dropdown list left - right (switching between columns)
|
|
476
|
-
function _navCursorLR(code, cols, target) {
|
|
477
|
-
if (!$.exist(_navCols.cursor)) return;
|
|
478
|
-
|
|
479
|
-
var currCol = _navCols.cursor.parent(),
|
|
480
|
-
currColIdx = cols.index(currCol),
|
|
481
|
-
delta = code == 37 ? -1 : 1,
|
|
482
|
-
nextColItems = getNextColItems(currColIdx),
|
|
483
|
-
cursorIdx = $(currCol).children('.tt-selectable').index(_navCols.cursor),
|
|
484
|
-
nextCursor = $.exist(nextColItems[cursorIdx]) ? nextColItems[cursorIdx] : nextColItems[nextColItems.length - 1];
|
|
485
|
-
|
|
486
|
-
$(_navCols.cursor).removeClass('tt-cursor');
|
|
487
|
-
_navCols.cursor = $(nextCursor).addClass('tt-cursor');
|
|
488
|
-
target.data().ttTypeahead.input.setInputValue(_getSelectableLabel(_navCols.cursor));
|
|
489
|
-
|
|
490
|
-
function getNextColItems(currColIdx) {
|
|
491
|
-
var nextColIdx = code == 37
|
|
492
|
-
? $.exist(cols[currColIdx - 1]) ? currColIdx - 1 : cols.length - 1
|
|
493
|
-
: $.exist(cols[currColIdx + 1]) ? currColIdx + 1 : 0,
|
|
494
|
-
nextColItems = $(cols[nextColIdx]).children('.tt-selectable');
|
|
495
|
-
|
|
496
|
-
return $.exist(nextColItems) ? nextColItems : getNextColItems(nextColIdx);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// Navigate dropdown list up - down
|
|
501
|
-
function _navCursorUD(code, menu, target) {
|
|
502
|
-
if (!$.exist(menu.find('.tt-cursor'))) {
|
|
503
|
-
_navCols.cursor = code == 38 ? menu.find('.tt-selectable').last() : menu.find('.tt-selectable').first();
|
|
504
|
-
_navCols.cursor.addClass('tt-cursor');
|
|
505
|
-
_navCols.query = target.val();
|
|
506
|
-
target.data().ttTypeahead.input.setInputValue(_getSelectableLabel(_navCols.cursor));
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
var currCol = _navCols.cursor.parent(),
|
|
511
|
-
currColItems = $(currCol).children('.tt-selectable');
|
|
512
|
-
|
|
513
|
-
if(!$.exist(currColItems)) return;
|
|
514
|
-
|
|
515
|
-
var cursorIdx = currColItems.index(_navCols.cursor), delta = code == 38 ? -1 : 1;
|
|
516
|
-
|
|
517
|
-
$(_navCols.cursor).removeClass('tt-cursor');
|
|
518
|
-
|
|
519
|
-
if (!$.exist(currColItems[cursorIdx + delta])) {
|
|
520
|
-
_navCols.cursor = null;
|
|
521
|
-
target.data().ttTypeahead.input.resetInputValue();
|
|
522
|
-
target.data().ttTypeahead._updateHint();
|
|
523
|
-
}
|
|
524
|
-
else {
|
|
525
|
-
_navCols.cursor = $(currColItems[cursorIdx + delta]).addClass('tt-cursor');
|
|
526
|
-
target.data().ttTypeahead.input.setInputValue(_getSelectableLabel(_navCols.cursor));
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// Debug
|
|
531
|
-
function logDebug(options, input, output, msg) {
|
|
532
|
-
if (!_debug || !window.console) return;
|
|
533
|
-
|
|
534
|
-
console.log(msg);
|
|
535
|
-
console.log('Options: ', options);
|
|
536
|
-
console.log('Input: ', input);
|
|
537
|
-
console.log('Output: ', output);
|
|
538
|
-
console.log('--------');
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
function logInteraction(options, input, target, event) {
|
|
542
|
-
if (!options.logging || !$.exist(options.interactionLog, true)) return;
|
|
543
|
-
if (!input.dataset || !options.datasets[input.dataset]) return;
|
|
544
|
-
|
|
545
|
-
$.ajax({
|
|
546
|
-
dataType: 'jsonp',
|
|
547
|
-
type: 'GET',
|
|
548
|
-
url: getInteractionUrl(options.datasets[input.dataset], input),
|
|
549
|
-
}).fail(function(qXHR, textStatus, errorThrown) {
|
|
550
|
-
logDebug(options, input, qXHR, 'Interaction log error: ' + textStatus + ' ' + errorThrown);
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
function getInteractionUrl(set, suggestion) {
|
|
554
|
-
var params = {
|
|
555
|
-
collection: set.collection,
|
|
556
|
-
type: event,
|
|
557
|
-
partial_query: suggestion.query,
|
|
558
|
-
client_time: new Date().getTime()
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
if ($.exist(set.profile, true)) params['profile'] = set.profile;
|
|
562
|
-
if ($.exist(suggestion.extra)) params = $.extend(true, {}, params, suggestion.extra);
|
|
563
|
-
|
|
564
|
-
return options.interactionLog + '?' + $.param(params);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
// Generate plugin
|
|
569
|
-
function Plugin() {
|
|
570
|
-
var args = [].slice.call(arguments), option = args.shift();
|
|
571
|
-
|
|
572
|
-
return this.each(function () {
|
|
573
|
-
var $this = $(this),
|
|
574
|
-
data = $this.data('flb.autocompletion'),
|
|
575
|
-
options = $.extend(true, {}, autocompletion.defaults, data || {}, $.isObject(option) && option);
|
|
576
|
-
|
|
577
|
-
if (!data && /destroy|hide/.test(option)) return;
|
|
578
|
-
if (!data) $this.data('flb.autocompletion', (data = new autocompletion(this, options)));
|
|
579
|
-
if ($.isString(option) && $.isFunction(data[option])) data[option].apply($this, args);
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
$.fn.autocompletion = Plugin;
|
|
584
|
-
$.fn.autocompletion.Constructor = autocompletion;
|
|
585
|
-
|
|
586
|
-
// List of predefined mapping functions
|
|
587
|
-
$.autocompletion = {
|
|
588
|
-
// Map /s/suggest.json output
|
|
589
|
-
processSetData: function(set, suggestion, i, name, query) {
|
|
590
|
-
var value = suggestion.key, label = suggestion.key;
|
|
591
|
-
if (suggestion.action_t == 'Q') value = suggestion.action;
|
|
592
|
-
if (suggestion.action_t == 'S') value = suggestion.disp;
|
|
593
|
-
if (suggestion.disp_t == 'C') label = eval(suggestion.disp);
|
|
594
|
-
else if (suggestion.disp) label = suggestion.disp;
|
|
595
|
-
|
|
596
|
-
return {
|
|
597
|
-
label : label,
|
|
598
|
-
value : value,
|
|
599
|
-
extra : suggestion,
|
|
600
|
-
category : suggestion.cat ? suggestion.cat : '',
|
|
601
|
-
rank : i + 1,
|
|
602
|
-
dataset : name,
|
|
603
|
-
query : query
|
|
604
|
-
};
|
|
605
|
-
},
|
|
606
|
-
|
|
607
|
-
// Map /s/search.json output
|
|
608
|
-
processSetDataFacets: function(set, suggestion, i, name, query) {
|
|
609
|
-
if (i !== 'response' || !$.exist(suggestion.facets)) return;
|
|
610
|
-
|
|
611
|
-
var suggestions = [], rank = 1;
|
|
612
|
-
for (var i = 0, leni = suggestion.facets.length; i < leni; i++) {
|
|
613
|
-
var facet = suggestion.facets[i];
|
|
614
|
-
|
|
615
|
-
if (!$.exist(facet.allValues)) continue;
|
|
616
|
-
if ($.exist(set.facets.blacklist) && set.facets.blacklist.indexOf(facet.name) > -1) continue;
|
|
617
|
-
if ($.exist(set.facets.whitelist) && set.facets.whitelist.indexOf(facet.name) < 0) continue;
|
|
618
|
-
|
|
619
|
-
for (var j = 0, lenj = facet.allValues.length; j < lenj; j++) {
|
|
620
|
-
if ($.exist(set.facets.show) && j > parseInt(set.facets.show) - 1) break;
|
|
621
|
-
if (!facet.allValues[j].count) continue;
|
|
622
|
-
|
|
623
|
-
suggestions.push({
|
|
624
|
-
label : facet.allValues[j].label,
|
|
625
|
-
value : facet.allValues[j].data,
|
|
626
|
-
extra : {
|
|
627
|
-
action : getUrl(facet.allValues[j]),
|
|
628
|
-
action_t: 'U'
|
|
629
|
-
},
|
|
630
|
-
category: facet.name,
|
|
631
|
-
rank : rank++,
|
|
632
|
-
dataset : name,
|
|
633
|
-
query : query
|
|
634
|
-
});
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
return suggestions;
|
|
639
|
-
|
|
640
|
-
function getUrl(facet) {
|
|
641
|
-
return ($.exist(set.facets.url, true) ? set.facets.url : window.location.origin + window.location.pathname) + facet.toggleUrl;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
// Helpers
|
|
647
|
-
$.exist = function(obj, bString) { if (!$.isDefinied(bString)) bString = false; var obj = bString ? obj : $(obj); return $.isDefinied(obj) && obj != null && ($.isString(obj) ? obj + '' : obj).length > 0; }
|
|
648
|
-
$.hasContent = function(obj) { return obj.html().trim().length ? true : false; }
|
|
649
|
-
$.isDefinied = function(obj) { return typeof(obj) !== 'undefined'; }
|
|
650
|
-
$.isFunction = function(obj) { return typeof(obj) === 'function'; }
|
|
651
|
-
$.isString = function(obj) { return typeof(obj) === 'string'; }
|
|
652
|
-
$.isObject = function(obj) { return typeof(obj) === 'object'; }
|
|
653
|
-
$.dataKeys = function(obj) { return iterateKeys(obj, ''); function iterateKeys(obj, prefix) { return $.map(Object.keys(obj), function(key) { if(obj[key] && $.isObject(obj[key])) return iterateKeys(obj[key], key); else return (prefix ? prefix + '-' + key : key);}); }}
|
|
654
|
-
$.dataVals = function(obj, key) { var parts = key.split('.'), key = parts.shift(); if (parts.length) { for (var i = 0, len = parts.length; i < len; i++) { obj = obj[key] || {}; key = parts[i]; } } return obj[key]; }
|
|
655
|
-
$.cssStyle = function(className) {
|
|
656
|
-
var styleSheets = window.document.styleSheets, styles = {};
|
|
657
|
-
for(var i = 0, leni = styleSheets.length; i < leni; i++){
|
|
658
|
-
if (styleSheets[i].href && styleSheets[i].href.indexOf(window.location.host) < 0) continue;
|
|
659
|
-
|
|
660
|
-
var classes = styleSheets[i].rules || styleSheets[i].cssRules;
|
|
661
|
-
if (!classes) continue;
|
|
662
|
-
|
|
663
|
-
for (var j = 0, lenj = classes.length; j < lenj; j++) {
|
|
664
|
-
if (classes[j].selectorText != className) continue;
|
|
665
|
-
|
|
666
|
-
var properties = classes[j].style.cssText.split(';');
|
|
667
|
-
for (var k = 0, lenk = properties.length; k < lenk; k++) {
|
|
668
|
-
var part = properties[k].split(':');
|
|
669
|
-
if (part.length == 2) styles[part[0].trim()] = part[1].trim();
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
return styles;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
}(jQuery));
|
|
677
|
-
|
|
678
|
-
String.prototype.capitalize = function() { return this.charAt(0).toUpperCase() + this.slice(1); }
|