Bug Tracker

Opened 11 years ago

Closed 9 years ago

#4630 closed enhancement (wontfix)

Add radioClass method

Reported by: brandon Owned by: brandon
Priority: low Milestone: 1.next
Component: attributes Version: 1.3.2
Keywords: needsreview Cc:
Blocked by: Blocking:

Description

radioClass method (inspired by Ext Core) adds a class to one element and removes it from its siblings. Attached is a patch to include radioClass into jQuery. This creates a dependency of the selectors module to the attributes module which didn't exist before. I didn't use the .siblings() method so as not to create another dependency on traversing.

Attachments (1)

radioClass.diff (1.8 KB) - added by brandon 11 years ago.
radioClass method

Download all attachments as: .zip

Change History (15)

Changed 11 years ago by brandon

Attachment: radioClass.diff added

radioClass method

comment:1 Changed 11 years ago by bganicky

Definitely good addition. I need this too often not to appreciate such a method.

+1

comment:2 Changed 11 years ago by memiux

Yeap, I agree too

comment:3 Changed 11 years ago by scrufus

+1

I would use this a lot.

comment:4 Changed 11 years ago by paul.irish

Would these two then be equivalent?

$(foo).radioClass('on');
$(foo).addClass('on').siblings().removeClass('on');

Even though Ext may go with radioClass, it doesn't specifically target radio's which can appear misleading; siblingClass() would be more logical to me.

But on the whole, it doesn't seem to be enough of an improvement to deserve it's own syntactic sugar. This would also be the only attribute manipulation method that assumes a specific DOM relationship. A bit odd to me.

-1

comment:5 Changed 11 years ago by ajpiano

not so sure this needs to be in core (though it seem some people like it). the name is certainly misleading, and i think that if something like this is going to go in, it way as well work natively to apply this behaviour on checkboxes, which at present wouldn't really be manipulated by this enhancement.

comment:6 Changed 11 years ago by bbonifield

I'm in agreement with paul.irish in both the naming and usefulness. The method would only be useful when dealing with exclusive classes in sibling relationships.

If you wanted to add something like this, I'd would say it is more valuable to have some flexibility.

Assuming you had

<div id="parent">
  <h3>heading</h3>
  <ul>
    <li class="active">1</li>
    <li>2</li>
  </ul>
  <h3>heading</h3>
  <ul>
    <li>1</li>
    <li>2</li>
  </ul>
  <h3>heading</h3>
  <ul>
    <li>1</li>
    <li>2</li>
  </ul>
</div>

Something like...

$("#parent ul:last li:first").exclusiveClass('active', $("#parent"));

Where the second argument would be the scope that you should maintain exclusiveness within (perhaps making it so that the default scope is within the direct parent).

-1

comment:7 Changed 11 years ago by cowboy

I agree with paul_irish completely.

comment:8 Changed 11 years ago by redsquare

I agree with my chums from #jquery.

I'd rather see these type of extension functions go into an 'optional' lib which would be available to download alongside the core. Lets keep the core lean and mean.

comment:9 Changed 11 years ago by eduardo

It's definitely useful.

+1

comment:10 Changed 9 years ago by dmethvin

Component: unfiledattributes

comment:11 Changed 9 years ago by Rick Waldron

Milestone: 1.5
Priority: majorlow
Status: newopen

Needs review/attention

comment:12 Changed 9 years ago by dmethvin

Keywords: needsreview added
Milestone: 1.51.next

comment:13 Changed 9 years ago by doublerebel

To have the same behavior as the Ext method, radioClass must also take an array of classes, as in my little plugin here:

http://code.doublerebel.com/jQuery/jquery.radioclass.js

Interestingly, this ticket was filed (and various radioclass blog posts were written) about the same time I created that. I think radioClass would definitely see use.

comment:14 Changed 9 years ago by Rick Waldron

Resolution: wontfix
Status: openclosed

Without a public repo, unit tests or docs, it's hard to support something that already seems easily accomplished with existing core methods - as noted by paul.irish

-1

Note: See TracTickets for help on using tickets.