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
ae27424b
Commit
ae27424b
authored
Sep 25, 2011
by
Dave Methvin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '8789-fun-with-fix' of
https://github.com/rwldrn/jquery
into fix-8789-rwldrn-fix
Conflicts: src/event.js test/unit/event.js
parents
d920ac68
87e1c62d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
48 deletions
+154
-48
event.js
src/event.js
+91
-44
event.js
test/unit/event.js
+63
-4
No files found.
src/event.js
View file @
ae27424b
...
@@ -407,6 +407,12 @@ jQuery.event = {
...
@@ -407,6 +407,12 @@ jQuery.event = {
// Make a writable jQuery.Event from the native event object
// Make a writable jQuery.Event from the native event object
event
=
jQuery
.
event
.
fix
(
event
||
window
.
event
);
event
=
jQuery
.
event
.
fix
(
event
||
window
.
event
);
var
propHook
=
jQuery
.
event
.
propHooks
[
event
.
type
];
if
(
propHook
)
{
event
=
propHook
(
event
);
}
var
handlers
=
((
jQuery
.
_data
(
this
,
"events"
)
||
{})[
event
.
type
]
||
[]),
var
handlers
=
((
jQuery
.
_data
(
this
,
"events"
)
||
{})[
event
.
type
]
||
[]),
delegateCount
=
handlers
.
delegateCount
,
delegateCount
=
handlers
.
delegateCount
,
args
=
Array
.
prototype
.
slice
.
call
(
arguments
,
0
),
args
=
Array
.
prototype
.
slice
.
call
(
arguments
,
0
),
...
@@ -463,7 +469,9 @@ jQuery.event = {
...
@@ -463,7 +469,9 @@ jQuery.event = {
return
event
.
result
;
return
event
.
result
;
},
},
props
:
"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which"
.
split
(
" "
),
props
:
"altKey attrName bubbles button cancelable charCode ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view which"
.
split
(
" "
),
propHooks
:
{},
fix
:
function
(
event
)
{
fix
:
function
(
event
)
{
if
(
event
[
jQuery
.
expando
]
)
{
if
(
event
[
jQuery
.
expando
]
)
{
...
@@ -472,21 +480,30 @@ jQuery.event = {
...
@@ -472,21 +480,30 @@ jQuery.event = {
// store a copy of the original event object
// store a copy of the original event object
// and "clone" to set read-only properties
// and "clone" to set read-only properties
var
originalEvent
=
event
;
var
originalEvent
=
event
,
propHook
=
jQuery
.
event
.
propHooks
[
event
.
type
],
copy
=
this
.
props
;
event
=
jQuery
.
Event
(
originalEvent
);
event
=
jQuery
.
Event
(
originalEvent
);
for
(
var
i
=
this
.
props
.
length
,
prop
;
i
;
)
{
if
(
propHook
)
{
prop
=
this
.
props
[
--
i
];
copy
.
push
.
apply
(
copy
,
propHook
()
||
[]
);
}
for
(
var
i
=
copy
.
length
,
prop
;
i
;
)
{
prop
=
copy
[
--
i
];
event
[
prop
]
=
originalEvent
[
prop
];
event
[
prop
]
=
originalEvent
[
prop
];
}
}
// Fix target property, if necessary
// Fix target property, if necessary
// Removal will crash IE6,7,8
if
(
!
event
.
target
)
{
if
(
!
event
.
target
)
{
// Fixes #1925 where srcElement might not be defined either
// Fixes #1925 where srcElement might not be defined either
event
.
target
=
event
.
srcElement
||
document
;
event
.
target
=
event
.
srcElement
||
document
;
}
}
// check if target is a textnode (safari)
// check if target is a textnode (safari)
// Removal will crash IE6,7,8
if
(
event
.
target
.
nodeType
===
3
)
{
if
(
event
.
target
.
nodeType
===
3
)
{
event
.
target
=
event
.
target
.
parentNode
;
event
.
target
=
event
.
target
.
parentNode
;
}
}
...
@@ -496,30 +513,8 @@ jQuery.event = {
...
@@ -496,30 +513,8 @@ jQuery.event = {
event
.
relatedTarget
=
event
.
fromElement
===
event
.
target
?
event
.
toElement
:
event
.
fromElement
;
event
.
relatedTarget
=
event
.
fromElement
===
event
.
target
?
event
.
toElement
:
event
.
fromElement
;
}
}
// Calculate pageX/Y if missing and clientX/Y available
if
(
propHook
)
{
if
(
event
.
pageX
==
null
&&
event
.
clientX
!=
null
)
{
event
=
propHook
(
event
,
originalEvent
);
var
eventDocument
=
event
.
target
.
ownerDocument
||
document
,
doc
=
eventDocument
.
documentElement
,
body
=
eventDocument
.
body
;
event
.
pageX
=
event
.
clientX
+
(
doc
&&
doc
.
scrollLeft
||
body
&&
body
.
scrollLeft
||
0
)
-
(
doc
&&
doc
.
clientLeft
||
body
&&
body
.
clientLeft
||
0
);
event
.
pageY
=
event
.
clientY
+
(
doc
&&
doc
.
scrollTop
||
body
&&
body
.
scrollTop
||
0
)
-
(
doc
&&
doc
.
clientTop
||
body
&&
body
.
clientTop
||
0
);
}
// Add which for key events
if
(
event
.
which
==
null
&&
(
event
.
charCode
!=
null
||
event
.
keyCode
!=
null
)
)
{
event
.
which
=
event
.
charCode
!=
null
?
event
.
charCode
:
event
.
keyCode
;
}
// Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
if
(
!
event
.
metaKey
&&
event
.
ctrlKey
)
{
event
.
metaKey
=
event
.
ctrlKey
;
}
// Add which for click: 1 === left; 2 === middle; 3 === right
// Note: button is not normalized, so don't use it
if
(
!
event
.
which
&&
event
.
button
!==
undefined
)
{
event
.
which
=
(
event
.
button
&
1
?
1
:
(
event
.
button
&
2
?
3
:
(
event
.
button
&
4
?
2
:
0
)
));
}
}
return
event
;
return
event
;
...
@@ -1013,7 +1008,7 @@ jQuery.fn.extend({
...
@@ -1013,7 +1008,7 @@ jQuery.fn.extend({
jQuery
.
each
(
(
"blur focus focusin focusout load resize scroll unload click dblclick "
+
jQuery
.
each
(
(
"blur focus focusin focusout load resize scroll unload click dblclick "
+
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave "
+
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave "
+
"change select submit keydown keypress keyup error"
).
split
(
" "
),
function
(
i
,
name
)
{
"change select submit keydown keypress keyup error
contextmenu
"
).
split
(
" "
),
function
(
i
,
name
)
{
// Handle event binding
// Handle event binding
jQuery
.
fn
[
name
]
=
function
(
data
,
fn
)
{
jQuery
.
fn
[
name
]
=
function
(
data
,
fn
)
{
...
@@ -1030,7 +1025,59 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl
...
@@ -1030,7 +1025,59 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl
if
(
jQuery
.
attrFn
)
{
if
(
jQuery
.
attrFn
)
{
jQuery
.
attrFn
[
name
]
=
true
;
jQuery
.
attrFn
[
name
]
=
true
;
}
}
});
// Key Event property hooks
if
(
rkeyEvent
.
test
(
name
)
)
{
jQuery
.
event
.
propHooks
[
name
]
=
function
(
event
,
original
)
{
var
charCode
=
event
.
charCode
,
keyCode
=
event
.
keyCode
,
ctrlKey
=
event
.
ctrlKey
;
// Add which for key events
if
(
event
.
which
==
null
&&
(
charCode
!=
null
||
keyCode
!=
null
)
)
{
event
.
which
=
charCode
!=
null
?
charCode
:
keyCode
;
}
// Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
if
(
!
event
.
metaKey
&&
ctrlKey
)
{
event
.
metaKey
=
ctrlKey
;
}
return
event
;
};
}
// Mouse Event property hooks
if
(
rmouseEvent
.
test
(
name
)
)
{
jQuery
.
event
.
propHooks
[
name
]
=
function
(
event
,
original
)
{
if
(
!
event
)
{
return
mouseProps
;
}
var
eventDoc
,
doc
,
body
,
button
=
event
.
button
;
// Calculate pageX/Y if missing and clientX/Y available
if
(
event
.
pageX
==
null
&&
event
.
clientX
!=
null
)
{
eventDoc
=
event
.
target
.
ownerDocument
||
document
;
doc
=
eventDoc
.
documentElement
;
body
=
eventDoc
.
body
;
event
.
pageX
=
event
.
clientX
+
(
doc
&&
doc
.
scrollLeft
||
body
&&
body
.
scrollLeft
||
0
)
-
(
doc
&&
doc
.
clientLeft
||
body
&&
body
.
clientLeft
||
0
);
event
.
pageY
=
event
.
clientY
+
(
doc
&&
doc
.
scrollTop
||
body
&&
body
.
scrollTop
||
0
)
-
(
doc
&&
doc
.
clientTop
||
body
&&
body
.
clientTop
||
0
);
}
// Add which for click: 1 === left; 2 === middle; 3 === right
// Note: button is not normalized, so don't use it
if
(
!
event
.
which
&&
button
!==
undefined
)
{
event
.
which
=
(
button
&
1
?
1
:
(
button
&
2
?
3
:
(
button
&
4
?
2
:
0
)
));
}
return
event
;
};
}});
})(
jQuery
);
})(
jQuery
);
test/unit/event.js
View file @
ae27424b
...
@@ -2457,6 +2457,65 @@ test("delegated events quickIs", function() {
...
@@ -2457,6 +2457,65 @@ test("delegated events quickIs", function() {
})();
})();
test
(
"jQuery.event.propHooks"
,
function
()
{
expect
(
1
);
ok
(
jQuery
.
event
.
propHooks
,
"jQuery.event.propHooks exists"
);
});
test
(
"jQuery.event.propHooks as function"
,
function
()
{
expect
(
2
);
jQuery
(
"<div id='hook-fixture'></div>"
).
appendTo
(
"#qunit-fixture"
);
var
$fixture
=
jQuery
(
"#hook-fixture"
);
// Does not exist
$fixture
.
bind
(
"click"
,
function
(
event
)
{
ok
(
!
(
"propC"
in
event
),
"event.propC Does not exist"
);
}).
trigger
(
"click"
);
$fixture
.
unbind
(
"click"
);
// Store as function
jQuery
.
event
.
propHooks
[
"custom"
]
=
function
(
event
)
{
// receives the event object for processing
event
.
propC
=
true
;
return
event
;
};
$fixture
.
bind
(
"custom"
,
function
(
event
)
{
ok
(
event
.
propC
,
"event.propC exists"
);
}).
trigger
(
"custom"
);
});
test
(
"jQuery.event.propHooks usecase"
,
function
()
{
expect
(
3
);
jQuery
(
"<div id='hook-fixture'></div>"
).
appendTo
(
"#qunit-fixture"
);
var
$fixture
=
jQuery
(
"#hook-fixture"
);
$fixture
.
bind
(
"fakedrop"
,
function
(
event
)
{
ok
(
!
(
"dataTransfer"
in
event
),
"event.dataTransfer is not available"
);
}).
trigger
(
"fakedrop"
);
$fixture
.
unbind
(
"fakedrop"
);
jQuery
.
event
.
propHooks
[
"fakedrop"
]
=
function
(
event
)
{
event
.
dataTransfer
=
"some val"
;
return
event
;
};
$fixture
.
bind
(
"fakedrop"
,
function
(
event
)
{
ok
(
(
"dataTransfer"
in
event
),
"event.dataTransfer exists, just copied"
);
equal
(
event
.
dataTransfer
,
"some val"
,
"event.dataTransfer equal 'some val'"
);
}).
trigger
(
"fakedrop"
);
$fixture
.
unbind
(
"fakedrop"
);
});
/*
/*
test("event properties", function() {
test("event properties", function() {
stop();
stop();
...
...
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