Sha256: 8e0595aec5982be1cca3522dcc287de65d6b36ff4d3d066a88bf7719de7f5b39

Contents?: true

Size: 1.74 KB

Versions: 34

Compression:

Stored size: 1.74 KB

Contents

/**
 * @namespace WORKAREA.searchFields
 */
WORKAREA.registerModule('searchFields', (function () {
    'use strict';

    var getSource = function (request, response) {
            var endpoint = WORKAREA.routes.storefront.searchesPath();

            $.getJSON(endpoint, { q: request.term }, function (data) {
                response(data.results);
            });
        },

        openSelected = function (event, ui) {
            if (ui.item.type === "Products") {
                WORKAREA.analytics.fireCallback(
                    'productClick',
                    ui.item.analytics
                );
            }

            if (WORKAREA.analytics.domEventsDisabled()) { return; }
            window.location = ui.item.url;
        },

        /**
         * iOS touch devices treat touch events as mouseenter unless there is no
         * change in the UI, like a menu-selected state. By unbinding the
         * mouseenter event we force those devices to treat the touch event as a
         * click. This prevents the user having to tap twice to open a search
         * autocomplete result.
         */
        openOnTouchDevices = function () {
            $('.ui-autocomplete').off('mouseenter');
        },

        getConfig = function () {
            return _.assign({}, WORKAREA.config.searchFieldsAutocomplete, {
                source: getSource,
                select: openSelected,
                open: openOnTouchDevices
            });
        },

        /**
         * @method
         * @name init
         * @memberof WORKAREA.searchFields
         */
        init = function ($scope) {
            $('[data-search-field]', $scope)
            .categorizedAutocomplete(getConfig());
        };

    return {
        init: init
    };
}()));

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-storefront-3.4.45 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.44 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.43 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.42 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.41 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.40 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.39 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.38 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.37 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.36 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.35 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.34 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.33 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.32 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.31 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.30 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.29 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.28 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.27 app/assets/javascripts/workarea/storefront/modules/search_fields.js
workarea-storefront-3.4.26 app/assets/javascripts/workarea/storefront/modules/search_fields.js