/* * styleSelect - apply style to a select box * (http://www.8stream.com) * http://www.8stream.com/scripts/styleSelect/ * Copyright (c) 2009 Siim Sindonen, 8STREAM * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * Requires jQuery version: >= 1.3.2 * $Version: 1.2.3 | 22.09.2009 *Options ------------------------------------------------------------------------------------------------------------- |Name |Options |Type |Default | |---------------|----------------------------------------------------------------|---------------|----------| |optionsTop |Options list distance from top |string |26px | |---------------|----------------------------------------------------------------|---------------|----------| |optionsLeft |Options list distance from left |string |0px | |---------------|----------------------------------------------------------------|---------------|----------| |optionsWidth |Options list width (0 - same as main selector) |string |0 | |---------------|----------------------------------------------------------------|---------------|----------| |styleClass |Select style class |string |selectMenu| |---------------|----------------------------------------------------------------|---------------|----------| |speed |Options list opening speed ('slow','medium','fast',milliseconds)|string, number |0 | |---------------|----------------------------------------------------------------|---------------|----------| |selectTrigger |Event to trigger on original select ('change','click') |string |change | ------------------------------------------------------------------------------------------------------------- */ (function($){ $.fn.styleSelect = function(options){ var tabindex = 1; var opts = $.extend({}, $.fn.styleSelect.defaults , options); //set tabindex $('input,select,textarea,button').each(function() { var input = $(this); if (!input.attr('tabindex')){ input.attr('tabindex', tabindex); tabindex++; } }); return this.each(function(){ mainSelect = $(this); var mainId = mainSelect.attr('name'); var styledTabIndex = mainSelect.attr('tabindex'); var date = new Date; var selectId = 'selectbox_'+mainId+date.getTime(); //Hidde select box mainSelect.hide(); //Main container var mainContainer = $('
').css({position : 'relative'}) .addClass(opts.styleClass) .attr('id', selectId) .insertBefore(mainSelect); //Options container var subContainer = $('').css({'position' : 'absolute', 'z-index' : '100'-styledTabIndex, 'top' : opts.optionsTop, 'left' : opts.optionsLeft}) .appendTo($(mainContainer)) .hide(); //Generate options list var optionsList = ""; mainSelect.find('option').each(function(){ optionsList += '
  • ').text(selectedName.text()) .attr('id', selectedName.parent().attr('id')) .addClass('passiveSelect') .appendTo($(this)); if (mainWidth === 0){ $(this).css({'width' : elementList.width()}); } }); $('.'+mainClass+' span').each(function(){ if ($(this).attr('id')){ $(this).removeClass(); $(this).addClass('activeSelect'); } }); } $.fn.styleSelect.defaults = { optionsTop: '26px', optionsLeft: '0px', optionsWidth: 0, styleClass: 'selectMenu', speed: 0, selectTrigger: 'change' }; })(jQuery);