-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regex may not always match the desired substring. #4
Comments
The space won't match when the classname is the first class in the attribute value (i.e. has a But you're right, this regex could be improved. |
How about a regex of |
@GaryJones I tested that out on a demo site and it didn't seem to work for me, possibly because quotation marks don't occur in the search string. How about |
Better yet, why don't we use var c = document.body.classList;
c = c.remove('no-js');
c = c.add('js');
document.body.classList = c; |
Brilliant! That's much better than a complex regex. |
Could reduce a few bytes with: var c = document.body.classList;
c.remove('no-js');
c.add('js'); |
Instead of relying on a regex to amend a string, deal with the list of classes as an array. Fixes #4.
@timothyjensen Feel free to checkout and give 70c2126 a go (or the rest of the |
Great, I just tested |
https://github.com/GaryJones/genesis-js-no-js/releases/tag/3.0.0 and https://github.com/GaryJones/genesis-js-no-js/releases/tag/3.0.1 have now been released which contains the improvement from here. |
The regex used in the
replace()
method may not always match the substring'no-js'
:genesis-js-no-js/includes/class-genesis-js-no-js.php
Line 63 in 7bc90e3
Say we have a body class of
'home alpha-plugin-no-js no-js'
, then the regex will match the first occurrence of'no-js'
and result in a body class of'home alpha-plugin-js no-js'
.To avoid this, we can add the global flag to the regex, but that might conflict with other plugins. Another idea is to add a space so that the regex matches
/ no-js/
(with a preceding space). We could also create a more complex regex, but that might not be necessary.The text was updated successfully, but these errors were encountered: