1(function($) { 2 $.fn.niceSelect = function(method) { 3 if (typeof method == 'string') { 4 if (method == 'update') { this.each(function() { var $select = $(this); var $dropdown = $(this).next('.nice-select'); var open = $dropdown.hasClass('open'); if ($dropdown.length) { $dropdown.remove(); 5 create_nice_select($select); if (open) { $select.next().trigger('click') } } }) } else if (method == 'destroy') { this.each(function() { var $select = $(this); var $dropdown = $(this).next('.nice-select'); if ($dropdown.length) { $dropdown.remove(); 6 $select.css('display', '') } }); if ($('.nice-select').length == 0) { $(document).off('.nice_select') } } else { console.log('Method "' + method + '" does not exist.') } 7 return this 8 } 9 this.hide(); 10 this.each(function() { var $select = $(this); if (!$select.next().hasClass('nice-select')) { create_nice_select($select) } }); 11 12 function create_nice_select($select) { 13 $select.after($('<div></div>').addClass('nice-select').addClass($select.attr('class') || '').addClass($select.attr('disabled') ? 'disabled' : '').addClass($select.attr('multiple') ? 'has-multiple' : '').attr('tabindex', $select.attr('disabled') ? null : '0').html($select.attr('multiple') ? '<span class="multiple-options"></span><div class="nice-select-search-box"><input type="text" class="nice-select-search" placeholder="..."/></div><ul class="list"></ul>' : '<span class="current"></span><div class="nice-select-search-box"><input type="text" class="nice-select-search" placeholder="..."/></div><ul class="list"></ul>')); 14 var $dropdown = $select.next(); 15 var $options = $select.find('option'); 16 if ($select.attr('multiple')) { 17 var $selected = $select.find('option:selected'); 18 var $selected_html = ''; 19 $selected.each(function() { 20 $selected_option = $(this); 21 $selected_text = $selected_option.data('display') || $selected_option.text(); 22 if (!$selected_option.val()) { return } 23 $selected_html += '<span class="current">' + $selected_text + '</span>' 24 }); 25 $select_placeholder = $select.data('js-placeholder') || $select.attr('js-placeholder'); 26 $select_placeholder = !$select_placeholder ? 'Select' : $select_placeholder; 27 console.log($select_placeholder); 28 $selected_html = $selected_html === '' ? $select_placeholder : $selected_html; 29 $dropdown.find('.multiple-options').html($selected_html) 30 } else { var $selected = $select.find('option:selected'); 31 $dropdown.find('.current').html($selected.data('display') || $selected.text()) } 32 $options.each(function(i) { var $option = $(this); var display = $option.data('display'); 33 $dropdown.find('ul').append($('<li></li>').attr('data-value', $option.val()).attr('data-display', (display || null)).addClass('option' + ($option.is(':selected') ? ' selected' : '') + ($option.is(':disabled') ? ' disabled' : '')).html($option.text())) }) 34 } 35 $(document).off('.nice_select'); 36 $(document).on('click.nice_select', '.nice-select', function(event) { var $dropdown = $(this); 37 $('.nice-select').not($dropdown).removeClass('open'); 38 $dropdown.toggleClass('open'); if ($dropdown.hasClass('open')) { $dropdown.find('.option'); 39 $dropdown.find('.nice-select-search').val(''); 40 $dropdown.find('.nice-select-search').focus(); 41 $dropdown.find('.focus').removeClass('focus'); 42 $dropdown.find('.selected').addClass('focus'); 43 $dropdown.find('ul li').show() } else { $dropdown.focus() } }); 44 $(document).on('click', '.nice-select-search-box', function(event) { event.stopPropagation(); return !1 }); 45 $(document).on('keyup.nice-select-search', '.nice-select', function() { 46 var $self = $(this); 47 var $text = $self.find('.nice-select-search').val(); 48 var $options = $self.find('ul li'); 49 if ($text == '') 50 $options.show(); 51 else if ($self.hasClass('open')) { $text = $text.toLowerCase(); var $matchReg = new RegExp($text); if (0 < $options.length) { $options.each(function() { var $this = $(this); var $optionText = $this.text().toLowerCase(); var $matchCheck = $matchReg.test($optionText); 52 $matchCheck ? $this.show() : $this.hide() }) } else { $options.show() } } 53 $self.find('.option'), $self.find('.focus').removeClass('focus'), $self.find('.selected').addClass('focus') 54 }); 55 $(document).on('click.nice_select', function(event) { if ($(event.target).closest('.nice-select').length === 0) { $('.nice-select').removeClass('open').find('.option') } }); 56 $(document).on('click.nice_select', '.nice-select .option:not(.disabled)', function(event) { 57 var $option = $(this); 58 var $dropdown = $option.closest('.nice-select'); 59 if ($dropdown.hasClass('has-multiple')) { 60 console.log('clicked', $option); 61 if ($option.hasClass('selected')) { $option.removeClass('selected') } else { $option.addClass('selected') } 62 $selected_html = ''; 63 $selected_values = []; 64 $dropdown.find('.selected').each(function() { $selected_option = $(this); var text = $selected_option.data('display') || $selected_option.text(); 65 $selected_html += '<span class="current">
65' + text + '</span>'; 66 $selected_values.push($selected_option.data('value')) }); 67 $select_placeholder = $dropdown.prev('select').data('js-placeholder') || $dropdown.prev('select').attr('js-placeholder'); 68 console.log($dropdown.prev('select')); 69 $select_placeholder = !$select_placeholder ? 'Select' : $select_placeholder; 70 $selected_html = $selected_html === '' ? $select_placeholder : $selected_html; 71 $dropdown.find('.multiple-options').html($selected_html); 72 $dropdown.prev('select').val($selected_values).trigger('change') 73 } else { $dropdown.find('.selected').removeClass('selected'); 74 $option.addClass('selected'); var text = $option.data('display') || $option.text(); 75 $dropdown.find('.current').text(text); 76 $dropdown.prev('select').val($option.data('value')).trigger('change') } 77 }); 78 $(document).on('keydown.nice_select', '.nice-select', function(event) { 79 var $dropdown = $(this); 80 var $focused_option = $($dropdown.find('.focus') || $dropdown.find('.list .option.selected')); 81 if (event.keyCode == 32 || event.keyCode == 13) { 82 if ($dropdown.hasClass('open')) { $focused_option.trigger('click') } else { $dropdown.trigger('click') } 83 return !1 84 } else if (event.keyCode == 40) { 85 if (!$dropdown.hasClass('open')) { $dropdown.trigger('click') } else { var $next = $focused_option.nextAll('.option:not(.disabled)').first(); if ($next.length > 0) { $dropdown.find('.focus').removeClass('focus'); 86 $next.addClass('focus') } } 87 return !1 88 } else if (event.keyCode == 38) { 89 if (!$dropdown.hasClass('open')) { $dropdown.trigger('click') } else { var $prev = $focused_option.prevAll('.option:not(.disabled)').first(); if ($prev.length > 0) { $dropdown.find('.focus').removeClass('focus'); 90 $prev.addClass('focus') } } 91 return !1 92 } else if (event.keyCode == 27) { if ($dropdown.hasClass('open')) { $dropdown.trigger('click') } } else if (event.keyCode == 9) { if ($dropdown.hasClass('open')) { return !1 } } 93 }); 94 var style = document.createElement('a').style; 95 style.cssText = 'pointer-events:auto'; 96 if (style.pointerEvents !== 'auto') { $('html').addClass('no-csspointerevents') } 97 return this 98 } 99}(jQuery))
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.