Opened 13 years ago

Closed 12 years ago

#9577 closed enhancement (fixed)

addClass/removeClass add array support

Reported by: Les Owned by: Eugene Lazutkin
Priority: low Milestone: 1.4
Component: Core Version: 1.3.0
Keywords: Cc:
Blocked By: Blocking:


Here's an example how I'd use it:

var styles = ["dijitTreeExpandoLoading", "dijitTreeExpandoOpened",
			"dijitTreeExpandoClosed", "dijitTreeExpandoLeaf"];

dojo.removeClass(this.expandoNode, styles);

... as opposed to the current code:

		dojo.removeClass(this.expandoNode, s);
	}, this

Currently, only Ext supports this feature, but not jQuery, Prototype or MooTools?.

Change History (10)

comment:1 Changed 13 years ago by Eugene Lazutkin

Component: GeneralCore
Milestone: tbd1.4
Owner: changed from anonymous to Eugene Lazutkin
Status: newassigned

This change appears to be small and unambiguous, yet useful. :-)

Should be combined with #9560.

comment:2 Changed 13 years ago by dante

jquery does this by .split(" ");

$(el).removeClass("foo bar baz");

dojo current tries to match a literal "foo bar baz", but would make sense to treat it as an array. we do something similar in .style() (obj) and .attr() so +1 from me on this.

comment:3 Changed 13 years ago by dante

fwiw: addClass already handles this (but could end up with double-classes) and toggleClass _should_

comment:4 Changed 13 years ago by Sam Foster

split(" ") ? that seems brittle. classes.split(/\s+/) if we stick to only handling a string. But I like passing/handling an array better. Ending up with double classes - and the possibility of removeClass not actually removing all className tokens of that name - these are pretty serious bugs IMO.

I guess you could have input like <div class="myclass myclass myclass"> and css like .myclass.myclass.myclass { ... } and be annoyed if removeClass("myclass") took them all out? This defines edge-case for me though.


comment:5 Changed 13 years ago by Eugene Lazutkin

Regarding legality adding the same class more than once. I seem to remember seeing that at least one browser (Opera?) re-normalizes the string automatically.

The HTML 4.01 spec doesn't allow to change the class string: --- the class string is a case-sensitive CDATA. The spec allows to ignore leading and trailing spaces.

OTOH, the HTML 5 spec defines that the class string is an unordered set of unique space-separated tokens:

I think that for our purposes we can safely adhere to the HTML 5 clarification.

comment:6 Changed 13 years ago by Eugene Lazutkin

(In [19075]) Adding array support to addClass/removeClass, adding support to remove all classes, adding unit tests and inline docs, thx Les!, !strict. refs #9577, refs #9560.

comment:7 Changed 13 years ago by Eugene Lazutkin

(In [19076]) removing trailing spaces, !strict, refs #9560, refs #9577.

comment:8 Changed 13 years ago by Eugene Lazutkin

Now I want to update the docs on Dojo Campus but I don't know what is the correct way to do it: this functionality is unreleased yet. Do we mark it somehow? Do we update some special area? How do we handle docs for different versions?

comment:9 Changed 13 years ago by dante

Just do "new in 1.4:" preceding the extended explanation.

new in 1.4 will bold in reST iirc.

comment:10 Changed 12 years ago by Eugene Lazutkin

Resolution: fixed
Status: assignedclosed

All information is added to the release nodes, and the documentation is updated.

Note: See TracTickets for help on using tickets.