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
6f7b6915
Commit
6f7b6915
authored
Jan 27, 2013
by
Dave Methvin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #12656. Make event shorthands excludable.
parent
a6c358d0
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
173 additions
and
162 deletions
+173
-162
Gruntfile.js
Gruntfile.js
+1
-0
event-alias.js
src/event-alias.js
+15
-0
event.js
src/event.js
+11
-27
attributes.js
test/unit/attributes.js
+1
-1
core.js
test/unit/core.js
+6
-3
event.js
test/unit/event.js
+113
-105
manipulation.js
test/unit/manipulation.js
+26
-26
No files found.
Gruntfile.js
View file @
6f7b6915
...
@@ -45,6 +45,7 @@ module.exports = function( grunt ) {
...
@@ -45,6 +45,7 @@ module.exports = function( grunt ) {
{
flag
:
"css"
,
src
:
"src/css.js"
},
{
flag
:
"css"
,
src
:
"src/css.js"
},
"src/serialize.js"
,
"src/serialize.js"
,
{
flag
:
"event-alias"
,
src
:
"src/event-alias.js"
},
{
flag
:
"ajax"
,
src
:
"src/ajax.js"
},
{
flag
:
"ajax"
,
src
:
"src/ajax.js"
},
{
flag
:
"ajax/script"
,
src
:
"src/ajax/script.js"
,
needs
:
[
"ajax"
]
},
{
flag
:
"ajax/script"
,
src
:
"src/ajax/script.js"
,
needs
:
[
"ajax"
]
},
{
flag
:
"ajax/jsonp"
,
src
:
"src/ajax/jsonp.js"
,
needs
:
[
"ajax"
,
"ajax/script"
]
},
{
flag
:
"ajax/jsonp"
,
src
:
"src/ajax/jsonp.js"
,
needs
:
[
"ajax"
,
"ajax/script"
]
},
...
...
src/event-alias.js
0 → 100644
View file @
6f7b6915
jQuery
.
each
(
(
"blur focus focusin focusout load resize scroll unload click dblclick "
+
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave "
+
"change select submit keydown keypress keyup error contextmenu"
).
split
(
" "
),
function
(
i
,
name
)
{
// Handle event binding
jQuery
.
fn
[
name
]
=
function
(
data
,
fn
)
{
return
arguments
.
length
>
0
?
this
.
on
(
name
,
null
,
data
,
fn
)
:
this
.
trigger
(
name
);
};
});
jQuery
.
fn
.
hover
=
function
(
fnOver
,
fnOut
)
{
return
this
.
mouseenter
(
fnOver
).
mouseleave
(
fnOut
||
fnOver
);
};
src/event.js
View file @
6f7b6915
...
@@ -481,9 +481,17 @@ jQuery.event = {
...
@@ -481,9 +481,17 @@ jQuery.event = {
}
}
// Create a writable copy of the event object and normalize some properties
// Create a writable copy of the event object and normalize some properties
var
i
,
prop
,
var
i
,
prop
,
copy
,
type
=
event
.
type
,
originalEvent
=
event
,
originalEvent
=
event
,
fixHook
=
jQuery
.
event
.
fixHooks
[
event
.
type
]
||
{},
fixHook
=
this
.
fixHooks
[
type
];
if
(
!
fixHook
)
{
this
.
fixHooks
[
type
]
=
fixHook
=
rmouseEvent
.
test
(
type
)
?
this
.
mouseHooks
:
rkeyEvent
.
test
(
type
)
?
this
.
keyHooks
:
{};
}
copy
=
fixHook
.
props
?
this
.
props
.
concat
(
fixHook
.
props
)
:
this
.
props
;
copy
=
fixHook
.
props
?
this
.
props
.
concat
(
fixHook
.
props
)
:
this
.
props
;
event
=
new
jQuery
.
Event
(
originalEvent
);
event
=
new
jQuery
.
Event
(
originalEvent
);
...
@@ -810,29 +818,5 @@ jQuery.fn.extend({
...
@@ -810,29 +818,5 @@ jQuery.fn.extend({
if
(
elem
)
{
if
(
elem
)
{
return
jQuery
.
event
.
trigger
(
type
,
data
,
elem
,
true
);
return
jQuery
.
event
.
trigger
(
type
,
data
,
elem
,
true
);
}
}
},
hover
:
function
(
fnOver
,
fnOut
)
{
return
this
.
mouseenter
(
fnOver
).
mouseleave
(
fnOut
||
fnOver
);
}
});
jQuery
.
each
(
(
"blur focus focusin focusout load resize scroll unload click dblclick "
+
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave "
+
"change select submit keydown keypress keyup error contextmenu"
).
split
(
" "
),
function
(
i
,
name
)
{
// Handle event binding
jQuery
.
fn
[
name
]
=
function
(
data
,
fn
)
{
return
arguments
.
length
>
0
?
this
.
on
(
name
,
null
,
data
,
fn
)
:
this
.
trigger
(
name
);
};
if
(
rkeyEvent
.
test
(
name
)
)
{
jQuery
.
event
.
fixHooks
[
name
]
=
jQuery
.
event
.
keyHooks
;
}
if
(
rmouseEvent
.
test
(
name
)
)
{
jQuery
.
event
.
fixHooks
[
name
]
=
jQuery
.
event
.
mouseHooks
;
}
}
});
});
test/unit/attributes.js
View file @
6f7b6915
...
@@ -312,7 +312,7 @@ test( "attr(String, Object)", function() {
...
@@ -312,7 +312,7 @@ test( "attr(String, Object)", function() {
equal
(
$input
.
attr
(
"checked"
),
"checked"
,
"Set checked to 'checked' (verified by .attr)"
);
equal
(
$input
.
attr
(
"checked"
),
"checked"
,
"Set checked to 'checked' (verified by .attr)"
);
var
$radios
=
jQuery
(
"#checkedtest"
).
find
(
"input[type='radio']"
);
var
$radios
=
jQuery
(
"#checkedtest"
).
find
(
"input[type='radio']"
);
$radios
.
eq
(
1
).
click
(
);
$radios
.
eq
(
1
).
trigger
(
"click"
);
equal
(
$radios
.
eq
(
1
).
prop
(
"checked"
),
true
,
"Second radio was checked when clicked"
);
equal
(
$radios
.
eq
(
1
).
prop
(
"checked"
),
true
,
"Second radio was checked when clicked"
);
equal
(
$radios
.
eq
(
0
).
attr
(
"checked"
),
"checked"
,
"First radio is still [checked]"
);
equal
(
$radios
.
eq
(
0
).
attr
(
"checked"
),
"checked"
,
"First radio is still [checked]"
);
...
...
test/unit/core.js
View file @
6f7b6915
...
@@ -34,9 +34,8 @@ test("jQuery()", function() {
...
@@ -34,9 +34,8 @@ test("jQuery()", function() {
div
=
jQuery
(
"<div/><hr/><code/><b/>"
),
div
=
jQuery
(
"<div/><hr/><code/><b/>"
),
exec
=
false
,
exec
=
false
,
lng
=
""
,
lng
=
""
,
expected
=
2
2
,
expected
=
2
1
,
attrObj
=
{
attrObj
=
{
"click"
:
function
()
{
ok
(
exec
,
"Click executed."
);
},
"text"
:
"test"
,
"text"
:
"test"
,
"class"
:
"test2"
,
"class"
:
"test2"
,
"id"
:
"test3"
"id"
:
"test3"
...
@@ -44,6 +43,10 @@ test("jQuery()", function() {
...
@@ -44,6 +43,10 @@ test("jQuery()", function() {
// The $(html, props) signature can stealth-call any $.fn method, check for a
// The $(html, props) signature can stealth-call any $.fn method, check for a
// few here but beware of modular builds where these methods may be excluded.
// few here but beware of modular builds where these methods may be excluded.
if
(
jQuery
.
fn
.
click
)
{
expected
++
;
attrObj
[
"click"
]
=
function
()
{
ok
(
exec
,
"Click executed."
);
};
}
if
(
jQuery
.
fn
.
width
)
{
if
(
jQuery
.
fn
.
width
)
{
expected
++
;
expected
++
;
attrObj
[
"width"
]
=
10
;
attrObj
[
"width"
]
=
10
;
...
@@ -133,7 +136,7 @@ test("jQuery()", function() {
...
@@ -133,7 +136,7 @@ test("jQuery()", function() {
equal
(
elem
[
0
].
id
,
"test3"
,
"jQuery() quick setter id"
);
equal
(
elem
[
0
].
id
,
"test3"
,
"jQuery() quick setter id"
);
exec
=
true
;
exec
=
true
;
elem
.
click
(
);
elem
.
trigger
(
"click"
);
// manually clean up detached elements
// manually clean up detached elements
elem
.
remove
();
elem
.
remove
();
...
...
test/unit/event.js
View file @
6f7b6915
...
@@ -4,12 +4,12 @@ test("null or undefined handler", function() {
...
@@ -4,12 +4,12 @@ test("null or undefined handler", function() {
expect
(
2
);
expect
(
2
);
// Supports Fixes bug #7229
// Supports Fixes bug #7229
try
{
try
{
jQuery
(
"#firstp"
).
click
(
null
);
jQuery
(
"#firstp"
).
on
(
"click"
,
null
);
ok
(
true
,
"Passing a null handler will not throw an exception"
);
ok
(
true
,
"Passing a null handler will not throw an exception"
);
}
catch
(
e
)
{}
}
catch
(
e
)
{}
try
{
try
{
jQuery
(
"#firstp"
).
click
(
undefined
);
jQuery
(
"#firstp"
).
on
(
"click"
,
undefined
);
ok
(
true
,
"Passing an undefined handler will not throw an exception"
);
ok
(
true
,
"Passing an undefined handler will not throw an exception"
);
}
catch
(
e
)
{}
}
catch
(
e
)
{}
});
});
...
@@ -66,7 +66,7 @@ test("bind(), with data", function() {
...
@@ -66,7 +66,7 @@ test("bind(), with data", function() {
ok
(
event
.
data
,
"bind() with data, check passed data exists"
);
ok
(
event
.
data
,
"bind() with data, check passed data exists"
);
equal
(
event
.
data
[
"foo"
],
"bar"
,
"bind() with data, Check value of passed data"
);
equal
(
event
.
data
[
"foo"
],
"bar"
,
"bind() with data, Check value of passed data"
);
};
};
jQuery
(
"#firstp"
).
bind
(
"click"
,
{
"foo"
:
"bar"
},
handler
).
click
(
).
unbind
(
"click"
,
handler
);
jQuery
(
"#firstp"
).
bind
(
"click"
,
{
"foo"
:
"bar"
},
handler
).
trigger
(
"click"
).
unbind
(
"click"
,
handler
);
ok
(
!
jQuery
.
_data
(
jQuery
(
"#firstp"
)[
0
],
"events"
),
"Event handler unbound when using data."
);
ok
(
!
jQuery
.
_data
(
jQuery
(
"#firstp"
)[
0
],
"events"
),
"Event handler unbound when using data."
);
...
@@ -74,7 +74,7 @@ test("bind(), with data", function() {
...
@@ -74,7 +74,7 @@ test("bind(), with data", function() {
var
handler2
=
function
(
event
)
{
var
handler2
=
function
(
event
)
{
equal
(
event
.
data
,
test
,
"bind() with function data, Check value of passed data"
);
equal
(
event
.
data
,
test
,
"bind() with function data, Check value of passed data"
);
};
};
jQuery
(
"#firstp"
).
bind
(
"click"
,
test
,
handler2
).
click
(
).
unbind
(
"click"
,
handler2
);
jQuery
(
"#firstp"
).
bind
(
"click"
,
test
,
handler2
).
trigger
(
"click"
).
unbind
(
"click"
,
handler2
);
});
});
test
(
"click(), with data"
,
function
()
{
test
(
"click(), with data"
,
function
()
{
...
@@ -83,7 +83,7 @@ test("click(), with data", function() {
...
@@ -83,7 +83,7 @@ test("click(), with data", function() {
ok
(
event
.
data
,
"bind() with data, check passed data exists"
);
ok
(
event
.
data
,
"bind() with data, check passed data exists"
);
equal
(
event
.
data
[
"foo"
],
"bar"
,
"bind() with data, Check value of passed data"
);
equal
(
event
.
data
[
"foo"
],
"bar"
,
"bind() with data, Check value of passed data"
);
};
};
jQuery
(
"#firstp"
).
click
({
"foo"
:
"bar"
},
handler
).
click
(
).
unbind
(
"click"
,
handler
);
jQuery
(
"#firstp"
).
on
(
"click"
,
{
"foo"
:
"bar"
},
handler
).
trigger
(
"click"
).
unbind
(
"click"
,
handler
);
ok
(
!
jQuery
.
_data
(
jQuery
(
"#firstp"
)[
0
],
"events"
),
"Event handler unbound when using data."
);
ok
(
!
jQuery
.
_data
(
jQuery
(
"#firstp"
)[
0
],
"events"
),
"Event handler unbound when using data."
);
});
});
...
@@ -391,7 +391,7 @@ test("bind/delegate bubbling, isDefaultPrevented", function() {
...
@@ -391,7 +391,7 @@ test("bind/delegate bubbling, isDefaultPrevented", function() {
$jq
[
0
].
click
();
// IE
$jq
[
0
].
click
();
// IE
}
}
};
};
$anchor2
.
click
(
function
(
e
)
{
$anchor2
.
on
(
"click"
,
function
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
});
});
$main
.
delegate
(
"#foo"
,
"click"
,
function
(
e
)
{
$main
.
delegate
(
"#foo"
,
"click"
,
function
(
e
)
{
...
@@ -408,7 +408,7 @@ test("bind/delegate bubbling, isDefaultPrevented", function() {
...
@@ -408,7 +408,7 @@ test("bind/delegate bubbling, isDefaultPrevented", function() {
fakeClick
(
$anchor2
);
fakeClick
(
$anchor2
);
$anchor2
.
unbind
(
"click"
);
$anchor2
.
unbind
(
"click"
);
$main
.
undelegate
(
"click"
);
$main
.
undelegate
(
"click"
);
$anchor2
.
click
(
function
(
e
)
{
$anchor2
.
on
(
"click"
,
function
(
e
)
{
// Let the default action occur
// Let the default action occur
});
});
$main
.
delegate
(
"#foo"
,
"click"
,
function
(
e
)
{
$main
.
delegate
(
"#foo"
,
"click"
,
function
(
e
)
{
...
@@ -427,7 +427,7 @@ test("bind(), iframes", function() {
...
@@ -427,7 +427,7 @@ test("bind(), iframes", function() {
jQuery
(
"div"
,
doc
).
bind
(
"click"
,
function
()
{
jQuery
(
"div"
,
doc
).
bind
(
"click"
,
function
()
{
ok
(
true
,
"Binding to element inside iframe"
);
ok
(
true
,
"Binding to element inside iframe"
);
}).
click
(
).
unbind
(
"click"
);
}).
trigger
(
"click"
).
unbind
(
"click"
);
});
});
test
(
"bind(), trigger change on select"
,
function
()
{
test
(
"bind(), trigger change on select"
,
function
()
{
...
@@ -489,7 +489,7 @@ test("bind(), namespaced events, cloned events", 18, function() {
...
@@ -489,7 +489,7 @@ test("bind(), namespaced events, cloned events", 18, function() {
}).
trigger
(
"tester"
);
}).
trigger
(
"tester"
);
// Make sure events stick with appendTo'd elements (which are cloned) #2027
// Make sure events stick with appendTo'd elements (which are cloned) #2027
jQuery
(
"<a href='#fail' class='test'>test</a>"
).
click
(
function
(){
return
false
;
}).
appendTo
(
"#qunit-fixture"
);
jQuery
(
"<a href='#fail' class='test'>test</a>"
).
on
(
"click"
,
function
(){
return
false
;
}).
appendTo
(
"#qunit-fixture"
);
ok
(
jQuery
(
"a.test:first"
).
triggerHandler
(
"click"
)
===
false
,
"Handler is bound to appendTo'd elements"
);
ok
(
jQuery
(
"a.test:first"
).
triggerHandler
(
"click"
)
===
false
,
"Handler is bound to appendTo'd elements"
);
});
});
...
@@ -603,8 +603,8 @@ test("bind(), with different this object", function() {
...
@@ -603,8 +603,8 @@ test("bind(), with different this object", function() {
};
};
jQuery
(
"#firstp"
)
jQuery
(
"#firstp"
)
.
bind
(
"click"
,
jQuery
.
proxy
(
handler1
,
thisObject
)).
click
(
).
unbind
(
"click"
,
handler1
)
.
bind
(
"click"
,
jQuery
.
proxy
(
handler1
,
thisObject
)).
trigger
(
"click"
).
unbind
(
"click"
,
handler1
)
.
bind
(
"click"
,
data
,
jQuery
.
proxy
(
handler2
,
thisObject
)).
click
(
).
unbind
(
"click"
,
handler2
);
.
bind
(
"click"
,
data
,
jQuery
.
proxy
(
handler2
,
thisObject
)).
trigger
(
"click"
).
unbind
(
"click"
,
handler2
);
ok
(
!
jQuery
.
_data
(
jQuery
(
"#firstp"
)[
0
],
"events"
),
"Event handler unbound when using different this object and data."
);
ok
(
!
jQuery
.
_data
(
jQuery
(
"#firstp"
)[
0
],
"events"
),
"Event handler unbound when using different this object and data."
);
});
});
...
@@ -738,7 +738,7 @@ test("unbind(type)", function() {
...
@@ -738,7 +738,7 @@ test("unbind(type)", function() {
jQuery
(
document
)
jQuery
(
document
)
.
bind
(
"click"
,
func
)
.
bind
(
"click"
,
func
)
.
unbind
(
"click"
,
func
)
.
unbind
(
"click"
,
func
)
.
click
(
)
.
trigger
(
"click"
)
.
unbind
(
"click"
);
.
unbind
(
"click"
);
});
});
...
@@ -778,7 +778,8 @@ test("unbind(eventObject)", function() {
...
@@ -778,7 +778,8 @@ test("unbind(eventObject)", function() {
assert
(
0
);
assert
(
0
);
});
});
test
(
"hover() mouseenter mouseleave"
,
function
()
{
if
(
jQuery
.
fn
.
hover
)
{
test
(
"hover() mouseenter mouseleave"
,
function
()
{
expect
(
1
);
expect
(
1
);
var
times
=
0
,
var
times
=
0
,
...
@@ -797,14 +798,15 @@ test("hover() mouseenter mouseleave", function() {
...
@@ -797,14 +798,15 @@ test("hover() mouseenter mouseleave", function() {
equal
(
times
,
4
,
"hover handlers fired"
);
equal
(
times
,
4
,
"hover handlers fired"
);
});
});
}
test
(
"mouseover triggers mouseenter"
,
function
()
{
test
(
"mouseover triggers mouseenter"
,
function
()
{
expect
(
1
);
expect
(
1
);
var
count
=
0
,
var
count
=
0
,
elem
=
jQuery
(
"<a />"
);
elem
=
jQuery
(
"<a />"
);
elem
.
mouseenter
(
function
()
{
elem
.
on
(
"mouseenter"
,
function
()
{
count
++
;
count
++
;
});
});
elem
.
trigger
(
"mouseover"
);
elem
.
trigger
(
"mouseover"
);
...
@@ -835,22 +837,26 @@ test("withinElement implemented with jQuery.contains()", function() {
...
@@ -835,22 +837,26 @@ test("withinElement implemented with jQuery.contains()", function() {
test
(
"mouseenter, mouseleave don't catch exceptions"
,
function
()
{
test
(
"mouseenter, mouseleave don't catch exceptions"
,
function
()
{
expect
(
2
);
expect
(
2
);
var
elem
=
jQuery
(
"#firstp"
).
hover
(
function
()
{
throw
"an Exception"
;
});
var
elem
=
jQuery
(
"#firstp"
).
on
(
"mouseenter mouseleave"
,
function
()
{
throw
"an Exception"
;
});
try
{
try
{
elem
.
mouseenter
(
);
elem
.
trigger
(
"mouseenter"
);
}
catch
(
e
)
{
}
catch
(
e
)
{
equal
(
e
,
"an Exception"
,
"mouseenter doesn't catch exceptions"
);
equal
(
e
,
"an Exception"
,
"mouseenter doesn't catch exceptions"
);
}
}
try
{
try
{
elem
.
mouseleave
(
);
elem
.
trigger
(
"mouseleave"
);
}
catch
(
e
)
{
}
catch
(
e
)
{
equal
(
e
,
"an Exception"
,
"mouseleave doesn't catch exceptions"
);
equal
(
e
,
"an Exception"
,
"mouseleave doesn't catch exceptions"
);
}
}
});
});
test
(
"trigger() shortcuts"
,
function
()
{
if
(
jQuery
.
fn
.
click
)
{
test
(
"trigger() shortcuts"
,
function
()
{
expect
(
6
);
expect
(
6
);
var
elem
=
jQuery
(
"<li><a href='#'>Change location</a></li>"
).
prependTo
(
"#firstUL"
);
var
elem
=
jQuery
(
"<li><a href='#'>Change location</a></li>"
).
prependTo
(
"#firstUL"
);
...
@@ -893,7 +899,9 @@ test("trigger() shortcuts", function() {
...
@@ -893,7 +899,9 @@ test("trigger() shortcuts", function() {
jQuery
(
"<xml:namespace ns='urn:schemas-microsoft-com:vml' prefix='v' />"
).
appendTo
(
"head"
);
jQuery
(
"<xml:namespace ns='urn:schemas-microsoft-com:vml' prefix='v' />"
).
appendTo
(
"head"
);
jQuery
(
"<v:oval id='oval' style='width:100pt;height:75pt;' fillcolor='red'> </v:oval>"
).
appendTo
(
"#form"
);
jQuery
(
"<v:oval id='oval' style='width:100pt;height:75pt;' fillcolor='red'> </v:oval>"
).
appendTo
(
"#form"
);
jQuery
(
"#oval"
).
click
().
keydown
();
jQuery
(
"#oval"
).
click
().
keydown
();
});
});
}
test
(
"trigger() bubbling"
,
function
()
{
test
(
"trigger() bubbling"
,
function
()
{
expect
(
18
);
expect
(
18
);
...
@@ -1007,7 +1015,7 @@ test("trigger(type, [data], [fn])", function() {
...
@@ -1007,7 +1015,7 @@ test("trigger(type, [data], [fn])", function() {
var
form
=
jQuery
(
"<form action=''></form>"
).
appendTo
(
"body"
);
var
form
=
jQuery
(
"<form action=''></form>"
).
appendTo
(
"body"
);
// Make sure it can be prevented locally
// Make sure it can be prevented locally
form
.
submit
(
function
(){
form
.
on
(
"submit"
,
function
(){
ok
(
true
,
"Local bind still works."
);
ok
(
true
,
"Local bind still works."
);
return
false
;
return
false
;
});
});
...
@@ -1017,7 +1025,7 @@ test("trigger(type, [data], [fn])", function() {
...
@@ -1017,7 +1025,7 @@ test("trigger(type, [data], [fn])", function() {
form
.
unbind
(
"submit"
);
form
.
unbind
(
"submit"
);
jQuery
(
document
).
submit
(
function
(){
jQuery
(
document
).
on
(
"submit"
,
function
(){
ok
(
true
,
"Make sure bubble works up to document."
);
ok
(
true
,
"Make sure bubble works up to document."
);
return
false
;
return
false
;
});
});
...
@@ -1050,7 +1058,7 @@ test( "submit event bubbles on copied forms (#11649)", function() {
...
@@ -1050,7 +1058,7 @@ test( "submit event bubbles on copied forms (#11649)", function() {
$fixture
.
on
(
"submit"
,
"form"
,
delegatedSubmit
);
$fixture
.
on
(
"submit"
,
"form"
,
delegatedSubmit
);
// Trigger form submission to introduce the _submit_attached property
// Trigger form submission to introduce the _submit_attached property
$testForm
.
on
(
"submit"
,
noSubmit
).
find
(
"input[name=sub1]"
).
click
(
);
$testForm
.
on
(
"submit"
,
noSubmit
).
find
(
"input[name=sub1]"
).
trigger
(
"click"
);
// Copy the form via .clone() and .html()
// Copy the form via .clone() and .html()
$formByClone
=
$testForm
.
clone
(
true
,
true
).
removeAttr
(
"id"
);
$formByClone
=
$testForm
.
clone
(
true
,
true
).
removeAttr
(
"id"
);
...
@@ -1058,7 +1066,7 @@ test( "submit event bubbles on copied forms (#11649)", function() {
...
@@ -1058,7 +1066,7 @@ test( "submit event bubbles on copied forms (#11649)", function() {
$wrapperDiv
.
append
(
$formByClone
,
$formByHTML
);
$wrapperDiv
.
append
(
$formByClone
,
$formByHTML
);
// Check submit bubbling on the copied forms
// Check submit bubbling on the copied forms
$wrapperDiv
.
find
(
"form"
).
on
(
"submit"
,
noSubmit
).
find
(
"input[name=sub1]"
).
click
(
);
$wrapperDiv
.
find
(
"form"
).
on
(
"submit"
,
noSubmit
).
find
(
"input[name=sub1]"
).
trigger
(
"click"
);
// Clean up
// Clean up
$wrapperDiv
.
remove
();
$wrapperDiv
.
remove
();
...
@@ -1083,7 +1091,7 @@ test( "change event bubbles on copied forms (#11796)", function(){
...
@@ -1083,7 +1091,7 @@ test( "change event bubbles on copied forms (#11796)", function(){
$fixture
.
on
(
"change"
,
"form"
,
delegatedChange
);
$fixture
.
on
(
"change"
,
"form"
,
delegatedChange
);
// Trigger change event to introduce the _change_attached property
// Trigger change event to introduce the _change_attached property
$form
.
find
(
"select[name=select1]"
).
val
(
"1"
).
change
(
);
$form
.
find
(
"select[name=select1]"
).
val
(
"1"
).
trigger
(
"change"
);
// Copy the form via .clone() and .html()
// Copy the form via .clone() and .html()
$formByClone
=
$form
.
clone
(
true
,
true
).
removeAttr
(
"id"
);
$formByClone
=
$form
.
clone
(
true
,
true
).
removeAttr
(
"id"
);
...
@@ -1091,7 +1099,7 @@ test( "change event bubbles on copied forms (#11796)", function(){
...
@@ -1091,7 +1099,7 @@ test( "change event bubbles on copied forms (#11796)", function(){
$wrapperDiv
.
append
(
$formByClone
,
$formByHTML
);
$wrapperDiv
.
append
(
$formByClone
,
$formByHTML
);
// Check change bubbling on the copied forms
// Check change bubbling on the copied forms
$wrapperDiv
.
find
(
"form select[name=select1]"
).
val
(
"2"
).
change
(
);
$wrapperDiv
.
find
(
"form select[name=select1]"
).
val
(
"2"
).
trigger
(
"change"
);
// Clean up
// Clean up
$wrapperDiv
.
remove
();
$wrapperDiv
.
remove
();
...
@@ -1203,7 +1211,7 @@ test(".trigger() bubbling on disconnected elements (#10489)", function() {
...
@@ -1203,7 +1211,7 @@ test(".trigger() bubbling on disconnected elements (#10489)", function() {
.
on
(
"click"
,
function
()
{
.
on
(
"click"
,
function
()
{
ok
(
true
,
"click fired on p"
);
ok
(
true
,
"click fired on p"
);
})
})
.
click
(
)
.
trigger
(
"click"
)
.
off
(
"click"
)
.
off
(
"click"
)
.
end
()
.
end
()
.
off
(
"click"
)
.
off
(
"click"
)
...
@@ -1470,7 +1478,7 @@ test("jQuery.Event.currentTarget", function(){
...
@@ -1470,7 +1478,7 @@ test("jQuery.Event.currentTarget", function(){
.
on
(
"click"
,
function
(
e
){
.
on
(
"click"
,
function
(
e
){
equal
(
e
.
currentTarget
,
this
,
"Check currentTarget on event"
);
equal
(
e
.
currentTarget
,
this
,
"Check currentTarget on event"
);
})
})
.
click
(
)
.
trigger
(
"click"
)
.
off
(
"click"
)
.
off
(
"click"
)
.
end
()
.
end
()
.
off
(
"click"
);
.
off
(
"click"
);
...
@@ -1666,7 +1674,7 @@ test(".delegate()/.undelegate()", function() {
...
@@ -1666,7 +1674,7 @@ test(".delegate()/.undelegate()", function() {
jQuery
(
"#body"
).
delegate
(
"#nothiddendivchild"
,
"click"
,
function
(
e
){
jQuery
(
"#nothiddendivchild"
).
html
(
""
);
});
jQuery
(
"#body"
).
delegate
(
"#nothiddendivchild"
,
"click"
,
function
(
e
){
jQuery
(
"#nothiddendivchild"
).
html
(
""
);
});
jQuery
(
"#body"
).
delegate
(
"#nothiddendivchild"
,
"click"
,
function
(
e
){
if
(
e
.
target
)
{
livec
++
;}
});
jQuery
(
"#body"
).
delegate
(
"#nothiddendivchild"
,
"click"
,
function
(
e
){
if
(
e
.
target
)
{
livec
++
;}
});
jQuery
(
"#nothiddendiv span"
).
click
(
);
jQuery
(
"#nothiddendiv span"
).
trigger
(
"click"
);
equal
(
jQuery
(
"#nothiddendiv span"
).
length
,
0
,
"Verify that first handler occurred and modified the DOM."
);
equal
(
jQuery
(
"#nothiddendiv span"
).
length
,
0
,
"Verify that first handler occurred and modified the DOM."
);
equal
(
livec
,
1
,
"Verify that second handler occurred even with nuked target."
);
equal
(
livec
,
1
,
"Verify that second handler occurred even with nuked target."
);
...
@@ -1681,7 +1689,7 @@ test(".delegate()/.undelegate()", function() {
...
@@ -1681,7 +1689,7 @@ test(".delegate()/.undelegate()", function() {
jQuery
(
"#body"
).
delegate
(
"span#liveSpan1 a"
,
"click"
,
function
(){
lived
++
;
return
false
;
});
jQuery
(
"#body"
).
delegate
(
"span#liveSpan1 a"
,
"click"
,
function
(){
lived
++
;
return
false
;
});
jQuery
(
"#body"
).
delegate
(
"span#liveSpan1"
,
"click"
,
function
(){
livee
++
;
});
jQuery
(
"#body"
).
delegate
(
"span#liveSpan1"
,
"click"
,
function
(){
livee
++
;
});
jQuery
(
"span#liveSpan1 a"
).
click
(
);
jQuery
(
"span#liveSpan1 a"
).
trigger
(
"click"
);
equal
(
lived
,
1
,
"Verify that only one first handler occurred."
);
equal
(
lived
,
1
,
"Verify that only one first handler occurred."
);
equal
(
livee
,
0
,
"Verify that second handler doesn't."
);
equal
(
livee
,
0
,
"Verify that second handler doesn't."
);
...
@@ -1691,7 +1699,7 @@ test(".delegate()/.undelegate()", function() {
...
@@ -1691,7 +1699,7 @@ test(".delegate()/.undelegate()", function() {
lived
=
0
;
lived
=
0
;
livee
=
0
;
livee
=
0
;
jQuery
(
"span#liveSpan2 a"
).
click
(
);
jQuery
(
"span#liveSpan2 a"
).
trigger
(
"click"
);
equal
(
lived
,
1
,
"Verify that only one first handler occurred."
);
equal
(
lived
,
1
,
"Verify that only one first handler occurred."
);
equal
(
livee
,
0
,
"Verify that second handler doesn't."
);
equal
(
livee
,
0
,
"Verify that second handler doesn't."
);
...
@@ -1706,7 +1714,7 @@ test(".delegate()/.undelegate()", function() {
...
@@ -1706,7 +1714,7 @@ test(".delegate()/.undelegate()", function() {
equal
(
e
.
target
.
nodeName
.
toUpperCase
(),
"A"
,
"Check the event.target within a delegate handler"
);
equal
(
e
.
target
.
nodeName
.
toUpperCase
(),
"A"
,
"Check the event.target within a delegate handler"
);
});
});
jQuery
(
"span#liveSpan1 a"
).
click
(
);
jQuery
(
"span#liveSpan1 a"
).
trigger
(
"click"
);
jQuery
(
"#body"
).
undelegate
(
"span#liveSpan1"
,
"click"
);
jQuery
(
"#body"
).
undelegate
(
"span#liveSpan1"
,
"click"
);
...
@@ -1758,7 +1766,7 @@ test("jQuery.off using dispatched jQuery.Event", function() {
...
@@ -1758,7 +1766,7 @@ test("jQuery.off using dispatched jQuery.Event", function() {
equal
(
++
count
,
1
,
"event called once before removal"
);
equal
(
++
count
,
1
,
"event called once before removal"
);
jQuery
().
off
(
event
);
jQuery
().
off
(
event
);
})
})
.
find
(
"a"
).
click
().
click
(
).
end
()
.
find
(
"a"
).
trigger
(
"click"
).
trigger
(
"click"
).
end
()
.
remove
();
.
remove
();
});
});
...
@@ -1776,7 +1784,7 @@ test( "delegated event with delegateTarget-relative selector", function() {
...
@@ -1776,7 +1784,7 @@ test( "delegated event with delegateTarget-relative selector", function() {
ok
(
this
.
id
===
"a0_0"
,
"first li under #u10 was clicked"
);
ok
(
this
.
id
===
"a0_0"
,
"first li under #u10 was clicked"
);
})
})
.
end
()
.
end
()
.
find
(
"a"
).
click
(
).
end
()
.
find
(
"a"
).
trigger
(
"click"
).
end
()
.
find
(
"#ul0"
).
off
();
.
find
(
"#ul0"
).
off
();
// Non-positional selector (#12383)
// Non-positional selector (#12383)
...
@@ -1792,7 +1800,7 @@ test( "delegated event with delegateTarget-relative selector", function() {
...
@@ -1792,7 +1800,7 @@ test( "delegated event with delegateTarget-relative selector", function() {
.
on
(
"click"
,
"li.test a"
,
function
()
{
.
on
(
"click"
,
"li.test a"
,
function
()
{
ok
(
true
,
"li.test is below the delegation point."
);
ok
(
true
,
"li.test is below the delegation point."
);
})
})
.
find
(
"#a0_0"
).
click
(
);
.
find
(
"#a0_0"
).
trigger
(
"click"
);
markup
.
remove
();
markup
.
remove
();
});
});
...
@@ -1823,7 +1831,7 @@ test("stopPropagation() stops directly-bound events on delegated target", functi
...
@@ -1823,7 +1831,7 @@ test("stopPropagation() stops directly-bound events on delegated target", functi
e
.
stopPropagation
();
e
.
stopPropagation
();
ok
(
true
,
"delegated handler was called"
);
ok
(
true
,
"delegated handler was called"
);
})
})
.
find
(
"a"
).
click
(
).
end
()
.
find
(
"a"
).
trigger
(
"click"
).
end
()
.
remove
();
.
remove
();
});
});
...
@@ -1959,7 +1967,7 @@ test("delegate with submit", function() {
...
@@ -1959,7 +1967,7 @@ test("delegate with submit", function() {
ev
.
preventDefault
();
ev
.
preventDefault
();
});
});
jQuery
(
"#testForm input[name=sub1]"
).
submit
(
);
jQuery
(
"#testForm input[name=sub1]"
).
trigger
(
"submit"
);
equal
(
count1
,
1
,
"Verify form submit."
);
equal
(
count1
,
1
,
"Verify form submit."
);
equal
(
count2
,
1
,
"Verify body submit."
);
equal
(
count2
,
1
,
"Verify body submit."
);
...
@@ -2004,24 +2012,24 @@ test("inline handler returning false stops default", function() {
...
@@ -2004,24 +2012,24 @@ test("inline handler returning false stops default", function() {
expect
(
1
);
expect
(
1
);
var
markup
=
jQuery
(
"<div><a href=
\"
#
\"
onclick=
\"
return false
\"
>x</a></div>"
);
var
markup
=
jQuery
(
"<div><a href=
\"
#
\"
onclick=
\"
return false
\"
>x</a></div>"
);
markup
.
click
(
function
(
e
)
{
markup
.
on
(
"click"
,
function
(
e
)
{
ok
(
e
.
isDefaultPrevented
(),
"inline handler prevented default"
);
ok
(
e
.
isDefaultPrevented
(),
"inline handler prevented default"
);
return
false
;
return
false
;
});
});
markup
.
find
(
"a"
).
click
(
);
markup
.
find
(
"a"
).
trigger
(
"click"
);
markup
.
off
(
"click"
);
markup
.
off
(
"click"
);
});
});
test
(
"window resize"
,
function
()
{
test
(
"window resize"
,
function
()
{
expect
(
2
);
expect
(
2
);
jQuery
(
window
).
unbind
();
jQuery
(
window
).
off
();
jQuery
(
window
).
bind
(
"resize"
,
function
(){
jQuery
(
window
).
on
(
"resize"
,
function
(){
ok
(
true
,
"Resize event fired."
);
ok
(
true
,
"Resize event fired."
);
}).
resize
().
unbind
(
"resize"
);
}).
trigger
(
"resize"
).
off
(
"resize"
);
ok
(
!
jQuery
.
_data
(
window
,
"
__events__
"
),
"Make sure all the events are gone."
);
ok
(
!
jQuery
.
_data
(
window
,
"
events
"
),
"Make sure all the events are gone."
);
});
});
test
(
"focusin bubbles"
,
function
()
{
test
(
"focusin bubbles"
,
function
()
{
...
@@ -2095,7 +2103,7 @@ test(".on and .off", function() {
...
@@ -2095,7 +2103,7 @@ test(".on and .off", function() {
.
one
(
"click"
,
7
,
function
(
e
,
trig
)
{
.
one
(
"click"
,
7
,
function
(
e
,
trig
)
{
counter
+=
e
.
data
+
(
trig
||
11
);
// once, 7+11=18
counter
+=
e
.
data
+
(
trig
||
11
);
// once, 7+11=18
})
})
.
click
(
)
.
trigger
(
"click"
)
.
trigger
(
"click"
,
17
)
.
trigger
(
"click"
,
17
)
.
off
(
"click"
);
.
off
(
"click"
);
equal
(
counter
,
54
,
"direct event bindings with data"
);
equal
(
counter
,
54
,
"direct event bindings with data"
);
...
@@ -2110,7 +2118,7 @@ test(".on and .off", function() {
...
@@ -2110,7 +2118,7 @@ test(".on and .off", function() {
counter
+=
e
.
data
+
(
trig
||
11
);
// once, 7+11=18
counter
+=
e
.
data
+
(
trig
||
11
);
// once, 7+11=18
})
})
.
find
(
"em"
)
.
find
(
"em"
)
.
click
(
)
.
trigger
(
"click"
)
.
trigger
(
"click"
,
17
)
.
trigger
(
"click"
,
17
)
.
end
()
.
end
()
.
off
(
"click"
,
"em"
);
.
off
(
"click"
,
"em"
);
...
@@ -2295,7 +2303,7 @@ test("clone() delegated events (#11076)", function() {
...
@@ -2295,7 +2303,7 @@ test("clone() delegated events (#11076)", function() {
.
on
(
"click"
,
"td:last-child"
,
clicked
),
.
on
(
"click"
,
"td:last-child"
,
clicked
),
clone
=
table
.
clone
(
true
);
clone
=
table
.
clone
(
true
);
clone
.
find
(
"td"
).
click
(
);
clone
.
find
(
"td"
).
trigger
(
"click"
);
equal
(
counter
[
"center"
],
1
,
"first child"
);
equal
(
counter
[
"center"
],
1
,
"first child"
);
equal
(
counter
[
"fold"
],
1
,
"last child"
);
equal
(
counter
[
"fold"
],
1
,
"last child"
);
equal
(
counter
[
"centerfold"
],
2
,
"all children"
);
equal
(
counter
[
"centerfold"
],
2
,
"all children"
);
...
@@ -2326,7 +2334,7 @@ test("checkbox state (#3827)", function() {
...
@@ -2326,7 +2334,7 @@ test("checkbox state (#3827)", function() {
// jQuery click
// jQuery click
cb
.
checked
=
true
;
cb
.
checked
=
true
;
equal
(
cb
.
checked
,
true
,
"jQuery - checkbox is initially checked"
);
equal
(
cb
.
checked
,
true
,
"jQuery - checkbox is initially checked"
);
jQuery
(
cb
).
click
(
);
jQuery
(
cb
).
trigger
(
"click"
);
equal
(
cb
.
checked
,
false
,
"jQuery - checkbox is no longer checked"
);
equal
(
cb
.
checked
,
false
,
"jQuery - checkbox is no longer checked"
);
// Handlers only; checkbox state remains false
// Handlers only; checkbox state remains false
...
@@ -2337,7 +2345,7 @@ test("focus-blur order (#12868)", function() {
...
@@ -2337,7 +2345,7 @@ test("focus-blur order (#12868)", function() {
expect
(
5
);
expect
(
5
);
var
$text
=
jQuery
(
"#text1"
),
var
$text
=
jQuery
(
"#text1"
),
$radio
=
jQuery
(
"#radio1"
).
focus
(
),
$radio
=
jQuery
(
"#radio1"
).
trigger
(
"focus"
),
order
;
order
;
// IE6-10 fire focus/blur events asynchronously; this is the resulting mess.
// IE6-10 fire focus/blur events asynchronously; this is the resulting mess.
...
@@ -2365,7 +2373,7 @@ test("focus-blur order (#12868)", function() {
...
@@ -2365,7 +2373,7 @@ test("focus-blur order (#12868)", function() {
// Enabled input getting focus
// Enabled input getting focus
order
=
0
;
order
=
0
;
equal
(
document
.
activeElement
,
$radio
[
0
],
"radio has focus"
);
equal
(
document
.
activeElement
,
$radio
[
0
],
"radio has focus"
);
$text
.
focus
(
);
$text
.
trigger
(
"focus"
);
setTimeout
(
function
()
{
setTimeout
(
function
()
{
equal
(
document
.
activeElement
,
$text
[
0
],
"text has focus"
);
equal
(
document
.
activeElement
,
$text
[
0
],
"text has focus"
);
...
@@ -2601,7 +2609,7 @@ test( "make sure events cloned correctly", 18, function() {
...
@@ -2601,7 +2609,7 @@ test( "make sure events cloned correctly", 18, function() {
ok
(
true
,
"Change on original child element is fired"
);
ok
(
true
,
"Change on original child element is fired"
);
});
});
fixture
.
clone
().
click
().
change
(
);
// 0 events should be fired
fixture
.
clone
().
trigger
(
"click"
).
trigger
(
"change"
);
// 0 events should be fired
clone
=
fixture
.
clone
(
true
);
clone
=
fixture
.
clone
(
true
);
...
@@ -2617,15 +2625,15 @@ test( "make sure events cloned correctly", 18, function() {
...
@@ -2617,15 +2625,15 @@ test( "make sure events cloned correctly", 18, function() {
p
.
off
();
p
.
off
();
checkbox
.
off
();
checkbox
.
off
();
p
.
click
(
);
// 0 should be fired
p
.
trigger
(
"click"
);
// 0 should be fired
checkbox
.
change
(
);
// 0 should be fired
checkbox
.
trigger
(
"change"
);
// 0 should be fired
clone
.
find
(
"p:first"
).
trigger
(
"click"
,
true
);
// 3 events should fire
clone
.
find
(
"p:first"
).
trigger
(
"click"
,
true
);
// 3 events should fire
clone
.
find
(
"#check1"
).
trigger
(
"change"
,
true
);
// 3 events should fire
clone
.
find
(
"#check1"
).
trigger
(
"change"
,
true
);
// 3 events should fire
clone
.
remove
();
clone
.
remove
();
clone
.
find
(
"p:first"
).
click
();
// 0 should be fired
clone
.
find
(
"p:first"
).
trigger
(
"click"
);
// 0 should be fired
clone
.
find
(
"#check1"
).
change
(
);
// 0 events should fire
clone
.
find
(
"#check1"
).
trigger
(
"change"
);
// 0 events should fire
});
});
test
(
"Check order of focusin/focusout events"
,
2
,
function
()
{
test
(
"Check order of focusin/focusout events"
,
2
,
function
()
{
...
@@ -2646,10 +2654,10 @@ test( "Check order of focusin/focusout events", 2, function() {
...
@@ -2646,10 +2654,10 @@ test( "Check order of focusin/focusout events", 2, function() {
});
});
// gain focus
// gain focus
input
.
focus
(
);
input
.
trigger
(
"focus"
);
// then lose it
// then lose it
jQuery
(
"#search"
).
focus
(
);
jQuery
(
"#search"
).
trigger
(
"focus"
);
// cleanup
// cleanup
input
.
off
();
input
.
off
();
...
...
test/unit/manipulation.js
View file @
6f7b6915
...
@@ -121,7 +121,7 @@ var testWrap = function( val ) {
...
@@ -121,7 +121,7 @@ var testWrap = function( val ) {
equal
(
result
.
text
(),
defaultText
,
"Check for element wrapping"
);
equal
(
result
.
text
(),
defaultText
,
"Check for element wrapping"
);
QUnit
.
reset
();
QUnit
.
reset
();
jQuery
(
"#check1"
).
click
(
function
()
{
jQuery
(
"#check1"
).
on
(
"click"
,
function
()
{
var
checkbox
=
this
;
var
checkbox
=
this
;
ok
(
checkbox
.
checked
,
"Checkbox's state is erased after wrap() action, see #769"
);
ok
(
checkbox
.
checked
,
"Checkbox's state is erased after wrap() action, see #769"
);
...
@@ -168,7 +168,7 @@ var testWrap = function( val ) {
...
@@ -168,7 +168,7 @@ var testWrap = function( val ) {
equal
(
j
[
0
].
parentNode
.
nodeName
.
toLowerCase
(),
"div"
,
"Wrapping works."
);
equal
(
j
[
0
].
parentNode
.
nodeName
.
toLowerCase
(),
"div"
,
"Wrapping works."
);
// Wrap an element with a jQuery set and event
// Wrap an element with a jQuery set and event
result
=
jQuery
(
"<div></div>"
).
click
(
function
()
{
result
=
jQuery
(
"<div></div>"
).
on
(
"click"
,
function
()
{
ok
(
true
,
"Event triggered."
);
ok
(
true
,
"Event triggered."
);
// Remove handlers on detached elements
// Remove handlers on detached elements
...
@@ -493,7 +493,7 @@ var testAppend = function( valueObj ) {
...
@@ -493,7 +493,7 @@ var testAppend = function( valueObj ) {
$radioChecked
=
jQuery
(
"input:radio[name='R1']"
).
eq
(
1
);
$radioChecked
=
jQuery
(
"input:radio[name='R1']"
).
eq
(
1
);
$radioParent
=
$radioChecked
.
parent
();
$radioParent
=
$radioChecked
.
parent
();
$radioUnchecked
=
jQuery
(
"<input type='radio' name='R1' checked='checked'/>"
).
appendTo
(
$radioParent
);
$radioUnchecked
=
jQuery
(
"<input type='radio' name='R1' checked='checked'/>"
).
appendTo
(
$radioParent
);
$radioChecked
.
click
(
);
$radioChecked
.
trigger
(
"click"
);
$radioUnchecked
[
0
].
checked
=
false
;
$radioUnchecked
[
0
].
checked
=
false
;
$radioParent
.
wrap
(
"<div></div>"
);
$radioParent
.
wrap
(
"<div></div>"
);
equal
(
$radioChecked
[
0
].
checked
,
true
,
"Reappending radios uphold which radio is checked"
);
equal
(
$radioChecked
[
0
].
checked
,
true
,
"Reappending radios uphold which radio is checked"
);
...
@@ -766,13 +766,13 @@ test( "appendTo(String|Element|Array<Element>|jQuery)", function() {
...
@@ -766,13 +766,13 @@ test( "appendTo(String|Element|Array<Element>|jQuery)", function() {
t
(
"Append select"
,
"#foo select"
,
[
"select1"
]
);
t
(
"Append select"
,
"#foo select"
,
[
"select1"
]
);
QUnit
.
reset
();
QUnit
.
reset
();
div
=
jQuery
(
"<div/>"
).
click
(
function
()
{
div
=
jQuery
(
"<div/>"
).
on
(
"click"
,
function
()
{
ok
(
true
,
"Running a cloned click."
);
ok
(
true
,
"Running a cloned click."
);
});
});
div
.
appendTo
(
"#qunit-fixture, #moretests"
);
div
.
appendTo
(
"#qunit-fixture, #moretests"
);
jQuery
(
"#qunit-fixture div:last"
).
click
(
);
jQuery
(
"#qunit-fixture div:last"
).
trigger
(
"click"
);
jQuery
(
"#moretests div:last"
).
click
(
);
jQuery
(
"#moretests div:last"
).
trigger
(
"click"
);
QUnit
.
reset
();
QUnit
.
reset
();
div
=
jQuery
(
"<div/>"
).
appendTo
(
"#qunit-fixture, #moretests"
);
div
=
jQuery
(
"<div/>"
).
appendTo
(
"#qunit-fixture, #moretests"
);
...
@@ -1139,35 +1139,35 @@ var testReplaceWith = function( val ) {
...
@@ -1139,35 +1139,35 @@ var testReplaceWith = function( val ) {
deepEqual
(
jQuery
(
"#anchor1"
).
contents
().
get
(),
[
tmp
],
"Replace text node with element"
);
deepEqual
(
jQuery
(
"#anchor1"
).
contents
().
get
(),
[
tmp
],
"Replace text node with element"
);
tmp
=
jQuery
(
"<div/>"
).
appendTo
(
"#qunit-fixture"
).
click
(
function
()
{
tmp
=
jQuery
(
"<div/>"
).
appendTo
(
"#qunit-fixture"
).
on
(
"click"
,
function
()
{
ok
(
true
,
"Newly bound click run."
);
ok
(
true
,
"Newly bound click run."
);
});
});
y
=
jQuery
(
"<div/>"
).
appendTo
(
"#qunit-fixture"
).
click
(
function
()
{
y
=
jQuery
(
"<div/>"
).
appendTo
(
"#qunit-fixture"
).
on
(
"click"
,
function
()
{
ok
(
false
,
"Previously bound click run."
);
ok
(
false
,
"Previously bound click run."
);
});
});
child
=
y
.
append
(
"<b>test</b>"
).
find
(
"b"
).
click
(
function
()
{
child
=
y
.
append
(
"<b>test</b>"
).
find
(
"b"
).
on
(
"click"
,
function
()
{
ok
(
true
,
"Child bound click run."
);
ok
(
true
,
"Child bound click run."
);
return
false
;
return
false
;
});
});
y
.
replaceWith
(
val
(
tmp
)
);
y
.
replaceWith
(
val
(
tmp
)
);
tmp
.
click
(
);
tmp
.
trigger
(
"click"
);
y
.
click
(
);
// Shouldn't be run
y
.
trigger
(
"click"
);
// Shouldn't be run
child
.
click
(
);
// Shouldn't be run
child
.
trigger
(
"click"
);
// Shouldn't be run
y
=
jQuery
(
"<div/>"
).
appendTo
(
"#qunit-fixture"
).
click
(
function
()
{
y
=
jQuery
(
"<div/>"
).
appendTo
(
"#qunit-fixture"
).
on
(
"click"
,
function
()
{
ok
(
false
,
"Previously bound click run."
);
ok
(
false
,
"Previously bound click run."
);
});
});
child2
=
y
.
append
(
"<u>test</u>"
).
find
(
"u"
).
click
(
function
()
{
child2
=
y
.
append
(
"<u>test</u>"
).
find
(
"u"
).
on
(
"click"
,
function
()
{
ok
(
true
,
"Child 2 bound click run."
);
ok
(
true
,
"Child 2 bound click run."
);
return
false
;
return
false
;
});
});
y
.
replaceWith
(
val
(
child2
)
);
y
.
replaceWith
(
val
(
child2
)
);
child2
.
click
(
);
child2
.
trigger
(
"click"
);
set
=
jQuery
(
"<div/>"
).
replaceWith
(
val
(
"<span>test</span>"
)
);
set
=
jQuery
(
"<div/>"
).
replaceWith
(
val
(
"<span>test</span>"
)
);
...
@@ -1287,7 +1287,7 @@ test( "clone()", function() {
...
@@ -1287,7 +1287,7 @@ test( "clone()", function() {
equal
(
jQuery
(
"#nonnodes"
).
contents
().
clone
().
length
,
3
,
"Check node,textnode,comment clone works (some browsers delete comments on clone)"
);
equal
(
jQuery
(
"#nonnodes"
).
contents
().
clone
().
length
,
3
,
"Check node,textnode,comment clone works (some browsers delete comments on clone)"
);
// Verify that clones of clones can keep event listeners
// Verify that clones of clones can keep event listeners
div
=
jQuery
(
"<div><ul><li>test</li></ul></div>"
).
click
(
function
()
{
div
=
jQuery
(
"<div><ul><li>test</li></ul></div>"
).
on
(
"click"
,
function
()
{
ok
(
true
,
"Bound event still exists."
);
ok
(
true
,
"Bound event still exists."
);
});
});
clone
=
div
.
clone
(
true
);
div
.
remove
();
clone
=
div
.
clone
(
true
);
div
.
remove
();
...
@@ -1302,7 +1302,7 @@ test( "clone()", function() {
...
@@ -1302,7 +1302,7 @@ test( "clone()", function() {
// Verify that cloned children can keep event listeners
// Verify that cloned children can keep event listeners
div
=
jQuery
(
"<div/>"
).
append
([
document
.
createElement
(
"table"
),
document
.
createElement
(
"table"
)
]);
div
=
jQuery
(
"<div/>"
).
append
([
document
.
createElement
(
"table"
),
document
.
createElement
(
"table"
)
]);
div
.
find
(
"table"
).
click
(
function
()
{
div
.
find
(
"table"
).
on
(
"click"
,
function
()
{
ok
(
true
,
"Bound event still exists."
);
ok
(
true
,
"Bound event still exists."
);
});
});
...
@@ -1316,7 +1316,7 @@ test( "clone()", function() {
...
@@ -1316,7 +1316,7 @@ test( "clone()", function() {
clone
.
remove
();
clone
.
remove
();
// Make sure that doing .clone() doesn't clone event listeners
// Make sure that doing .clone() doesn't clone event listeners
div
=
jQuery
(
"<div><ul><li>test</li></ul></div>"
).
click
(
function
()
{
div
=
jQuery
(
"<div><ul><li>test</li></ul></div>"
).
on
(
"click"
,
function
()
{
ok
(
false
,
"Bound event still exists after .clone()."
);
ok
(
false
,
"Bound event still exists after .clone()."
);
});
});
clone
=
div
.
clone
();
clone
=
div
.
clone
();
...
@@ -1734,9 +1734,9 @@ test( "remove() event cleaning ", 1, function() {
...
@@ -1734,9 +1734,9 @@ test( "remove() event cleaning ", 1, function() {
count
=
0
;
count
=
0
;
first
=
jQuery
(
"#ap"
).
children
(
":first"
);
first
=
jQuery
(
"#ap"
).
children
(
":first"
);
cleanUp
=
first
.
click
(
function
()
{
cleanUp
=
first
.
on
(
"click"
,
function
()
{
count
++
;
count
++
;
}).
remove
().
appendTo
(
"#qunit-fixture"
).
click
(
);
}).
remove
().
appendTo
(
"#qunit-fixture"
).
trigger
(
"click"
);
strictEqual
(
0
,
count
,
"Event handler has been removed"
);
strictEqual
(
0
,
count
,
"Event handler has been removed"
);
...
@@ -1753,9 +1753,9 @@ test( "detach() event cleaning ", 1, function() {
...
@@ -1753,9 +1753,9 @@ test( "detach() event cleaning ", 1, function() {
count
=
0
;
count
=
0
;
first
=
jQuery
(
"#ap"
).
children
(
":first"
);
first
=
jQuery
(
"#ap"
).
children
(
":first"
);
cleanUp
=
first
.
click
(
function
()
{
cleanUp
=
first
.
on
(
"click"
,
function
()
{
count
++
;
count
++
;
}).
detach
().
appendTo
(
"#qunit-fixture"
).
click
(
);
}).
detach
().
appendTo
(
"#qunit-fixture"
).
trigger
(
"click"
);
strictEqual
(
1
,
count
,
"Event handler has not been removed"
);
strictEqual
(
1
,
count
,
"Event handler has not been removed"
);
...
@@ -1832,13 +1832,13 @@ test( "jQuery.cleanData", function() {
...
@@ -1832,13 +1832,13 @@ test( "jQuery.cleanData", function() {
div
.
remove
();
div
.
remove
();
function
getDiv
()
{
function
getDiv
()
{
var
div
=
jQuery
(
"<div class='outer'><div class='inner'></div></div>"
).
click
(
function
()
{
var
div
=
jQuery
(
"<div class='outer'><div class='inner'></div></div>"
).
on
(
"click"
,
function
()
{
ok
(
true
,
type
+
" "
+
pos
+
" Click event fired."
);
ok
(
true
,
type
+
" "
+
pos
+
" Click event fired."
);
}).
focus
(
function
()
{
}).
on
(
"focus"
,
function
()
{
ok
(
true
,
type
+
" "
+
pos
+
" Focus event fired."
);
ok
(
true
,
type
+
" "
+
pos
+
" Focus event fired."
);
}).
find
(
"div"
).
click
(
function
()
{
}).
find
(
"div"
).
on
(
"click"
,
function
()
{
ok
(
false
,
type
+
" "
+
pos
+
" Click event fired."
);
ok
(
false
,
type
+
" "
+
pos
+
" Click event fired."
);
}).
focus
(
function
()
{
}).
on
(
"focus"
,
function
()
{
ok
(
false
,
type
+
" "
+
pos
+
" Focus event fired."
);
ok
(
false
,
type
+
" "
+
pos
+
" Focus event fired."
);
}).
end
().
appendTo
(
"body"
);
}).
end
().
appendTo
(
"body"
);
...
...
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