PageSourceSearch

https://www.elpradopaloalto.com/integration/el-prado/public/vendor/jquery.nice-select.min.js

js elpradopaloalto.com collected 2026-09-28 12:01:59 UTC 6,363 bytes, 194 lines download raw bytes

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