1/* jQuery Nice Select - v1.1.0 2 https://github.com/hernansartorio/jquery-nice-select 3 Made by Hernán Sartorio */ 4 5(function($) { 6 var URL_ROOT = "https://albstadt.de/"; 7 $.fn.niceSelect = function(method) { 8 9 // Methods 10 if (typeof method == 'string') { 11 if (method == 'update') { 12 this.each(function() { 13 var $select = $(this); 14 var $dropdown = $(this).next('.nice-select'); 15 var open = $dropdown.hasClass('open'); 16 17 if ($dropdown.length) { 18 $dropdown.remove(); 19 create_nice_select($select); 20 21 if (open) { 22 $select.next().trigger('click'); 23 } 24 } 25 }); 26 } else if (method == 'destroy') { 27 this.each(function() { 28 var $select = $(this); 29 var $dropdown = $(this).next('.nice-select'); 30 31 if ($dropdown.length) { 32 $dropdown.remove(); 33 $select.css('display', ''); 34 } 35 }); 36 if ($('.nice-select').length == 0) { 37 $(document).off('.nice_select'); 38 } 39 } else { 40 console.log('Method "' + method + '" does not exist.') 41 } 42 return this; 43 } 44 45 // Hide native select 46 this.hide(); 47 48 // Create custom markup 49 this.each(function() { 50 var $select = $(this); 51 52 if (!$select.next().hasClass('nice-select')) { 53 create_nice_select($select); 54 } 55 }); 56 57 function create_nice_select($select) { 58 59 $select.after($('<div></div>') 60 .addClass('nice-select') 61 .addClass($select.attr('class') || '') 62 .addClass($select.attr('disabled') ? 'disabled' : '') 63 .attr('tabindex', $select.attr('disabled') ? null : '0') 64 .html('<span class="current" data-col="light"></span><ul class="list"></ul>') 65 ); 66 67 var $dropdown = $select.next(); 68 var $options = $select.find('option'); 69 var $selected = $select.find('option:selected'); 70 71 $dropdown.find('.current').html($selected.data('display') || $selected.text()); 72 73 $options.each(function(i) { 74 var $option = $(this); 75 var display = $option.data('display'); 76 if ($select.hasClass('onlinedienste')){ 77 if($option.val() == 0){ 78 $dropdown.find('ul').append($('<li></li>') 79 .attr('data-display', (display || null)) 80 .addClass('option' + 81 ($option.is(':selected') ? ' selected rel-current="rel_cur" ' : '') + 82 ($option.is(':disabled') ? ' disabled' : '')) 83 .html('<a class="bs_option_a" target="_blank" href="/albstadt-onlinedienste"><div>' + $option.text() + '</div></a>') 84 ); 85 } else { 86 $dropdown.find('ul').append($('<li></li>') 87 .attr('data-value', $option.val()) 88 .attr('data-display', (display || null)) 89 .addClass('option' + 90 ($option.is(':selected') ? ' selected' : '') + 91 ($option.is(':disabled') ? ' disabled' : '')) 92 .html('<a class="bs_option_a" target="_blank" href="' + $option.val() + '"><div>' + $option.text() + '</div></a>') 93 ); 94 } 95 96 } 97 else if ($select.hasClass('lebenssituationen')){ 98 if($option.val() == 0){ 99 $dropdown.find('ul').append($('<li></li>') 100 .attr('data-display', (display || null)) 101 .addClass('option' + 102 ($option.is(':selected') ? ' selected' : '') + 103 ($option.is(':disabled') ? ' disabled' : '')) 104 .html('<a class="bs_option_a" href="/lebenssituationen/"><div>' + $option.text() + '</div></a>') 105 ); 106 } else{ 107 $dropdown.find('ul').append($('<li></li>') 108 .attr('data-value', $option.val()) 109 .attr('data-display', (display || null)) 110 .addClass('option' + 111 ($option.is(':selected') ? ' selected' : '') + 112 ($option.is(':disabled') ? ' disabled' : '')) 113 .html('<a class="bs_option_a" href="/' + $option.val() + '"><div>' + $option.text() + '</div></a>') 114 ); 115 } 116 117 } 118 else if ($select.hasClass('leistungen')){ 119 120 if($option.val() == 0){ 121 $dropdown.find('ul').append($('<li></li>') 122 .attr('data-display', (display || null)) 123 .addClass('option' + 124 ($option.is(':selected') ? ' selected' : '') + 125 ($option.is(':disabled') ? ' disabled' : '')) 126 .html('<a class="bs_option_a" href="' + URL_ROOT + 'leistungen-a-z/"><div>' + $option.text() + '</div></a>') 127 ); 128 } 129 else{ 130 $dropdown.find('ul').append($('<li></li>') 131 .attr('data-value', $option.val()) 132 .attr('data-display', (display || null)) 133 .addClass('option' + 134 ($option.is(':selected') ? ' selected' : '') + 135 ($option.is(':disabled') ? ' disabled' : '')) 136 .html('<a class="bs_option_a" href="' + URL_ROOT + 'leistungen-a-z/&id=' + $option.val() + '"><div>' + $option.text() + '</div></a>') 137 ); 138 } 139 } 140 else{ 141 $dropdown.find('ul').append($('<li></li>') 142 .attr('data-value', $option.val()) 143 .attr('data-val', "def") 144 .attr('data-display', (display || null)) 145 .addClass('option' + 146 ($option.is(':selected') ? ' selected' : '') + 147 ($option.is(':disabled') ? ' disabled' : '')) 148 .html($option.text()) 149 ); 150 } 151 }); 152 console.log($select.className); 153 } 154 155 /* Event listeners */ 156 157 // Unbind existing events in case that the plugin has been initialized before 158 $(document).off('.nice_select'); 159 160 // Open/close 161 $(document).on('click.nice_select', '.nice-select', function(event) { 162 var $dropdown = $(this); 163 164 $('.nice-select').not($dropdown).removeClass('open'); 165 $dropdown.toggleClass('open'); 166 167 if ($dropdown.hasClass('open')) { 168 $dropdown.find('.option'); 169 $dropdown.find('.focus').removeClass('focus'); 170 $dropdown.find('.selected').addClass('focus'); 171 } else { 172 $dropdown.focus(); 173 } 174 }); 175 176 // Close when clicking outside 177 $(document).on('click.nice_select', function(event) { 178 if ($(event.target).closest('.nice-select').length === 0) { 179 $('.nice-select').removeClass('open').find('.option'); 180 } 181 }); 182 183 // Option click 184 $(document).on('click.nice_select', '.nice-select .option:not(.disabled)', function(event) { 185 var $option = $(this); 186 var $dropdown = $option.closest('.nice-select'); 187 188 $dropdown.find('.selected').removeClass('selected'); 189 $option.addClass('selected'); 190 191 var text = $option.data('display') || $option.text(); 192 $dropdown.find('.current').attr("data-col", "black").text(text); 193 194 $dropdown.prev('select').val($option.data('value')).trigger('change'); 195 }); 196 197 // Keyboard events 198 $(document).on('keydown.nice_select', '.nice-select', function(event) { 199 var $dropdown = $(this);
200 var $focused_option = $($dropdown.find('.focus') || $dropdown.find('.list .option.selected')); 201 202 // Space or Enter 203 if (event.keyCode == 32 || event.keyCode == 13) { 204 if ($dropdown.hasClass('open')) { 205 $focused_option.trigger('click'); 206 } else { 207 $dropdown.trigger('click'); 208 } 209 return false; 210 // Down 211 } else if (event.keyCode == 40) { 212 if (!$dropdown.hasClass('open')) { 213 $dropdown.trigger('click'); 214 } else { 215 var $next = $focused_option.nextAll('.option:not(.disabled)').first(); 216 if ($next.length > 0) { 217 $dropdown.find('.focus').removeClass('focus'); 218 $next.addClass('focus'); 219 } 220 } 221 return false; 222 // Up 223 } else if (event.keyCode == 38) { 224 if (!$dropdown.hasClass('open')) { 225 $dropdown.trigger('click'); 226 } else { 227 var $prev = $focused_option.prevAll('.option:not(.disabled)').first(); 228 if ($prev.length > 0) { 229 $dropdown.find('.focus').removeClass('focus'); 230 $prev.addClass('focus'); 231 } 232 } 233 return false; 234 // Esc 235 } else if (event.keyCode == 27) { 236 if ($dropdown.hasClass('open')) { 237 $dropdown.trigger('click'); 238 } 239 // Tab 240 } else if (event.keyCode == 9) { 241 if ($dropdown.hasClass('open')) { 242 return false; 243 } 244 } 245 }); 246 247 // Detect CSS pointer-events support, for IE <= 10. From Modernizr. 248 var style = document.createElement('a').style; 249 style.cssText = 'pointer-events:auto'; 250 if (style.pointerEvents !== 'auto') { 251 $('html').addClass('no-csspointerevents'); 252 } 253 254 return this; 255 256 }; 257 258}(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.