Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
2526e293
Commit
2526e293
authored
Jan 06, 2010
by
jeresig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing some bugs in the re-tooling of toggleClass, adding in some performance optimizations.
parent
600d3145
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
10 deletions
+11
-10
attributes.js
src/attributes.js
+11
-10
No files found.
src/attributes.js
View file @
2526e293
...
@@ -93,26 +93,27 @@ jQuery.fn.extend({
...
@@ -93,26 +93,27 @@ jQuery.fn.extend({
return
this
;
return
this
;
},
},
toggleClass
:
function
(
classNames
,
state
)
{
toggleClass
:
function
(
value
,
stateVal
)
{
var
type
=
typeof
classNames
;
var
type
=
typeof
value
,
isBool
=
typeof
stateVal
===
"boolean"
;
if
(
jQuery
.
isFunction
(
classNames
)
)
{
if
(
jQuery
.
isFunction
(
value
)
)
{
return
this
.
each
(
function
(
i
)
{
return
this
.
each
(
function
(
i
)
{
var
self
=
jQuery
(
this
);
var
self
=
jQuery
(
this
);
self
.
toggleClass
(
classNames
.
call
(
this
,
i
,
self
.
attr
(
"class"
)),
state
);
self
.
toggleClass
(
value
.
call
(
this
,
i
,
self
.
attr
(
"class"
)),
stateVal
);
});
});
}
}
return
this
.
each
(
function
(){
return
this
.
each
(
function
()
{
if
(
type
===
"string"
)
{
if
(
type
===
"string"
)
{
// toggle individual class names
// toggle individual class names
var
isBool
=
typeof
state
===
"boolean"
,
className
,
i
=
0
,
var
className
,
i
=
0
,
self
=
jQuery
(
this
),
classNames
=
classNames
.
split
(
rspace
);
state
=
stateVal
,
classNames
=
value
.
split
(
rspace
);
while
(
(
className
=
classNames
[
i
++
])
)
{
while
(
(
className
=
classNames
[
i
++
])
)
{
// check each className given, space seperated list
// check each className given, space seperated list
state
=
isBool
?
state
:
!
jQuery
(
this
)
.
hasClass
(
className
);
state
=
isBool
?
state
:
!
self
.
hasClass
(
className
);
jQuery
(
this
)
[
state
?
"addClass"
:
"removeClass"
](
className
);
self
[
state
?
"addClass"
:
"removeClass"
](
className
);
}
}
}
else
if
(
type
===
"undefined"
||
type
===
"boolean"
)
{
}
else
if
(
type
===
"undefined"
||
type
===
"boolean"
)
{
...
@@ -122,7 +123,7 @@ jQuery.fn.extend({
...
@@ -122,7 +123,7 @@ jQuery.fn.extend({
}
}
// toggle whole className
// toggle whole className
this
.
className
=
this
.
className
||
classNames
===
false
?
""
:
jQuery
.
data
(
this
,
"__className__"
)
||
""
;
this
.
className
=
this
.
className
||
value
===
false
?
""
:
jQuery
.
data
(
this
,
"__className__"
)
||
""
;
}
}
});
});
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment