/*! * jQuery Pretty Dropdowns Plugin v4.13.0 by T. H. Doan (https://thdoan.github.io/pretty-dropdowns/) * * jQuery Pretty Dropdowns by T. H. Doan is licensed under the MIT License. * Read a copy of the license in the LICENSE file or at https://choosealicense.com/licenses/mit/ */ (function($) { $.fn.prettyDropdown = function(oOptions) { // Default options oOptions = $.extend({ classic: true, customClass: 'arrow', width: null, height: 50, hoverIntent: 200, multiDelimiter: '; ', multiVerbosity: 99, selectedMarker: '✓', afterLoad: function(){} }, oOptions); oOptions.selectedMarker = ''; // Validate options if (isNaN(oOptions.width) && !/^\d+%$/.test(oOptions.width)) oOptions.width = null; if (isNaN(oOptions.height)) oOptions.height = 50; else if (oOptions.height<8) oOptions.height = 8; if (isNaN(oOptions.hoverIntent) || oOptions.hoverIntent<0) oOptions.hoverIntent = 200; if (isNaN(oOptions.multiVerbosity)) oOptions.multiVerbosity = 99; // Translatable strings var MULTI_NONE = 'None selected', MULTI_PREFIX = 'Selected: ', MULTI_POSTFIX = ' selected'; // Globals var $current, aKeys = [ '0','1','2','3','4','5','6','7','8','9',,,,,,,, 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' ], nCount, nHoverIndex, nLastIndex, nTimer, nTimestamp, // Initiate pretty drop-downs init = function(elSel) { var $select = $(elSel), nSize = elSel.size, sId = elSel.name || elSel.id || '', sLabelId; // Exit if widget has already been initiated if ($select.data('loaded')) return; // Remove 'size' attribute to it doesn't affect vertical alignment $select.data('size', nSize).removeAttr('size'); // Set element $dropdown.children(':not(.selected)').each(function(nIndex) { $('optgroup, option', $select).eq(nIndex).prop('selected', $(this).children('span.checked').length>0); }); // Update selected values for multi-select menu updateSelected($dropdown); } else { $selected.removeClass('selected').children('span.checked').remove(); $li.addClass('selected').append(oOptions.selectedMarker); if (!oOptions.classic) $dropdown.prepend($li); $dropdown.removeClass('reverse').attr('aria-activedescendant', $li.attr('id')); if ($selected.data('group') && !oOptions.classic) $dropdown.children('.label').filter(function() { return $(this).text()===$selected.data('group'); }).after($selected); // Sync to reflect state changes this.refresh = function(oOptions) { return this.each(function() { var $select = $(this); $select.prevAll('ul').remove(); $select.unwrap().data('loaded', false); this.size = $select.data('size'); init(this); }); }; return this.each(function() { init(this); }); }; }(jQuery));