/* jQuery selectBox (version 1.0.7) A cosmetic, styleable replacement for SELECT elements. Homepage: http://abeautifulsite.net/blog/2011/01/jquery-selectbox-plugin/ Demo page: http://labs.abeautifulsite.net/projects/js/jquery/selectBox/ Copyright 2011 Cory LaViska for A Beautiful Site, LLC. License: Licensed under both the MIT license and the GNU GPLv2 (same as jQuery: http://jquery.org/license) */ (function($) { $.extend($.fn, { selectBox: function(method, data) { var typeTimer, typeSearch = ''; // // Private methods // var init = function(select, data) { // Disable for iOS devices (their native controls are more suitable for a touch device) if( navigator.userAgent.match(/iPad|iPhone|Android/i) ) return false; // Element must be a select control if( select.tagName.toLowerCase() !== 'select' ) return false; select = $(select); if( select.data('selectBox-control') ) return false; var control = $(''), inline = select.attr('multiple') || parseInt(select.attr('size')) > 1; var settings = data || {}; if( settings.autoWidth === undefined ) settings.autoWidth = true; // Inherit class names, style, and title attributes control .addClass(select.attr('class')) .attr('style', select.attr('style') || '') .attr('title', select.attr('title') || '') .attr('tabindex', parseInt(select.attr('tabindex'))) .css('display', 'inline-block') .bind('focus.selectBox', function() { if( this !== document.activeElement ) $(document.activeElement).blur(); if( control.hasClass('selectBox-active') ) return; control.addClass('selectBox-active'); select.trigger('focus'); }) .bind('blur.selectBox', function() { if( !control.hasClass('selectBox-active') ) return; control.removeClass('selectBox-active'); select.trigger('blur'); }); if( select.attr('disabled') ) control.addClass('selectBox-disabled'); // Generate control if( inline ) { // // Inline controls // var options = getOptions(select, 'inline'); control .append(options) .data('selectBox-options', options) .addClass('selectBox-inline') .addClass('selectBox-menuShowing') .bind('keydown.selectBox', function(event) { handleKeyDown(select, event); }) .bind('keypress.selectBox', function(event) { handleKeyPress(select, event); }) .bind('mousedown.selectBox', function(event) { if( $(event.target).is('A.selectBox-inline') ) event.preventDefault(); if( !control.hasClass('selectBox-focus') ) control.focus(); }) .insertAfter(select); // Auto-height based on size attribute if( !select[0].style.height ) { var size = select.attr('size') ? parseInt(select.attr('size')) : 5; // Draw a dummy control off-screen, measure, and remove it var tmp = control .clone() .removeAttr('id') .css({ position: 'absolute', top: '-9999em' }) .show() .appendTo('body'); tmp.find('.selectBox-options').html('
  • \u00A0
  • '); optionHeight = parseInt(tmp.find('.selectBox-options A:first').html(' ').outerHeight()); tmp.remove(); control.height(optionHeight * size); } disableSelection(control); } else { // // Dropdown controls // var label = $(''), arrow = $(''); label.text( $(select).find('OPTION:selected').text() || '\u00A0' ); var options = getOptions(select, 'dropdown'); options.appendTo('BODY'); control .data('selectBox-options', options) .addClass('selectBox-dropdown') .append(label) .append(arrow) .bind('mousedown.selectBox', function(event) { if( control.hasClass('selectBox-menuShowing') ) { hideMenus(); } else { event.stopPropagation(); // Webkit fix to prevent premature selection of options options.data('selectBox-down-at-x', event.screenX).data('selectBox-down-at-y', event.screenY); showMenu(select); } }) .bind('keydown.selectBox', function(event) { handleKeyDown(select, event); }) .bind('keypress.selectBox', function(event) { handleKeyPress(select, event); }) .insertAfter(select); disableSelection(control); } // Store data for later use and show the control select .addClass('selectBox') .data('selectBox-control', control) .data('selectBox-settings', settings) .hide(); }; var getOptions = function(select, type) { var options; switch( type ) { case 'inline': options = $('