jquery/jquery-ui — pull request #958 by sgharms (2013-04-14 19:42:55+00:00)
Title: Refactor: Create subcomponent "ui.menubarMenuItem"

Per conversation #953 and email with @jzaefferer, I was feeling very frustrated with the very long procedural style of initializing the components in the menubar. In a spike to see if I could make the code's initialization more understandable, I tried out this refactor and it really feels like a much cleaner initialization process.

To wit, https://github.com/sgharms/jquery-ui/pull/new/jquery:menubar...refactor#L1R164 shows a _much_ nicer initialization process ( https://github.com/sgharms/jquery-ui/pull/new/jquery:menubar...refactor#L1R221 ) since we have a class that manages all the setup and event application logic.

It does, however, create a widget called ui.menubarMenuItem. I feel that the gain in having a class which can be pointed at within the context of ui.menubar is well worth constructing the code in this fashion.

However I do not want to create this widget as public, I'd like to keep it as a "private inner widget" to menubar. I'm not sure of the best way to do that. Conceivably I could delete it from the $ object after assigning it to a private variable inside menubar? I'm open to better ways of doing it.

In any case, I believe the code is now _much_ more debuggable and _much_ easier to understand. This setup will also provide a much better interface for mocking and stubbing in the expanded unit test suite requested by http://wiki.jqueryui.com/w/page/38666403/Menubar.

This PR is less "I want this merged in" and more of a "is this way better" but having looked at this code this morning for a few hours, I despair at ever going back to what's in jquery-ui/menubar.