className prefix is not applied when removing "no-js" classname #1031

Closed
keeganstreet opened this Issue Sep 3, 2013 · 11 comments

Projects

None yet

5 participants

@keeganstreet

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.

@patrickkettner
Member

Just out of curiosity, is there a reason you want to use .supports-no-js, rather than just .no-js?

@keeganstreet

@patrickkettner Yes. I want it to be clear what each classname is for, so all feature-detection classnames are prefixed with supports-.

@patrickkettner
Member

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.

@ryanseddon
Member

We have the option to prefix classes and no-js should be included in that. I'll take a look at this.

@stucox
Member
stucox commented Sep 4, 2013

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-jsjs switch, and now includes the lib/build.js function which handles build parameters.

@keeganstreet

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.

@ryanseddon
Member

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.

@stucox
Member
stucox commented Sep 19, 2013

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.

@donaldpipowitch

If I use the build function from the site this doesn't seem to be solved:
Link

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").

@stucox
Member
stucox commented Feb 17, 2014

This change will be in v3.0.0

@donaldpipowitch

Thank you for the update!

@patrickkettner patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this issue Feb 22, 2015
@ryanseddon ryanseddon Handle class prefixing on no-js classes properly. Fixes #1031 01be04b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment