Improve extensibility of ui.menu (and thus ui.autocomplete)
jQuery UI Autocomplete was one of the great additions to 1.8. Browsing the nightlies I noticed that it has been decided to make it use the newly developed Menu plugin.
Since I cannot modify the behavior of the menu through $.widget-izing the Autocomplete anymore, I would like to see an option to make Autocomplete use a custom widget (inherited from menu) instead of the menu. 4 lines of code which I would gladly provide.
On the other hand, ui.menu is really hard to extend. Mostly this is because there are many inline jQueries which rely on the plain UL/LI structure. I think it would be much better to decouple the plugin / introduce new private functions that can be reimplemented.
Examples (current and proposed):
- // in various places
- this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
- this.focus( event, this._menuItems( this.activeMenu, ".ui-menu-item" ).first() );
- // in _move
- var next = this.active[ direction + "All" ]( ".ui-menu-item" ).eq( 0 );
- var next = this[ "_" + direction + "Items" ]().eq( 0 ); // with _nextItems and _prevItems as additional functions
- // in _close
- this.active.parent().find("ul").hide().end()...
- this.active.closest(".ui-menu").find(".ui-menu").hide().end()...
- // in _closeAll
- this.element.find("ul").hide().end()
- this.element.find(".ui-menu").hide().end()
The full set of changes can be found on my
GitHub fork. This might have minor performance implications but it was much easier to make the autocomplete feel/look different. I added an example (see attachment) how to create a Last.fm-ish Autocomplete, which the current category example could never reach.