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
d74c6bd0
Commit
d74c6bd0
authored
Aug 02, 2011
by
Dave Methvin
Committed by
timmywil
Sep 19, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for quickIs cases and fix the regexp as a result.
parent
03f99ff9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
9 deletions
+41
-9
event.js
src/event.js
+4
-4
event.js
test/unit/event.js
+37
-5
No files found.
src/event.js
View file @
d74c6bd0
...
@@ -7,7 +7,7 @@ var rnamespaces = /\.(.*)$/,
...
@@ -7,7 +7,7 @@ var rnamespaces = /\.(.*)$/,
rescape
=
/
[^\w\s
.|`
]
/g
,
rescape
=
/
[^\w\s
.|`
]
/g
,
rtypenamespace
=
/^
([^\.]
*
)?(?:\.(
.+
))?
$/
,
rtypenamespace
=
/^
([^\.]
*
)?(?:\.(
.+
))?
$/
,
rhoverHack
=
/
\b
hover
(\.\S
+
)?
/
,
rhoverHack
=
/
\b
hover
(\.\S
+
)?
/
,
rquickIs
=
/^
([\w\-]
+
)?(?:
#
([\w\-]
+
))?(?:\.([\w\-]
+
))?(?:\[([\w
+
\-]
+
)
=
[
"'
]?([\w\-]
*
)[
"'
]?\])(
:first-child|:last-child|:empty
)?
$/
,
rquickIs
=
/^
([\w\-]
+
)?(?:
#
([\w\-]
+
))?(?:\.([\w\-]
+
))?(?:\[([\w
+
\-]
+
)
=
[
"'
]?([\w\-]
*
)[
"'
]?\])
?
(
:first-child|:last-child|:empty
)?
$/
,
delegateTypeMap
=
{
delegateTypeMap
=
{
focus
:
"focusin"
,
focus
:
"focusin"
,
blur
:
"focusout"
,
blur
:
"focusout"
,
...
@@ -69,12 +69,12 @@ jQuery.event = {
...
@@ -69,12 +69,12 @@ jQuery.event = {
// Handle multiple events separated by a space
// Handle multiple events separated by a space
// jQuery(...).bind("mouseover mouseout", fn);
// jQuery(...).bind("mouseover mouseout", fn);
types
=
types
.
replace
(
rhoverHack
,
"mouseover$1 mouseout$1"
).
split
(
" "
);
types
=
types
.
replace
(
rhoverHack
,
"mouseover$1 mouseout$1"
).
split
(
" "
);
for
(
t
=
0
;
t
<
types
.
length
;
t
++
)
{
for
(
t
=
0
;
t
<
types
.
length
;
t
++
)
{
tns
=
rtypenamespace
.
exec
(
types
[
t
]
)
||
[];
tns
=
rtypenamespace
.
exec
(
types
[
t
]
)
||
[];
type
=
tns
[
1
];
type
=
tns
[
1
];
namespaces
=
(
tns
[
2
]
||
""
).
split
(
"."
).
sort
();
namespaces
=
(
tns
[
2
]
||
""
).
split
(
"."
).
sort
();
handleObj
=
jQuery
.
extend
({
handleObj
=
jQuery
.
extend
({
type
:
type
,
type
:
type
,
data
:
data
,
data
:
data
,
...
@@ -112,7 +112,7 @@ jQuery.event = {
...
@@ -112,7 +112,7 @@ jQuery.event = {
}
}
// Pre-analyze selector so we can process it quickly on event dispatch
// Pre-analyze selector so we can process it quickly on event dispatch
quick
=
handleObj
.
quick
=
rquickIs
.
exec
(
selector
);
quick
=
handleObj
.
quick
=
rquickIs
.
exec
(
selector
);
if
(
quick
)
{
if
(
quick
)
{
// 0 1 2 3 4 5 6
// 0 1 2 3 4 5 6
// [ _, tag, id, class, attrName, attrValue, pseudo(:empty :first-child :last-child) ]
// [ _, tag, id, class, attrName, attrValue, pseudo(:empty :first-child :last-child) ]
...
...
test/unit/event.js
View file @
d74c6bd0
...
@@ -2306,12 +2306,44 @@ test(".on and .off", function() {
...
@@ -2306,12 +2306,44 @@ test(".on and .off", function() {
});
});
test
(
"delegated events quickIs"
,
function
()
{
test
(
"delegated events quickIs"
,
function
()
{
expect
(
1
);
expect
(
23
);
ok
(
false
,
"write a unit test you lazy slob!"
);
var
markup
=
jQuery
(
'<div#quickis><p class="D">dead<b devo="cool">beat</b>club</p><quote id="famous">worked<em>or</em>borked?<em></em></quote></div>'
),
//TODO: specific unit tests for quickIs selector cases
str
,
//TODO: make a test to ensure == matches the null returned by getAttribute for [name]
check
=
function
(
el
,
expect
){
//ALSO: will quick[5] return undefined in all regexp impls? If not fix it
str
=
""
;
markup
.
find
(
el
).
trigger
(
"blink"
);
equals
(
str
,
expect
,
"On "
+
el
);
},
func
=
function
(
e
){
var
tag
=
this
.
nodeName
.
toLowerCase
();
str
+=
(
str
&&
" "
)
+
tag
+
"|"
+
e
.
handleObj
.
selector
;
ok
(
e
.
handleObj
.
quick
,
"Selector "
+
e
.
handleObj
.
selector
+
" on "
+
tag
+
" is a quickIs case"
);
};
// tag#id.class[name=value]
markup
.
appendTo
(
"body "
)
.
on
(
"blink"
,
"em"
,
func
)
.
on
(
"blink"
,
".D"
,
func
)
.
on
(
"blink"
,
".d"
,
func
)
.
on
(
"blink"
,
"p.d"
,
func
)
.
on
(
"blink"
,
"[devo=cool]"
,
func
)
.
on
(
"blink"
,
"[devo='NO']"
,
func
)
.
on
(
"blink"
,
"#famous"
,
func
)
.
on
(
"blink"
,
"em:empty"
,
func
)
.
on
(
"blink"
,
":first-child"
,
func
)
.
on
(
"blink"
,
"em:last-child"
,
func
);
check
(
"[devo=cool]"
,
"b|[devo=cool] p|.D p|:first-child"
);
check
(
"[devo='']"
,
""
);
check
(
"p"
,
"p|.D p|:first-child"
);
check
(
"b"
,
"b|[devo=cool] p|.D p|:first-child"
);
check
(
"em"
,
"em|em quote|#famous em|em em|em:empty em|em:last-child quote|#famous"
);
markup
.
find
(
"b"
).
attr
(
"devo"
,
"NO"
);
check
(
"b"
,
"b|[devo='NO'] p|.D p|:first-child"
);
markup
.
remove
();
});
});
...
...
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