-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
add a hasClass() method #1464
add a hasClass() method #1464
Conversation
Two goals here: First, the removeClass() wasn't adding spaces before and after element.className and the class. This could create weird false positives as we get into compound class names, like vjs-fluid, and vjs-fluid-4-3. This aligns the check across both methods. Second, I think hasClass is going to be essential for testing, going forward.
@@ -314,18 +328,19 @@ vjs.addClass = function(element, classToAdd){ | |||
vjs.removeClass = function(element, classToRemove){ | |||
var classNames, i; | |||
|
|||
if (element.className.indexOf(classToRemove) == -1) { return; } | |||
if (vjs.hasClass(element, classToRemove)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you make this if check !hasClass, and then return, it will keep the rest of this function not indented, which is nice.
Other than the two comments, LGTM. |
Yeah, this looks good to me, thanks! If you want to make the updates @gkatsev mentioned, and add a quick test this should be ready to go. |
* @return {vjs.Component} | ||
*/ | ||
vjs.Component.prototype.hasClass = function(classToCheck){ | ||
vjs.hasClass(this.el_, classToCheck); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this should return the result of vjs.hasClass.
I think I'm there now. Thx for your patience!
I could also rewrite some of the older tests to use hasClass(), too. The older tests incorrectly match a substring, e.g. https://github.com/videojs/video.js/blob/master/test/unit/component.js#L184 but I think this works now as is. |
Good to go for this week's release. |
Merged in. Thank you! |
Two goals here:
First, the removeClass() wasn't adding spaces before and after element.className and the class. This could create weird false positives as we get into compound class names, like vjs-fluid, and vjs-fluid-4-3. This aligns the check across both methods.
Second, I think hasClass is going to be essential for testing, going forward.