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 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 $select.after($('<div></div>') 59 .addClass('nice-select') 60 .addClass($select.attr('class') || '') 61 .addClass($select.attr('disabled') ? 'disabled' : '') 62 .attr('tabindex', $select.attr('disabled') ? null : '0') 63 .html('<span class="current"></span><ul class="list"></ul>') 64 ); 65 66 var $dropdown = $select.next(); 67 var $options = $select.find('option'); 68 var $selected = $select.find('option:selected'); 69 70 $dropdown.find('.current').html($selected.data('display') || "<img src='" + $selected.attr('data-image') + "' alt='flag-current' width='50'>" + $selected.text()); 71 72 $options.each(function(i) { 73 var $option = $(this); 74 var display = $option.data('display'); 75 76 $dropdown.find('ul').append($('<li></li>') 77 .attr('data-value', $option.val()) 78 .attr('data-image', $option.attr('data-image')) 79 .attr('data-display', (display || null)) 80 .addClass('option' + 81 ($option.is(':selected') ? ' selected' : '') + 82 ($option.is(':disabled') ? ' disabled' : '')) 83 .html("<img src='" + $option.attr('data-image') + "' alt='flag' width='50'>" + $option.text()) 84 ); 85 }); 86 } 87 88 /* Event listeners */ 89 90 // Unbind existing events in case that the plugin has been initialized before 91 $(document).off('.nice_select'); 92 93 // Open/close 94 $(document).on('click.nice_select', '.nice-select', function(event) { 95 var $dropdown = $(this); 96 97 $('.nice-select').not($dropdown).removeClass('open'); 98 $dropdown.toggleClass('open'); 99 100 if ($dropdown.hasClass('open')) { 101 $dropdown.find('.option'); 102 $dropdown.find('.focus').removeClass('focus'); 103 $dropdown.find('.selected').addClass('focus'); 104 } else { 105 $dropdown.focus(); 106 } 107 }); 108 109 // Close when clicking outside 110 $(document).on('click.nice_select', function(event) { 111 if ($(event.target).closest('.nice-select').length === 0) { 112 $('.nice-select').removeClass('open').find('.option'); 113 } 114 }); 115 116 // Option click 117 $(document).on('click.nice_select', '.nice-select .option:not(.disabled)', function(event) { 118 var $option = $(this); 119 var $dropdown = $option.closest('.nice-select'); 120 121 $dropdown.find('.selected').removeClass('selected'); 122 $option.addClass('selected'); 123 124 var text = $option.data('display') || "<img src='" + $option.attr('data-image') + "' width='50'>" + $option.text(); 125 $dropdown.find('.current').html(text); 126 127 $dropdown.prev('select').val($option.data('value')).trigger('change'); 128 });
129 130 // Keyboard events 131 $(document).on('keydown.nice_select', '.nice-select', function(event) { 132 var $dropdown = $(this); 133 var $focused_option = $($dropdown.find('.focus') || $dropdown.find('.list .option.selected')); 134 135 // Space or Enter 136 if (event.keyCode == 32 || event.keyCode == 13) { 137 if ($dropdown.hasClass('open')) { 138 $focused_option.trigger('click'); 139 } else { 140 $dropdown.trigger('click'); 141 } 142 return false; 143 // Down 144 } else if (event.keyCode == 40) { 145 if (!$dropdown.hasClass('open')) { 146 $dropdown.trigger('click'); 147 } else { 148 var $next = $focused_option.nextAll('.option:not(.disabled)').first(); 149 if ($next.length > 0) { 150 $dropdown.find('.focus').removeClass('focus'); 151 $next.addClass('focus'); 152 } 153 } 154 return false; 155 // Up 156 } else if (event.keyCode == 38) { 157 if (!$dropdown.hasClass('open')) { 158 $dropdown.trigger('click'); 159 } else { 160 var $prev = $focused_option.prevAll('.option:not(.disabled)').first(); 161 if ($prev.length > 0) { 162 $dropdown.find('.focus').removeClass('focus'); 163 $prev.addClass('focus'); 164 } 165 } 166 return false; 167 // Esc 168 } else if (event.keyCode == 27) { 169 if ($dropdown.hasClass('open')) { 170 $dropdown.trigger('click'); 171 } 172 // Tab 173 } else if (event.keyCode == 9) { 174 if ($dropdown.hasClass('open')) { 175 return false; 176 } 177 } 178 }); 179 180 // Detect CSS pointer-events support, for IE <= 10. From Modernizr. 181 var style = document.createElement('a').style; 182 style.cssText = 'pointer-events:auto'; 183 if (style.pointerEvents !== 'auto') { 184 $('html').addClass('no-csspointerevents'); 185 } 186 187 return this; 188 189 }; 190 191}(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.