All files / web/bundles/pimui/lib/select2 select2-placeholder.js

100% Statements 11/11
50% Branches 1/2
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 321183x                         1183x 1183x       1183x   1183x 6188x 6188x 6188x 6188x   6188x   6188x      
(function($, _) {
    /**
     * Extension of select2 to allow placeholder in the search input field
     * Original solution comes from
     * https://stackoverflow.com/questions/45819164/how-make-select2-placeholder-for-search-input
     *
     * @author    Pierre Allard <pierre.allard@akeneo.com>
     * @author    Tamara Robichet <tamara.noob@akeneo.com>
     * @copyright 2019 Akeneo SAS (http://www.akeneo.com)
     * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
     */
    "use strict";
 
    let Defaults = $.fn.select2.defaults;
    $.extend(Defaults, {
        searchInputPlaceholder: null
    });
 
    const createContainer = window.Select2['class']['single'].prototype.createContainer;
 
    window.Select2['class']['single'].prototype.createContainer = function () {
        const container = createContainer.apply(this, arguments);
        let placeholder = this.opts.searchInputPlaceholder;
        Eif (placeholder === null) {
            placeholder = _.__('pim_common.search');
        }
        container.find('.select2-input').attr('placeholder', placeholder);
 
        return container;
    };
})(jQuery, _);