Skip to content

Classes #1411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 36 commits into from
Closed

Classes #1411

wants to merge 36 commits into from

Conversation

arschmitz
Copy link
Member

This addes a new built in option to the widget factory classes which maps structural classes to theme classes. To make this possible it introduces three new documented widget methods _addClass, _removeClass, and _toggleClass.

var current, i;
for ( i = 0; i < classes.length; i++ ) {
current = that.classObject[ classes[ i ] ] ? that.classObject[ classes[ i ] ] : $();
that.classObject[ classes[ i ] ] = current[ add ? "add" : "not" ]( element );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jQuery's add method order elements by DOM position, even when detached. I don't know the exact complexity of that method, but its very slow for more than a handful of elements. Is there a way to avoid using add completely?

If not, what are the odds for current containing more than 1, 10 and 100 elements?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever .not() is used, a new jQuery instance is needed with no stack to avoid memory leaks. See _off() for an example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can avoid the ordering slowness with (untested):

current = $( $.unique( current.get().concat( element.get() ) ) );

This would have decent parity with the required .not() handling too :-P

@jzaefferer
Copy link
Member

Since the empty default classes are gone, can you start a list somewhere that list all the properties for each classes option for each widget? We can then use that for the API docs.

for ( classKey in value ) {
if ( value[ classKey ] !== this.options.classes[ classKey ] ) {
if ( this.classObject[ classKey ] && this.classObject[ classKey ].length > 0 ) {
elements = $.extend( {}, this.classObject[ classKey ] );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this trying to clone a jQuery instance?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraneous space after =.

this.mouseHandled = true;
}
this._addClass( "ui-menu", "ui-widget ui-widget-content" )
._toggleClass( "ui-menu-icons", null, !!this.element.find( ".ui-icon" ).length )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing issue, should probably address it here anyway: This call duplicates parts of refresh(), which is called later in this method. Maybe there is a reason for the duplication, but I guess that its just an oversight. If so, this line should be dropped.

@arschmitz arschmitz closed this in c192d40 Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
arschmitz added a commit that referenced this pull request Mar 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants