Skip to content

Commit

Permalink
Ensuring events work with Document and Window objects
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiospampinato committed Jan 5, 2020
1 parent 78a3afc commit d77372a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/events/off.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn.off = function ( this: Cash, eventFullName?: string | Record<string, EventCal

this.each ( ( i, ele ) => {

if ( !isElement ( ele ) ) return;
if ( !isElement ( ele ) && !isDocument ( ele ) && !isWindow ( ele ) ) return;

removeEvent ( ele );

Expand Down Expand Up @@ -50,7 +50,7 @@ fn.off = function ( this: Cash, eventFullName?: string | Record<string, EventCal

this.each ( ( i, ele ) => {

if ( !isElement ( ele ) ) return;
if ( !isElement ( ele ) && !isDocument ( ele ) && !isWindow ( ele ) ) return;

removeEvent ( ele, name, namespaces, selector, callback );

Expand Down
2 changes: 1 addition & 1 deletion src/events/on.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function on ( this: Cash, eventFullName: Record<string, EventCallback> | string,

this.each ( ( i, ele ) => {

if ( !isElement ( ele ) ) return;
if ( !isElement ( ele ) && !isDocument ( ele ) && !isWindow ( ele ) ) return;

const finalCallback = function ( event: Event ) {

Expand Down
16 changes: 16 additions & 0 deletions test/modules/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@ describe ( 'Events', { beforeEach: getFixtureInit ( fixture ) }, function () {

});

it ( 'supports Window and Document objects', function ( t ) {

var eles = $([window, document]);
var count = 0;

function handler () {
count++;
}

eles.on ( 'foo', handler );
eles.trigger ( 'foo' );

t.is ( count, 3 );

});

it ( 'ignores the order of namespaces', function ( t ) {

var ele = $('.event');
Expand Down

0 comments on commit d77372a

Please sign in to comment.