{"version":3,"file":"slx.autocomplete.min.js","sources":["dist/js/slx.autocomplete.js"],"sourcesContent":["/**\r\n * SlxControls 1.2.38 ({@link https://www.selerix.com})\r\n * This is unpublished proprietary source code of Selerix Systems, Inc. The\r\n * copyright notice above is not evidence any actual or intended\r\n * publication of such source code.\r\n * @copyright Copyright 2024 Selerix Systems, Inc. All Rights Reserved.\r\n */\r\n(function (global) {\r\n\t'use strict';\r\n\tvar x = global.SlxControl;\r\n\r\n\t// event keys\r\n\tvar EVENTS = {\r\n\t\tclick: 'click.slx.ac',\r\n\t\tkeydown: 'keydown.slx.ac',\r\n\t\tscroll: 'scroll.slx.ac',\r\n\t\tchange: 'change.slx.ac',\r\n\t\tkeyup: 'keyup.slx.ac',\r\n\t\tfocus: 'focus.slx.ac',\r\n\t\tfocusout: 'focusout.slx.ac',\r\n\t\tresize: 'resize.slx.ac'\r\n\t};\r\n\r\n\t/**\r\n\t * slx.autocomplete\r\n\t * @requires slx.core\r\n\t */\r\n\tx.slx.autocomplete = function () {\r\n\t\tvar that = this;\r\n\t\tx.slx.base.apply(that, arguments);\r\n\r\n\t\t// reference current element\r\n\t\tvar el = that._element;\r\n\t\tif (el === void 0) { return this; }\r\n\t\telse if (el.length === 0) { return el; }\r\n\r\n\t\t// set custom settings from data props and attributes\r\n\t\tthat.id = that.id || el.slxUniqueId();\r\n\t\tthat.selector = '#' + that.id;\r\n\t\tthat.items = that.items || [];\r\n\t\tif (that.highlight === void 0) { that.highlight = el.data('highlight') === false ? false : true; }\r\n\t\tthat.container = x(that.selector + '_container');\r\n\t\tif (!that.container.length) { that.container = el.closest('.input-group'); }\r\n\t\tthat.service = that.service || el.data('service') || null;\r\n\t\tthat.dropDownHeight = that.dropDownHeight || el.data('dropdownheight') || null;\r\n\t\tthat.showArrow = that.showArrow || el.data('showarrow');\r\n\t\tthat.template = that.template || that.container.find('.slx-autocomplete-template').html() || null;\r\n\t\tthat.templateID = that.templateID || el.data('templateid') || null;\r\n\t\tthat.onChange = that.onChange || el.attr('onchange') !== void 0 ? x.eval.call(el[0], el.attr('onchange'), 'event') : void 0;\r\n\t\tthat.placeholder = that.placeholder || el.attr('placeholder') || el.data('placeholder') || '';\r\n\r\n\t\t// check for match requirement\r\n\t\tif (that.requireMatch === void 0) {\r\n\t\t\tthat.requireMatch = el.data('require-match');\r\n\t\t\tif (that.requireMatch === void 0 || that.requireMatch === null) {\r\n\t\t\t\tthat.requireMatch = true;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// check for template\r\n\t\tif (that.templateID !== null) {\r\n\t\t\tvar t = x('#' + that.templateID);\r\n\t\t\tif (!t.hasClass('slx-autocomplete-template')) { t.addClass('slx-autocomplete-template'); }\r\n\t\t\tthat.template = t.html();\r\n\t\t}\r\n\r\n\t\t// local flags\r\n\t\tvar _filtered = null;\r\n\t\tvar _label = x('label[for=\"' + that.id + '\"]');\r\n\r\n\t\t// hidden value field\r\n\t\tvar _hidden = this.container.find(that.selector + '_value');\r\n\t\tif (_hidden.length === 0) { _hidden = x(that.selector + '_value'); }\r\n\r\n\t\t// get and set value\r\n\t\tthat.value = function (v) {\r\n\t\t\tif (v === void 0) {\r\n\t\t\t\t// get value\r\n\t\t\t\treturn _hidden.slxVal();\r\n\t\t\t} else {\r\n\t\t\t\t// set value\r\n\t\t\t\tvar item = that.selectedItem() || v;\r\n\t\t\t\tvar selectedText = _itemText(item);\r\n\t\t\t\tvar ischange = (v !== null && v.toString() !== (_hidden.slxVal() || '')) || (el.slxVal() !== selectedText && selectedText !== '');\r\n\t\t\t\tvar h = _hidden.slxVal(v);\r\n\t\t\t\t// trigger change event\r\n\t\t\t\tif (ischange) {\r\n\t\t\t\t\t_hidden.trigger('change');\r\n\t\t\t\t\tel.trigger('change');\r\n\t\t\t\t} else { that.close(); }\r\n\t\t\t\treturn h;\r\n\t\t\t}\r\n\t\t};\r\n\t\t// get and set text\r\n\t\tthat.text = function (v) {\r\n\t\t\tif (v === void 0) {\r\n\t\t\t\t// get text\r\n\t\t\t\treturn el.slxVal();\r\n\t\t\t} else {\r\n\t\t\t\t// set text\r\n\t\t\t\tif (v === '') { that.value(''); }\r\n\t\t\t\treturn el.slxVal(v);\r\n\t\t\t}\r\n\t\t};\r\n\t\t// get selected index\r\n\t\tthat.selectedIndex = function () {\r\n\t\t\treturn that.items.findIndex(function (i) {\r\n\t\t\t\treturn _itemValue(i).toString() === that.value();\r\n\t\t\t});\r\n\t\t};\r\n\t\t// get selected item\r\n\t\tthat.selectedItem = function () {\r\n\t\t\tvar i = that.selectedIndex();\r\n\t\t\treturn (i >= 0 && that.items.length > i) ? that.items[i] : null;\r\n\t\t};\r\n\t\t// select item by index or value\r\n\t\tthat.select = function (i) {\r\n\t\t\tvar item = i;\r\n\t\t\tif (typeof item === 'number') { item = that.items[i]; }\r\n\t\t\telse if (typeof item === 'string') { that.text(item); }\r\n\t\t\tthat.value(_itemValue(item));\r\n\t\t};\r\n\t\t// get selected index from filtered options\r\n\t\tthat.selectedFilteredIndex = function () {\r\n\t\t\tvar f = _filtered || that.items;\r\n\t\t\t// find index\r\n\t\t\treturn f.findIndex(function (i) {\r\n\t\t\t\treturn _itemValue(i).toString() === that.value();\r\n\t\t\t});\r\n\t\t};\r\n\t\t// get selected item from filtered options\r\n\t\tthat.selectedFilteredItem = function () {\r\n\t\t\tvar f = _filtered || that.items;\r\n\t\t\tvar i = that.selectedFilteredIndex();\r\n\t\t\treturn (i >= 0 && f.length > 0) ? f[i] : null;\r\n\t\t};\r\n\r\n\t\t// prevent default behavior for defined keypress\r\n\t\tvar _preventDefault = function (event) {\r\n\t\t\tvar k = event.keyCode || event.which;\r\n\t\t\t// keypresses to prevent\r\n\t\t\tif ([13, 38, 40].indexOf(k) > -1) {\r\n\t\t\t\tevent.preventDefault();\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t};\r\n\r\n\t\t// check for value property in item\r\n\t\tvar _itemValue = function (item) {\r\n\t\t\t// ensure that the item exists\r\n\t\t\tif (item === null || item === void 0) {\r\n\t\t\t\treturn '';\r\n\t\t\t}\r\n\r\n\t\t\t// get value (regardless of capitalization)\r\n\t\t\treturn typeof item === 'string' ? item : item.Value || item.value || '';\r\n\t\t};\r\n\r\n\t\t// check for text property in item\r\n\t\tvar _itemText = function (item) {\r\n\t\t\t// ensure that the item exists\r\n\t\t\tif (item === null || item === void 0) {\r\n\t\t\t\treturn '';\r\n\t\t\t}\r\n\r\n\t\t\t// get text (regardless of capitalization)\r\n\t\t\treturn typeof item === 'string' ? item : item.Text || item.text || '';\r\n\t\t};\r\n\r\n\t\t// local vars\r\n\t\tvar _options, _blurTimeout = null, _changeTimeout = null, _autoChangeTimeout = null, _isScrolling = false, _selectedVal = null, _isAutoChange = false, _isClickSelect = false;\r\n\t\t// close options window\r\n\t\tthat.close = function (options) {\r\n\t\t\t// close current options window\r\n\t\t\tthat.container.removeClass('open');\r\n\t\t\tvar opt = options || _options;\r\n\t\t\t_filtered = null;\r\n\t\t\t// clean up event listeners and trigger closed event\r\n\t\t\tif (opt !== void 0) { opt.off('click.slx').remove(); }\r\n\t\t\tel.off('click.slx').trigger('closed');\r\n\t\t\tx(document).off('click.slx');\r\n\t\t\tif (_blurTimeout !== null) { clearTimeout(_blurTimeout); }\r\n\t\t\t_options = void 0;\r\n\t\t\tel.closest('form').off(EVENTS.keydown);\r\n\t\t\tx(document).off(EVENTS.keydown);\r\n\t\t};\r\n\r\n\t\t// open options window\r\n\t\tthat.open = function () {\r\n\t\t\t// open options\r\n\t\t\tthat.container.addClass('open');\r\n\t\t\tx('.slx-autocomplete-container:not(#' + that.container.prop('id') + ') .slx-autocomplete-options').empty();\r\n\t\t\t_filtered = _filtered || that.items;\r\n\r\n\t\t\t// close if filtered options is empty\r\n\t\t\tif (_filtered.length === 0) {\r\n\t\t\t\tthat.close();\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t// reset local var and rebuild options window\r\n\t\t\t_options = that.container.find('.slx-autocomplete-options');\r\n\t\t\tif (_options.length > 0) { _options.empty(); }\r\n\t\t\t// drop-down needs tabindex to maintain focus when within a modal\r\n\t\t\telse { that.container.append(_options = x('