@@ -12,6 +12,10 @@ function functionReturningObj( value ) {
} ;
}
function arrayFromString ( value ) {
return value ? value . split ( " " ) : [ ] ;
}
/*
======== local reference =======
bareObj and functionReturningObj can be used to test passing functions to setters
@@ -1261,6 +1265,10 @@ QUnit.test( "addClass(Function)", function( assert ) {
testAddClass ( functionReturningObj , assert ) ;
} ) ;
QUnit . test ( "addClass(Array)" , function ( assert ) {
testAddClass ( arrayFromString , assert ) ;
} ) ;
QUnit . test ( "addClass(Function) with incoming value" , function ( assert ) {
assert . expect ( 52 ) ;
var pass , i ,
@@ -1334,6 +1342,10 @@ QUnit.test( "removeClass(Function) - simple", function( assert ) {
testRemoveClass ( functionReturningObj , assert ) ;
} ) ;
QUnit . test ( "removeClass(Array) - simple" , function ( assert ) {
testRemoveClass ( arrayFromString , assert ) ;
} ) ;
QUnit . test ( "removeClass(Function) with incoming value" , function ( assert ) {
assert . expect ( 52 ) ;
@@ -1432,6 +1444,10 @@ QUnit.test( "toggleClass(Function[, boolean])", function( assert ) {
testToggleClass ( functionReturningObj , assert ) ;
} ) ;
QUnit . test ( "toggleClass(Array[, boolean])" , function ( assert ) {
testToggleClass ( arrayFromString , assert ) ;
} ) ;
QUnit . test ( "toggleClass(Function[, boolean]) with incoming value" , function ( assert ) {
assert . expect ( 14 ) ;
@@ -1567,6 +1583,40 @@ QUnit.test( "addClass, removeClass, hasClass on many elements", function( assert
"Did not find a class when not present" ) ;
} ) ;
QUnit . test ( "addClass, removeClass, hasClass on many elements - Array" , function ( assert ) {
assert . expect ( 16 ) ;
var elem = jQuery ( "<p>p0</p><p>p1</p><p>p2</p>" ) ;
elem . addClass ( [ "hi" ] ) ;
assert . equal ( elem [ 0 ] . className , "hi" , "Check single added class" ) ;
assert . equal ( elem [ 1 ] . className , "hi" , "Check single added class" ) ;
assert . equal ( elem [ 2 ] . className , "hi" , "Check single added class" ) ;
elem . addClass ( [ "foo" , "bar" ] ) ;
assert . equal ( elem [ 0 ] . className , "hi foo bar" , "Check more added classes" ) ;
assert . equal ( elem [ 1 ] . className , "hi foo bar" , "Check more added classes" ) ;
assert . equal ( elem [ 2 ] . className , "hi foo bar" , "Check more added classes" ) ;
elem . removeClass ( ) ;
assert . equal ( elem [ 0 ] . className , "" , "Remove all classes" ) ;
assert . equal ( elem [ 1 ] . className , "" , "Remove all classes" ) ;
assert . equal ( elem [ 2 ] . className , "" , "Remove all classes" ) ;
elem . addClass ( [ "hi" , "foo" , "bar" , "baz" ] ) ;
elem . removeClass ( [ "foo" ] ) ;
assert . equal ( elem [ 0 ] . className , "hi bar baz" , "Check removal of one class" ) ;
assert . equal ( elem [ 1 ] . className , "hi bar baz" , "Check removal of one class" ) ;
assert . equal ( elem [ 2 ] . className , "hi bar baz" , "Check removal of one class" ) ;
elem . removeClass ( [ "bar baz" ] ) ;
assert . equal ( elem [ 0 ] . className , "hi" , "Check removal of two classes" ) ;
assert . equal ( elem [ 1 ] . className , "hi" , "Check removal of two classes" ) ;
assert . equal ( elem [ 2 ] . className , "hi" , "Check removal of two classes" ) ;
assert . ok ( elem . hasClass ( "hi" ) , "Check has1" ) ;
} ) ;
QUnit . test ( "addClass, removeClass, hasClass on elements with classes with non-HTML whitespace (gh-3072, gh-3003)" , function ( assert ) {
assert . expect ( 9 ) ;
This comment has been minimized.
Nice addition, but this should also work with the element creation shortform, not just with
.addClass
:$("<span/>", {"class" : ["a", "b", "c"]}));
Results in:
<span class="a,b,c"></span>
instead of<span class="a b c"/>
which is not intuitive and will fail silently.This comment has been minimized.
The short form doesn't work that way. There is no special case code for it, other than calling
.attr()
if there's no jQuery method. I agree it's not intuitive and for that reason it's better to not use the "short form" at all, especially since it's not even that much shorter. Perhaps we should mark it as deprecated to emphasize that.