The className prefix option is used to prefix the default Modernizr classnames. I am using a prefix of "supports", so I have classes like "supports-js", "supports-no-js", "supports-flexbox" and "supports-no-touch" for my feature detection classnames.
I have added a classname of "supports-no-js" to my HTML element, but Modernizr does not remove this. Modernizr has been hardcoded to remove a classname of "no-js" only, disregarding the className prefix option:
docElement.className = docElement.className.replace(/(^|\s)no-js(\s|$)/, '$1$2') +
This is a feature request to apply the className prefix option when removing the "no-js" className.
Just out of curiosity, is there a reason you want to use .supports-no-js, rather than just .no-js?
@patrickkettner Yes. I want it to be clear what each classname is for, so all feature-detection classnames are prefixed with supports-.
Sure, its in this case, I think that no-js is clearer. A positive-negative makes it sound clunkier.
Personal preference is all.
Regardless, this is technically an issue with the builder, rather than the detects themselves. I'll be messing with this over at Modernizr/modernizr.com, and will ping you with any update.
We have the option to prefix classes and no-js should be included in that. I'll take a look at this.
I think it should remove both prefixed and non-prefixed no-js.
Otherwise, I think it could cause problems if e.g. using HTML5 Boilerplate with className prefix supports- didn't also remove no-js.
@patrickkettner – this is an issue with Modernizr (rather than modernizr.com), as this repo includes the code which applies the no-js → js switch, and now includes the lib/build.js function which handles build parameters.
Yeah I think that's a valid point @stucox. I wouldn't want this to break existing sites that use the current behaviour, even if the current behaviour isn't completely logical.
Handle class prefixing on no-js classes properly. Fixes #1031
This will correctly handle class name prefixes now.
@stucox any ideas on testing? We'd probably have to kick off two builds on travis somehow where one does a normal build and the other does a build with the classPrefix config value set.
I think you're right. Could be a simpler build though, with just a few tests in it. Maybe our travis task should be running a handful of different configs anyway.
If I use the build function from the site this doesn't seem to be solved:
I can't use modernizr-no-js, because it won't be removed from my html. g.className.replace(/(^|\s)no-js(\s|$)/,"$1$2") should be g.className.replace(/(^|\s)modernizr-no-js(\s|$)/,"$1$2").
This change will be in v3.0.0
Thank you for the update!