dist/toolkit.js
function() {
        var select = this.element,
            options = this.options,
            buildOption = this._buildOption.bind(this),
            renderTemplate = this.render.bind(this),
            dropdown = renderTemplate(options.optionsTemplate).attr('role', 'listbox').aria('multiselectable', this.multiple),
            list = $('<ul/>'),
            index = 0,
            self = this;

        // Must be set for `_buildOption()`
        this.dropdown = dropdown;

        select.children().each(function() {
            var optgroup = $(this);

            if (optgroup.prop('tagName').toLowerCase() === 'optgroup') {
                if (index === 0) {
                    options.hideFirst = false;
                }

                list.append(
                    renderTemplate(options.headingTemplate).text(optgroup.attr('label'))
                );

                optgroup.children().each(function() {
                    var option = $(this);

                    if (optgroup.prop('disabled')) {
                        option.prop('disabled', true);
                    }

                    if (option.prop('selected')) {
                        self.index = index;
                    }

                    list.append( buildOption(option, index) );
                    index++;
                });
            } else {
                if (optgroup.prop('selected')) {
                    self.index = index;
                }

                list.append( buildOption(optgroup, index) );
                index++;
            }
        });

        if (options.hideSelected && !options.multiple) {
            dropdown.addClass('hide-selected');
        }

        if (options.hideFirst) {
            dropdown.addClass('hide-first');
        }

        if (this.multiple) {
            dropdown.addClass('is-multiple');
        }

        this.wrapper.append(dropdown.append(list));

        return dropdown;
    }
function() {
        var select = this.element,
            options = this.options,
            buildOption = this._buildOption.bind(this),
            renderTemplate = this.render.bind(this),
            dropdown = renderTemplate(options.optionsTemplate).attr('role', 'listbox').aria('multiselectable', this.multiple),
            list = $('<ul/>'),
            index = 0,
            self = this;

        // Must be set for `_buildOption()`
        this.dropdown = dropdown;

        select.children().each(function() {
            var optgroup = $(this);

            if (optgroup.prop('tagName').toLowerCase() === 'optgroup') {
                if (index === 0) {
                    options.hideFirst = false;
                }

                list.append(
                    renderTemplate(options.headingTemplate).text(optgroup.attr('label'))
                );

                optgroup.children().each(function() {
                    var option = $(this);

                    if (optgroup.prop('disabled')) {
                        option.prop('disabled', true);
                    }

                    if (option.prop('selected')) {
                        self.index = index;
                    }

                    list.append( buildOption(option, index) );
                    index++;
                });
            } else {
                if (optgroup.prop('selected')) {
                    self.index = index;
                }

                list.append( buildOption(optgroup, index) );
                index++;
            }
        });

        if (options.hideSelected && !options.multiple) {
            dropdown.addClass('hide-selected');
        }

        if (options.hideFirst) {
            dropdown.addClass('hide-first');
        }

        if (this.multiple) {
            dropdown.addClass('is-multiple');
        }

        this.wrapper.append(dropdown.append(list));

        return dropdown;
    }
function ( ) { var select = this . element , options = this . options , buildOption = this . _buildOption . bind ( this ) , renderTemplate = this . render . bind ( this ) , dropdown = renderTemplate ( options . optionsTemplate ) . attr ( 'role' , 'listbox' ) . aria ( 'multiselectable' , this . multiple ) , list = $ ( '<ul/>' ) , index = 0 , self = this ; // Must be set for `_buildOption()` this . dropdown = dropdown ; select . children ( ) . each ( function ( ) { var optgroup = $ ( this ) ; if ( optgroup . prop ( 'tagName' ) . toLowerCase ( ) === 'optgroup' ) { if ( index === 0 ) { options . hideFirst = false ; } list . append ( renderTemplate ( options . headingTemplate ) . text ( optgroup . attr ( 'label' ) ) ) ; optgroup . children ( ) . each ( function ( ) { var option = $ ( this ) ; if ( optgroup . prop ( 'disabled' ) ) { option . prop ( 'disabled' , true ) ; } if ( option . prop ( 'selected' ) ) { self . index = index ; } list . append ( buildOption ( option , index ) ) ; index ++ ; } ) ; } else { if ( optgroup . prop ( 'selected' ) ) { self . index = index ; } list . append ( buildOption ( optgroup , index ) ) ; index ++ ; } } ) ; if ( options . hideSelected && ! options . multiple ) { dropdown . addClass ( 'hide-selected' ) ; } if ( options . hideFirst ) { dropdown . addClass ( 'hide-first' ) ; } if ( this . multiple ) { dropdown . addClass ( 'is-multiple' ) ; } this . wrapper . append ( dropdown . append ( list ) ) ; return dropdown ; }
Build the custom dropdown to hold a list of option items.

@returns {jQuery}
Build the custom dropdown to hold a list of option items .