jQuery(function($){ $.fn.shop_select_to_html = function(option) { var defaults = { menu_down_icon : '' } if (typeof option == 'string') { } else if(typeof option == 'object'){ defaults = $.extend({}, defaults, option); } // Hide native select this.hide(); this.each(function() { var $select = $(this); if (!$select.next().hasClass('shop_select_to_html')) { create_html_select($select); } }); function create_html_select($select) { $select.after($('
') .addClass('shop_select_to_html') .addClass($select.attr('class') || '') .addClass($select.attr('disabled') ? 'disabled' : '') // .attr('tabindex', $select.attr('disabled') ? null : '0') .html('') ); var $dropdown = $select.next(), $options = $select.find('option'), $selected = $select.find('option:selected'), list_next_num = 8, menuhtmls = []; $dropdown.find('.current').html($selected.data('display') || $selected.text()+defaults.menu_down_icon); var $ul_el = $(''), options_length = $options.length; if( options_length > list_next_num ){ $ul_el.addClass("wide"); } $options.each(function(i) { var $option = $(this), display = $option.data('display'), data_url = $(this).attr("data-url"); $ul_el.append($('
  • ') .attr('data-value', $option.val()) .attr('data-display', (display || null)) .addClass('option' + ($option.is(':selected') ? ' selected' : '') + ($option.is(':disabled') ? ' disabled' : '')) .html(''+$option.text()+'') ); if( i && (i % list_next_num === 0) ){ menuhtmls.push($ul_el[0].outerHTML); $ul_el = $('').addClass("wide left-border"); } if( i == ($options.length - 1) ){ menuhtmls.push($ul_el[0].outerHTML); } }); $dropdown.find('.menulist').html(menuhtmls.join('')); } return this; }; });