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
5be99ecc
Commit
5be99ecc
authored
Jan 03, 2013
by
adamcoulombe
Committed by
Dave Methvin
Jan 27, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #13150, .has() w/o args checks for any callbacks. Close gh-1111.
parent
24e76245
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
2 deletions
+50
-2
callbacks.js
src/callbacks.js
+3
-2
callbacks.js
test/unit/callbacks.js
+47
-0
No files found.
src/callbacks.js
View file @
5be99ecc
...
@@ -137,9 +137,10 @@ jQuery.Callbacks = function( options ) {
...
@@ -137,9 +137,10 @@ jQuery.Callbacks = function( options ) {
}
}
return
this
;
return
this
;
},
},
// Control if a given callback is in the list
// Check if a given callback is in the list.
// If no argument is given, return whether or not list has callbacks attached.
has
:
function
(
fn
)
{
has
:
function
(
fn
)
{
return
jQuery
.
inArray
(
fn
,
list
)
>
-
1
;
return
fn
?
jQuery
.
inArray
(
fn
,
list
)
>
-
1
:
!!
(
list
&&
list
.
length
)
;
},
},
// Remove all callbacks from the list
// Remove all callbacks from the list
empty
:
function
()
{
empty
:
function
()
{
...
...
test/unit/callbacks.js
View file @
5be99ecc
...
@@ -269,6 +269,53 @@ test( "jQuery.Callbacks.remove - should remove all instances", function() {
...
@@ -269,6 +269,53 @@ test( "jQuery.Callbacks.remove - should remove all instances", function() {
}).
remove
(
fn
).
fire
();
}).
remove
(
fn
).
fire
();
});
});
test
(
"jQuery.Callbacks.has"
,
function
()
{
expect
(
13
);
var
cb
=
jQuery
.
Callbacks
();
function
getA
()
{
return
"A"
;
}
function
getB
()
{
return
"B"
;
}
function
getC
()
{
return
"C"
;
}
cb
.
add
(
getA
,
getB
,
getC
);
strictEqual
(
cb
.
has
(),
true
,
"No arguments to .has() returns whether callback function(s) are attached or not"
);
strictEqual
(
cb
.
has
(
getA
),
true
,
"Check if a specific callback function is in the Callbacks list"
);
cb
.
remove
(
getB
);
strictEqual
(
cb
.
has
(
getB
),
false
,
"Remove a specific callback function and make sure its no longer there"
);
strictEqual
(
cb
.
has
(
getA
),
true
,
"Remove a specific callback function and make sure other callback function is still there"
);
cb
.
empty
();
strictEqual
(
cb
.
has
(),
false
,
"Empty list and make sure there are no callback function(s)"
);
strictEqual
(
cb
.
has
(
getA
),
false
,
"Check for a specific function in an empty() list"
);
cb
.
add
(
getA
,
getB
,
function
(){
strictEqual
(
cb
.
has
(),
true
,
"Check if list has callback function(s) from within a callback function"
);
strictEqual
(
cb
.
has
(
getA
),
true
,
"Check if list has a specific callback from within a callback function"
);
}).
fire
();
strictEqual
(
cb
.
has
(),
true
,
"Callbacks list has callback function(s) after firing"
);
cb
.
disable
();
strictEqual
(
cb
.
has
(),
false
,
"disabled() list has no callback functions (returns false)"
);
strictEqual
(
cb
.
has
(
getA
),
false
,
"Check for a specific function in a disabled() list"
);
cb
=
jQuery
.
Callbacks
(
"unique"
);
cb
.
add
(
getA
);
cb
.
add
(
getA
);
strictEqual
(
cb
.
has
(),
true
,
"Check if unique list has callback function(s) attached"
);
cb
.
lock
();
strictEqual
(
cb
.
has
(),
false
,
"locked() list is empty and returns false"
);
});
test
(
"jQuery.Callbacks() - adding a string doesn't cause a stack overflow"
,
function
()
{
test
(
"jQuery.Callbacks() - adding a string doesn't cause a stack overflow"
,
function
()
{
expect
(
1
);
expect
(
1
);
...
...
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