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
Expand all
Hide 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 ) {
{
flag
:
"css"
,
src
:
"src/css.js"
},
"src/serialize.js"
,
{
flag
:
"event-alias"
,
src
:
"src/event-alias.js"
},
{
flag
:
"ajax"
,
src
:
"src/ajax.js"
},
{
flag
:
"ajax/script"
,
src
:
"src/ajax/script.js"
,
needs
:
[
"ajax"
]
},
{
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,10 +481,18 @@ jQuery.event = {
}
// Create a writable copy of the event object and normalize some properties
var
i
,
prop
,
var
i
,
prop
,
copy
,
type
=
event
.
type
,
originalEvent
=
event
,
fixHook
=
jQuery
.
event
.
fixHooks
[
event
.
type
]
||
{},
copy
=
fixHook
.
props
?
this
.
props
.
concat
(
fixHook
.
props
)
:
this
.
props
;
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
;
event
=
new
jQuery
.
Event
(
originalEvent
);
...
...
@@ -810,29 +818,5 @@ jQuery.fn.extend({
if
(
elem
)
{
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() {
equal
(
$input
.
attr
(
"checked"
),
"checked"
,
"Set checked to 'checked' (verified by .attr)"
);
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
(
0
).
attr
(
"checked"
),
"checked"
,
"First radio is still [checked]"
);
...
...
test/unit/core.js
View file @
6f7b6915
...
...
@@ -34,9 +34,8 @@ test("jQuery()", function() {
div
=
jQuery
(
"<div/><hr/><code/><b/>"
),
exec
=
false
,
lng
=
""
,
expected
=
2
2
,
expected
=
2
1
,
attrObj
=
{
"click"
:
function
()
{
ok
(
exec
,
"Click executed."
);
},
"text"
:
"test"
,
"class"
:
"test2"
,
"id"
:
"test3"
...
...
@@ -44,6 +43,10 @@ test("jQuery()", function() {
// 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.
if
(
jQuery
.
fn
.
click
)
{
expected
++
;
attrObj
[
"click"
]
=
function
()
{
ok
(
exec
,
"Click executed."
);
};
}
if
(
jQuery
.
fn
.
width
)
{
expected
++
;
attrObj
[
"width"
]
=
10
;
...
...
@@ -133,7 +136,7 @@ test("jQuery()", function() {
equal
(
elem
[
0
].
id
,
"test3"
,
"jQuery() quick setter id"
);
exec
=
true
;
elem
.
click
(
);
elem
.
trigger
(
"click"
);
// manually clean up detached elements
elem
.
remove
();
...
...
test/unit/event.js
View file @
6f7b6915
This diff is collapsed.
Click to expand it.
test/unit/manipulation.js
View file @
6f7b6915
...
...
@@ -121,7 +121,7 @@ var testWrap = function( val ) {
equal
(
result
.
text
(),
defaultText
,
"Check for element wrapping"
);
QUnit
.
reset
();
jQuery
(
"#check1"
).
click
(
function
()
{
jQuery
(
"#check1"
).
on
(
"click"
,
function
()
{
var
checkbox
=
this
;
ok
(
checkbox
.
checked
,
"Checkbox's state is erased after wrap() action, see #769"
);
...
...
@@ -168,7 +168,7 @@ var testWrap = function( val ) {
equal
(
j
[
0
].
parentNode
.
nodeName
.
toLowerCase
(),
"div"
,
"Wrapping works."
);
// 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."
);
// Remove handlers on detached elements
...
...
@@ -493,7 +493,7 @@ var testAppend = function( valueObj ) {
$radioChecked
=
jQuery
(
"input:radio[name='R1']"
).
eq
(
1
);
$radioParent
=
$radioChecked
.
parent
();
$radioUnchecked
=
jQuery
(
"<input type='radio' name='R1' checked='checked'/>"
).
appendTo
(
$radioParent
);
$radioChecked
.
click
(
);
$radioChecked
.
trigger
(
"click"
);
$radioUnchecked
[
0
].
checked
=
false
;
$radioParent
.
wrap
(
"<div></div>"
);
equal
(
$radioChecked
[
0
].
checked
,
true
,
"Reappending radios uphold which radio is checked"
);
...
...
@@ -766,13 +766,13 @@ test( "appendTo(String|Element|Array<Element>|jQuery)", function() {
t
(
"Append select"
,
"#foo select"
,
[
"select1"
]
);
QUnit
.
reset
();
div
=
jQuery
(
"<div/>"
).
click
(
function
()
{
div
=
jQuery
(
"<div/>"
).
on
(
"click"
,
function
()
{
ok
(
true
,
"Running a cloned click."
);
});
div
.
appendTo
(
"#qunit-fixture, #moretests"
);
jQuery
(
"#qunit-fixture div:last"
).
click
(
);
jQuery
(
"#moretests div:last"
).
click
(
);
jQuery
(
"#qunit-fixture div:last"
).
trigger
(
"click"
);
jQuery
(
"#moretests div:last"
).
trigger
(
"click"
);
QUnit
.
reset
();
div
=
jQuery
(
"<div/>"
).
appendTo
(
"#qunit-fixture, #moretests"
);
...
...
@@ -1139,35 +1139,35 @@ var testReplaceWith = function( val ) {
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."
);
});
y
=
jQuery
(
"<div/>"
).
appendTo
(
"#qunit-fixture"
).
click
(
function
()
{
y
=
jQuery
(
"<div/>"
).
appendTo
(
"#qunit-fixture"
).
on
(
"click"
,
function
()
{
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."
);
return
false
;
});
y
.
replaceWith
(
val
(
tmp
)
);
tmp
.
click
(
);
y
.
click
(
);
// Shouldn't be run
child
.
click
(
);
// Shouldn't be run
tmp
.
trigger
(
"click"
);
y
.
trigger
(
"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."
);
});
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."
);
return
false
;
});
y
.
replaceWith
(
val
(
child2
)
);
child2
.
click
(
);
child2
.
trigger
(
"click"
);
set
=
jQuery
(
"<div/>"
).
replaceWith
(
val
(
"<span>test</span>"
)
);
...
...
@@ -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)"
);
// 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."
);
});
clone
=
div
.
clone
(
true
);
div
.
remove
();
...
...
@@ -1302,7 +1302,7 @@ test( "clone()", function() {
// Verify that cloned children can keep event listeners
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."
);
});
...
...
@@ -1316,7 +1316,7 @@ test( "clone()", function() {
clone
.
remove
();
// 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()."
);
});
clone
=
div
.
clone
();
...
...
@@ -1734,9 +1734,9 @@ test( "remove() event cleaning ", 1, function() {
count
=
0
;
first
=
jQuery
(
"#ap"
).
children
(
":first"
);
cleanUp
=
first
.
click
(
function
()
{
cleanUp
=
first
.
on
(
"click"
,
function
()
{
count
++
;
}).
remove
().
appendTo
(
"#qunit-fixture"
).
click
(
);
}).
remove
().
appendTo
(
"#qunit-fixture"
).
trigger
(
"click"
);
strictEqual
(
0
,
count
,
"Event handler has been removed"
);
...
...
@@ -1753,9 +1753,9 @@ test( "detach() event cleaning ", 1, function() {
count
=
0
;
first
=
jQuery
(
"#ap"
).
children
(
":first"
);
cleanUp
=
first
.
click
(
function
()
{
cleanUp
=
first
.
on
(
"click"
,
function
()
{
count
++
;
}).
detach
().
appendTo
(
"#qunit-fixture"
).
click
(
);
}).
detach
().
appendTo
(
"#qunit-fixture"
).
trigger
(
"click"
);
strictEqual
(
1
,
count
,
"Event handler has not been removed"
);
...
...
@@ -1832,13 +1832,13 @@ test( "jQuery.cleanData", function() {
div
.
remove
();
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."
);
}).
focus
(
function
()
{
}).
on
(
"focus"
,
function
()
{
ok
(
true
,
type
+
" "
+
pos
+
" Focus event fired."
);
}).
find
(
"div"
).
click
(
function
()
{
}).
find
(
"div"
).
on
(
"click"
,
function
()
{
ok
(
false
,
type
+
" "
+
pos
+
" Click event fired."
);
}).
focus
(
function
()
{
}).
on
(
"focus"
,
function
()
{
ok
(
false
,
type
+
" "
+
pos
+
" Focus event fired."
);
}).
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