-
Notifications
You must be signed in to change notification settings - Fork 137
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
toggleClass appends existing classes to className #106
Comments
thanks for the bug report. i will figure something out |
This is still happening in Safari (or maybe it's a new issue), but only when the class name contains capital letters. Instead of removing the class name, the same one just gets appended each time. Turns out Here's the userAgent for the version I'm seeing this in: I noticed the problem in Bonzo 1.2.3, but I updated to Bonzo 1.3.4 and it still does the same thing. |
Figured it out, and it looks like it's a bug in Safari's DOM interface (occurs in both the desktop and mobile versions). Still broken in Safari 6.0.3 (which shipped with OS X 10.8.3). Class names that are added either via setting the Anyway, the end result is Bonzo's This obviously needs to be reported to Apple (which I will do after this), and I was able to work around the issue on my current project by just using lowercase class names in place of the ones that weren't working with |
Alrighty, here's the reduced test case I sent in my bug report (ID: 13446153 @ bugreport.apple.com) (1) Create a new HTML document with the following contents:
(2) Open the web inspector and type the following in the console:
|
Interestingly, if HTML document contents:
Paste in JS console:
|
jesus! this is quite the findings. i'll have some closer reading. first things first is to add a test-case into the tests file and then begin running them in safari |
Might be a good case for some feature-detection at startup. make a new element, add a classname with capitals in it, check if it returns lowercased version, if so, swap out default methods for one that does a toLowerCase or a regex/i. It'd be a shame to have to do a toLowerCase or a regex on all browsers if this is only for one buggy browser, would it not? |
This isn't a proper test case for Bonzo (not really Bonzo's fault), but you can load it up in any browser and see what happens. I'm just using plain old JavaScript (without any modules) to clarify that the bug is in the DOM API, and that it occurs when adding a class via As for Bonzo, you could work around it by setting an element's Anyway here's the thing that'll tell you if any given browser's
|
@rvagg Yeah, definitely don't want to change how Bonzo works for every browser. I don't even like the idea of doing any kind of workaround at all; I worry about JS libraries slowly acquiring a mess of hacks to deal with browser bugs that only existed for a few versions, then being stuck with the hacks because someone might still be running one of those versions. On the other hand I guess some of the appeal of modules is to fix these things once and (hopefully) not have to worry about them again. If you guys do want to try to handle this, I like the idea of a quick startup test; make a new element, do a Sadly, I think the hack I mentioned earlier (setting Anyway, that's everything I've figured out so far. |
Just noticed this bug is fixed in the current WebKit nightly (r152225). I kinda forgot about this until just now, so they might have fixed it awhile ago. |
If the browser does not support classList toggleClass does not have the same behaviour.
If the toggled class already exists on an element toggleClass will add that same class to the className string, which means the class can never be removed.
This is caused by the internal addClass function not checking for the new class existing in the className string before appending.
I suppose the fix would be something like:
That would unfortunately make the addClass API call hasClass twice.
However, given that add/removeClass API functions now have the same functionality as their classList equivalents the hasClass checks are now unnecessary and can be removed.
The text was updated successfully, but these errors were encountered: