$(document).ready(function () { CustomSelectInitializer.init(); }); class CustomSelectOptionModel { public id: string; public value: string; } class CustomSelectInitializer { public static init() { $(".custom-select select").each((index, item) => { CustomSelectInitializer.InitCustomSelect(item, false); }); } public static InitCustomSelect($select: HTMLElement, refresh: boolean) { // Cache the number of options let $this = $($select); //Защита от повторной инициализации if (!refresh && $this.parent().find(".styledSelect").length > 0) { return; } //Простановка значения дополнительно, если есть касмтомный список let selectedVal = $this.attr("selected-val"); if (selectedVal) { let select = $((Array as any).from(($this[0] as any).options).filter(x => x.value === selectedVal.toUpperCase())[0]); select.attr('selected', 'selected'); select.prop('selected', 'selected'); } // Cache the styled div var $styledSelect = $this.next('div.styledSelect'); var $list = $styledSelect.next('.options'); if (!refresh) { // Hides the select element $this.addClass('s-hidden'); // Wrap the select element in a div $this.wrap('
'); // Insert a styled div to sit over the top of the hidden select element $this.after('
'); // Cache the styled div $styledSelect = $this.next('div.styledSelect'); // Insert an unordered list after the styled div and also cache the list $list = $('