Opened 14 years ago
Closed 14 years ago
#1972 closed defect (wontfix)
dojo.html.removeClass() doesn't work properly when allowPartialMatches is true
Reported by: | Owned by: | Bryan Forbes | |
---|---|---|---|
Priority: | high | Milestone: | 0.9 |
Component: | HTML | Version: | 0.4 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
When trying to clear a set of classes from an HTML element, I found that dojo.html.removeClass() doesn't work properly in 0.4. I believe it did work properly in 0.3.1.
I looked into it and it turns out that the probably faster .replace() call for allowPartialMatches == true only replaces the passed in classStr exactly once. In other words, if obj
has className
set to "blah noblah
" calling dojo.html.replaceClass(obj, 'no', true)
would result in className
being set to "blah blah
". Obviously not what I was looking for.
The following patch fixes it.
--- style.js (revision 213) +++ style.js (working copy) @@ -92,7 +92,7 @@ if (!allowPartialMatches) { var newcs = dojo.html.getClass(node).replace(new RegExp('(^|\s+)'+classStr+'(\s+|$)'), "$1$2"); } else { - var newcs = dojo.html.getClass(node).replace(classStr,''); + var newcs = dojo.html.getClass(node).replace(new RegExp('(^|\s+)(?:'+classStr+'\S*(?:\s+|$)?)+(\s+|$)','g'), "$1$2"); } dojo.html.setClass(node, newcs); }catch(e){
Yeah, the RegExp? is a tad more complicated (heh) but I believe it works properly in all cases. The extra (?:\s+|$)? in there allows for repeated strings, like
blah noblah noimage, which with out that nastiness just did
blah noimage`.
By the way, the revision number is from our internal project, not Dojo.
Michael
Change History (2)
comment:1 Changed 14 years ago by
Milestone: | → 0.9 |
---|
comment:2 Changed 14 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
we don't support allowPartialMatches anymore in 0.9