/* * jQuery selectBox2 - A cosmetic, styleable replacement for SELECT elements (selectBox + jQuery UI Slider)! * * */ if(jQuery) (function($) { $.extend($.fn, { selectBox2: function(method, data) { var typeTimer, typeSearch = '', isMac = navigator.platform.match(/mac/i); // // Private methods // var init = function(select, data) { var options; // Disable for iOS devices (their native controls are more suitable for a touch device) if( navigator.userAgent.match(/iPad|iPhone|Android|IEMobile|BlackBerry/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 || {}; control .width(select.outerWidth()) .addClass(select.attr('class')) .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( !$(window).data('selectBox-bindings') ) { $(window) .data('selectBox-bindings', true) .bind('scroll.selectBox', hideMenus) .bind('resize.selectBox', hideMenus); } if( select.attr('disabled') ) control.addClass('selectBox-disabled'); // Focus on control when label is clicked select.bind('click.selectBox', function(event) { control.focus(); event.preventDefault(); }); // Generate control if( inline ) { // // Inline controls // options = getOptions(select, 'inline'); control .append(options) .data('selectBox-options', options) .addClass('selectBox-inline 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 = $(''); // Update label label .attr('class', getLabelClass(select)) .text(getLabelText(select)); 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); // Set label width var labelWidth = control.width() - arrow.outerWidth() - parseInt(label.css('paddingLeft')) - parseInt(label.css('paddingLeft')); label.width(labelWidth); 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 = $('