Sha256: 362e50e04800da5e74681e648292d2a394382c3b9edb39cca9603577eda67ee8

Contents?: true

Size: 1.33 KB

Versions: 63

Compression:

Stored size: 1.33 KB

Contents

/**
 * @external jQuery
 */

/**
 * @method
 * @name categorizedAutocomplete
 * @memberof external:jQuery
 */
$.widget('workarea.categorizedAutocomplete', $.ui.autocomplete, {
    _create: function () {
        'use strict';

        this._super();

        this.widget().menu(
            'option', 'items', '> :not(.ui-menu-heading)'
        );
    },

    _renderItem: function ($ul, item) {
        'use strict';

        var itemTemplate = JST['workarea/storefront/templates/ui_menu_item'];

        return $(itemTemplate({ label: item.label, image: item.image })).appendTo($ul);
    },

    _renderMenu: function ($ul, items) {
        'use strict';

        var widget = this,
            categories = _.uniq(_.map(items, 'type')),
            itemsByCategory = _.groupBy(items, 'type'),
            categoryHeaderTemplate = JST['workarea/storefront/templates/ui_menu_heading'],

            renderCategoryItem = function (item) {
                widget._renderItemData($ul, item);
            },

            renderCategory = function (category) {
                $ul.append(categoryHeaderTemplate({
                    categoryName: category
                }));

                _.forEach(
                    itemsByCategory[category], renderCategoryItem
                );
            };

        _.forEach(categories, renderCategory);
    }
});

Version data entries

63 entries across 63 versions & 2 rubygems

Version Path
workarea-storefront-3.4.14 app/assets/javascripts/jquery_ui/storefront/categorized_autocomplete.js
workarea-storefront-3.4.13 app/assets/javascripts/jquery_ui/storefront/categorized_autocomplete.js
workarea-storefront-3.4.12 app/assets/javascripts/jquery_ui/storefront/categorized_autocomplete.js