Improve extensibility of ui.menu (and thus ui.autocomplete)

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):

  1. // in various places
  2. this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
  3. this.focus( event, this._menuItems( this.activeMenu, ".ui-menu-item" ).first() );

  4. // in _move
  5. var next = this.active[ direction + "All" ]( ".ui-menu-item" ).eq( 0 );
  6. var next = this[ "_" + direction + "Items" ]().eq( 0 ); // with _nextItems and _prevItems as additional functions

  7. // in _close
  8. this.active.parent().find("ul").hide().end()...
  9. this.active.closest(".ui-menu").find(".ui-menu").hide().end()...

  10. // in _closeAll
  11. this.element.find("ul").hide().end()
  12. 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.