jquery event: jQuery.Event can be instantiated without the 'new' keyword.
This commit is contained in:
parent
d37aeceb69
commit
4f99e793fa
10
src/event.js
10
src/event.js
|
@ -195,9 +195,9 @@ jQuery.event = {
|
||||||
// jQuery.Event object
|
// jQuery.Event object
|
||||||
e[expando] ? e :
|
e[expando] ? e :
|
||||||
// Object literal
|
// Object literal
|
||||||
jQuery.extend( new jQuery.Event(type), e ) :
|
jQuery.extend( jQuery.Event(type), e ) :
|
||||||
// Just the event type (string)
|
// Just the event type (string)
|
||||||
new jQuery.Event(type);
|
jQuery.Event(type);
|
||||||
|
|
||||||
e.target = e.target || elem;
|
e.target = e.target || elem;
|
||||||
e.currentTarget = elem;
|
e.currentTarget = elem;
|
||||||
|
@ -306,7 +306,7 @@ 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;
|
||||||
event = new jQuery.Event( originalEvent );
|
event = jQuery.Event( originalEvent );
|
||||||
|
|
||||||
for ( var i = this.props.length, prop; i; ){
|
for ( var i = this.props.length, prop; i; ){
|
||||||
prop = this.props[ --i ];
|
prop = this.props[ --i ];
|
||||||
|
@ -386,6 +386,10 @@ jQuery.event = {
|
||||||
};
|
};
|
||||||
|
|
||||||
jQuery.Event = function( src ){
|
jQuery.Event = function( src ){
|
||||||
|
// Allow instantiation without the 'new' keyword
|
||||||
|
if( !this.preventDefault )
|
||||||
|
return new jQuery.Event(src);
|
||||||
|
|
||||||
// Event object
|
// Event object
|
||||||
if( src && src.type ){
|
if( src && src.type ){
|
||||||
this.originalEvent = src;
|
this.originalEvent = src;
|
||||||
|
|
|
@ -270,7 +270,7 @@ test("unbind(event)", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("trigger(event, [data], [fn])", function() {
|
test("trigger(event, [data], [fn])", function() {
|
||||||
expect(67);
|
expect(69);
|
||||||
|
|
||||||
var handler = function(event, a, b, c) {
|
var handler = function(event, a, b, c) {
|
||||||
equals( event.type, "click", "check passed data" );
|
equals( event.type, "click", "check passed data" );
|
||||||
|
@ -330,8 +330,13 @@ test("trigger(event, [data], [fn])", function() {
|
||||||
// Triggers 8
|
// Triggers 8
|
||||||
equals( $elem.triggerHandler("click", [1, "2", "abc"], handler2), false, "Verify handler response" );
|
equals( $elem.triggerHandler("click", [1, "2", "abc"], handler2), false, "Verify handler response" );
|
||||||
|
|
||||||
|
var eventObj = jQuery.Event("noNew");
|
||||||
|
|
||||||
|
ok( eventObj != window, "Instantiate jQuery.Event without the 'new' keyword" );
|
||||||
|
equals( eventObj.type, "noNew", "Verify its type" );
|
||||||
|
|
||||||
// Build fake click event to pass in
|
// Build fake click event to pass in
|
||||||
var eventObj = new jQuery.Event("click");
|
eventObj = new jQuery.Event("click");
|
||||||
|
|
||||||
// Trigger only the handlers (no native), with external event obj
|
// Trigger only the handlers (no native), with external event obj
|
||||||
// Triggers 5
|
// Triggers 5
|
||||||
|
|
Loading…
Reference in a new issue