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
b8d46f7b
Commit
b8d46f7b
authored
Dec 28, 2006
by
Jörn Zaefferer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented, tested and documented #202
parent
def8c734
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
17 deletions
+65
-17
eventTest.js
src/event/eventTest.js
+43
-0
coreTest.js
src/jquery/coreTest.js
+0
-13
jquery.js
src/jquery/jquery.js
+22
-4
No files found.
src/event/eventTest.js
View file @
b8d46f7b
...
@@ -8,4 +8,47 @@ test("toggle(Function, Function) - add toggle event and fake a few clicks", func
...
@@ -8,4 +8,47 @@ test("toggle(Function, Function) - add toggle event and fake a few clicks", func
link
=
$
(
'#mark'
);
link
=
$
(
'#mark'
);
link
.
click
().
toggle
(
fn1
,
fn2
).
click
().
click
().
click
().
click
().
click
();
link
.
click
().
toggle
(
fn1
,
fn2
).
click
().
click
().
click
().
click
().
click
();
ok
(
count
==
1
,
"Check for toggle(fn, fn)"
);
ok
(
count
==
1
,
"Check for toggle(fn, fn)"
);
});
test
(
"unbind(event)"
,
function
()
{
expect
(
3
);
var
el
=
$
(
"#firstp"
);
el
.
click
(
function
()
{
ok
(
true
,
"Fake normal bind"
);
});
el
.
click
(
function
(
event
)
{
el
.
unbind
(
event
);
ok
(
true
,
"Fake onebind"
);
});
el
.
click
().
click
();
});
test
(
"trigger(event, [data]"
,
function
()
{
expect
(
3
);
var
handler
=
function
(
event
,
a
,
b
,
c
)
{
ok
(
a
==
1
,
"check passed data"
);
ok
(
b
==
"2"
,
"check passed data"
);
ok
(
c
==
"abc"
,
"check passed data"
);
}
$
(
"#firstp"
).
bind
(
"click"
,
handler
).
trigger
(
"click"
,
[
1
,
"2"
,
"abc"
]);
});
test
(
"bind() with data"
,
function
()
{
expect
(
2
);
var
handler
=
function
(
event
)
{
ok
(
event
.
data
,
"check passed data exists"
);
ok
(
event
.
data
.
foo
==
"bar"
,
"Check value of passed data"
);
}
$
(
"#firstp"
).
bind
(
"click"
,
{
foo
:
"bar"
},
handler
).
click
();
});
test
(
"bind() with data and trigger() with data"
,
function
()
{
expect
(
4
);
var
handler
=
function
(
event
,
data
)
{
ok
(
event
.
data
,
"check passed data exists"
);
ok
(
event
.
data
.
foo
==
"bar"
,
"Check value of passed data"
);
ok
(
data
,
"Check trigger data"
);
ok
(
data
.
bar
==
"foo"
,
"Check value of trigger data"
);
}
$
(
"#firstp"
).
bind
(
"click"
,
{
foo
:
"bar"
},
handler
).
trigger
(
"click"
,
[{
bar
:
"foo"
}]);
});
});
\ No newline at end of file
src/jquery/coreTest.js
View file @
b8d46f7b
...
@@ -564,16 +564,3 @@ test("removeClass(String) - add three classes and remove again", function() {
...
@@ -564,16 +564,3 @@ test("removeClass(String) - add three classes and remove again", function() {
test
(
"removeAttr(String"
,
function
()
{
test
(
"removeAttr(String"
,
function
()
{
ok
(
$
(
'#mark'
).
removeAttr
(
"class"
)[
0
].
className
==
""
,
"remove class"
);
ok
(
$
(
'#mark'
).
removeAttr
(
"class"
)[
0
].
className
==
""
,
"remove class"
);
});
});
test
(
"unbind(event)"
,
function
()
{
expect
(
3
);
var
el
=
$
(
"#firstp"
);
el
.
click
(
function
()
{
ok
(
true
,
"Fake normal bind"
);
});
el
.
click
(
function
(
event
)
{
el
.
unbind
(
event
);
ok
(
true
,
"Fake onebind"
);
});
el
.
click
().
click
();
});
src/jquery/jquery.js
View file @
b8d46f7b
...
@@ -2045,12 +2045,16 @@ jQuery.extend({
...
@@ -2045,12 +2045,16 @@ jQuery.extend({
// Bind an event to an element
// Bind an event to an element
// Original by Dean Edwards
// Original by Dean Edwards
add
:
function
(
element
,
type
,
handler
)
{
add
:
function
(
element
,
type
,
handler
,
data
)
{
// For whatever reason, IE has trouble passing the window object
// For whatever reason, IE has trouble passing the window object
// around, causing it to be cloned in the process
// around, causing it to be cloned in the process
if
(
jQuery
.
browser
.
msie
&&
element
.
setInterval
!=
undefined
)
if
(
jQuery
.
browser
.
msie
&&
element
.
setInterval
!=
undefined
)
element
=
window
;
element
=
window
;
// if data is passed, bind to handler
if
(
data
)
handler
.
data
=
data
;
// Make sure that the function being executed has a unique ID
// Make sure that the function being executed has a unique ID
if
(
!
handler
.
guid
)
if
(
!
handler
.
guid
)
handler
.
guid
=
this
.
guid
++
;
handler
.
guid
=
this
.
guid
++
;
...
@@ -2140,6 +2144,7 @@ jQuery.extend({
...
@@ -2140,6 +2144,7 @@ jQuery.extend({
// Pass in a reference to the handler function itself
// Pass in a reference to the handler function itself
// So that we can later remove it
// So that we can later remove it
args
[
0
].
handler
=
c
[
j
];
args
[
0
].
handler
=
c
[
j
];
args
[
0
].
data
=
c
[
j
].
data
;
if
(
c
[
j
].
apply
(
this
,
args
)
===
false
)
{
if
(
c
[
j
].
apply
(
this
,
args
)
===
false
)
{
event
.
preventDefault
();
event
.
preventDefault
();
...
@@ -2149,7 +2154,7 @@ jQuery.extend({
...
@@ -2149,7 +2154,7 @@ jQuery.extend({
}
}
// Clean up added properties in IE to prevent memory leak
// Clean up added properties in IE to prevent memory leak
if
(
jQuery
.
browser
.
msie
)
event
.
target
=
event
.
preventDefault
=
event
.
stopPropagation
=
null
;
if
(
jQuery
.
browser
.
msie
)
event
.
target
=
event
.
preventDefault
=
event
.
stopPropagation
=
event
.
handler
=
event
.
data
=
null
;
return
returnValue
;
return
returnValue
;
},
},
...
@@ -3174,12 +3179,24 @@ jQuery.macros = {
...
@@ -3174,12 +3179,24 @@ jQuery.macros = {
* default behaviour. To stop both default action and event bubbling, your handler
* default behaviour. To stop both default action and event bubbling, your handler
* has to return false.
* has to return false.
*
*
* In most cases, you can define your event handlers as anonymous functions
* (see first example). In cases where that is not possible, you can pass additional
* data as the second paramter (and the handler function as the third), see
* second example.
*
* @example $("p").bind( "click", function() {
* @example $("p").bind( "click", function() {
* alert( $(this).text() );
* alert( $(this).text() );
* } )
* } )
* @before <p>Hello</p>
* @before <p>Hello</p>
* @result alert("Hello")
* @result alert("Hello")
*
*
* @example var handler = function(event) {
* alert(event.data.foo);
* };
* $("p").bind( "click", {foo: "bar"}, handler)
* @result alert("bar")
* @desc Pass some additional data to the event handler.
*
* @example $("form").bind( "submit", function() { return false; } )
* @example $("form").bind( "submit", function() { return false; } )
* @desc Cancel a default action and prevent it from bubbling by returning false
* @desc Cancel a default action and prevent it from bubbling by returning false
* from your function.
* from your function.
...
@@ -3198,11 +3215,12 @@ jQuery.macros = {
...
@@ -3198,11 +3215,12 @@ jQuery.macros = {
* @name bind
* @name bind
* @type jQuery
* @type jQuery
* @param String type An event type
* @param String type An event type
* @param Object data (optional) Additional data passed to the event handler as event.data
* @param Function fn A function to bind to the event on each of the set of matched elements
* @param Function fn A function to bind to the event on each of the set of matched elements
* @cat Events
* @cat Events
*/
*/
bind
:
function
(
type
,
fn
)
{
bind
:
function
(
type
,
data
,
fn
)
{
jQuery
.
event
.
add
(
this
,
type
,
fn
);
jQuery
.
event
.
add
(
this
,
type
,
fn
||
data
,
data
);
},
},
/**
/**
...
...
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