/* * jQuery UI selectmenu dev version * * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * http://docs.jquery.com/UI * https://github.com/fnagel/jquery-ui/wiki/Selectmenu */ (function($) { $.widget("ui.selectmenu", { getter: "value", version: "1.8", eventPrefix: "selectmenu", options: { transferClasses: true, typeAhead: "sequential", style: 'dropdown', positionOptions: { my: "left top", at: "left bottom", offset: null }, width: null, menuWidth: null, handleWidth: 26, maxHeight: null, icons: null, format: null, bgImage: function() {}, wrapperElement: "
" }, _create: function() { var self = this, o = this.options; // set a default id value, generate a new random one if not set by developer var selectmenuId = this.element.attr( 'id' ) || 'ui-selectmenu-' + Math.random().toString( 16 ).slice( 2, 10 ); // quick array of button and menu id's this.ids = [ selectmenuId + '-button', selectmenuId + '-menu' ]; // define safe mouseup for future toggling this._safemouseup = true; // create menu button wrapper this.newelement = $( '', { 'class': this.widgetBaseClass + ' ui-widget ui-state-default ui-corner-all', 'id' : this.ids[ 0 ], 'role': 'button', 'href': '#nogo', 'tabindex': this.element.attr( 'disabled' ) ? 1 : 0, 'aria-haspopup': true, 'aria-owns': this.ids[ 1 ] }); this.newelementWrap = $( o.wrapperElement ) .append( this.newelement ) .insertAfter( this.element ); // transfer tabindex var tabindex = this.element.attr( 'tabindex' ); if ( tabindex ) { this.newelement.attr( 'tabindex', tabindex ); } // save reference to select in data for ease in calling methods this.newelement.data( 'selectelement', this.element ); // menu icon this.selectmenuIcon = $( '' ) .prependTo( this.newelement ); // append status span to button this.newelement.prepend( '' ); // make associated form label trigger focus $( 'label[for="' + selectmenuId + '"]' ) .attr( 'for', this.ids[0] ) .bind( 'click.selectmenu', function() { self.newelement[0].focus(); return false; }); // click toggle for menu visibility this.newelement .bind('mousedown.selectmenu', function(event) { self._toggle(event, true); // make sure a click won't open/close instantly if (o.style == "popup") { self._safemouseup = false; setTimeout(function() { self._safemouseup = true; }, 300); } return false; }) .bind('click.selectmenu', function() { return false; }) .bind("keydown.selectmenu", function(event) { var ret = false; switch (event.keyCode) { case $.ui.keyCode.ENTER: ret = true; break; case $.ui.keyCode.SPACE: self._toggle(event); break; case $.ui.keyCode.UP: if (event.altKey) { self.open(event); } else { self._moveSelection(-1); } break; case $.ui.keyCode.DOWN: if (event.altKey) { self.open(event); } else { self._moveSelection(1); } break; case $.ui.keyCode.LEFT: self._moveSelection(-1); break; case $.ui.keyCode.RIGHT: self._moveSelection(1); break; case $.ui.keyCode.TAB: ret = true; break; default: ret = true; } return ret; }) .bind('keypress.selectmenu', function(event) { self._typeAhead(event.which, 'mouseup'); return true; }) .bind('mouseover.selectmenu focus.selectmenu', function() { if (!o.disabled) { $(this).addClass(self.widgetBaseClass + '-focus ui-state-hover'); } }) .bind('mouseout.selectmenu blur.selectmenu', function() { if (!o.disabled) { $(this).removeClass(self.widgetBaseClass + '-focus ui-state-hover'); } }); // document click closes menu $(document).bind("mousedown.selectmenu", function(event) { self.close(event); }); // change event on original selectmenu this.element .bind("click.selectmenu", function() { self._refreshValue(); }) // FIXME: newelement can be null under unclear circumstances in IE8 // TODO not sure if this is still a problem (fnagel 20.03.11) .bind("focus.selectmenu", function() { if (self.newelement) { self.newelement[0].focus(); } }); // set width when not set via options if (!o.width) { o.width = this.element.outerWidth(); } // set menu button width this.newelement.width(o.width); // hide original selectmenu element this.element.hide(); // create menu portion, append to body this.list = $( '