From edc9122c6b75fc71805dea2300f1bd75f9d0c46c Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Wed, 27 Aug 2014 17:57:09 -0500 Subject: [PATCH 1/3] Still in progress, needs changes to unbind and tests. --- src/events/bind.js | 41 ++++++++++++--------- src/events/trigger.js | 15 +++++--- test/unit/extensions.js | 80 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 115 insertions(+), 21 deletions(-) diff --git a/src/events/bind.js b/src/events/bind.js index da46023..0dd9b5e 100644 --- a/src/events/bind.js +++ b/src/events/bind.js @@ -19,7 +19,7 @@ define([ "shoestring", "dom/closest" ], function(){ var evts = evt.split( " " ), docEl = document.documentElement, - addToEventCache = function( el, evt, callback ) { + addToEventCache = function( el, evt, eventInfo ) { if ( !el.shoestringData ) { el.shoestringData = {}; } @@ -30,19 +30,25 @@ define([ "shoestring", "dom/closest" ], function(){ el.shoestringData.events[ evt ] = []; } var obj = {}; - if( callback.customCallfunc ) { + if( eventInfo.customCallfunc ) { obj.isCustomEvent = true; } - obj.callback = callback.customCallfunc || callback.callfunc; - obj.originalCallback = callback.originalCallback; + obj.callback = eventInfo.customCallfunc || eventInfo.callfunc; + obj.originalCallback = eventInfo.originalCallback; + obj.namespace = eventInfo.namespace; el.shoestringData.events[ evt ].push( obj ); }; - function encasedCallback( e ){ + function encasedCallback( e, namespace ){ var result; + if( e._namespace && e._namespace !== namespace ) { + return; + } + e.data = data; + e.namespace = e._namespace; var returnTrue = function(){ return true; @@ -85,11 +91,11 @@ define([ "shoestring", "dom/closest" ], function(){ } // This is exclusively for custom events on browsers without addEventListener (IE8) - function propChange( originalEvent, boundElement ) { + function propChange( originalEvent, boundElement, namespace ) { var triggeredElement = document.documentElement[ originalEvent.propertyName ].el; if( triggeredElement !== undefined && shoestring( triggeredElement ).closest( boundElement ).length ) { - encasedCallback.call( triggeredElement, originalEvent ); + encasedCallback.call( triggeredElement, originalEvent, namespace ); } } @@ -97,7 +103,7 @@ define([ "shoestring", "dom/closest" ], function(){ // rebinds all callbacks on an element in the correct order. function reorderEvents( eventName ) { if( !this.attachEvent ) { - // do onthing + // do nothing return; } else if( this.shoestringData && this.shoestringData.events ) { var otherEvents = this.shoestringData.events[ eventName ]; @@ -117,24 +123,26 @@ define([ "shoestring", "dom/closest" ], function(){ var domEventCallback, customEventCallback, oEl = this; for( var i = 0, il = evts.length; i < il; i++ ){ - var evt = evts[ i ]; - domEventCallback = null; + var split = evts[ i ].split( "." ), + evt = split[ 0 ], + namespace = split.length > 0 ? split[ 1 ] : null; + + domEventCallback = function( originalEvent ) { + return encasedCallback.call( oEl, originalEvent, namespace ); + }; customEventCallback = null; if( "addEventListener" in this ){ - this.addEventListener( evt, encasedCallback, false ); + this.addEventListener( evt, domEventCallback, false ); } else if( this.attachEvent ){ if( this[ "on" + evt ] !== undefined ) { - domEventCallback = function( originalEvent ) { - return encasedCallback.call( oEl, originalEvent ); - }; this.attachEvent( "on" + evt, domEventCallback ); } else { customEventCallback = (function() { var eventName = evt; return function( e ) { if( e.propertyName === eventName ) { - propChange.call( this, e, oEl ); + propChange.call( this, e, oEl, namespace ); } }; })(); @@ -145,7 +153,8 @@ define([ "shoestring", "dom/closest" ], function(){ addToEventCache( this, evts[ i ], { callfunc: domEventCallback || encasedCallback, customCallfunc: customEventCallback, - originalCallback: originalCallback + originalCallback: originalCallback, + namespace: namespace }); reorderEvents.call( oEl, evt ); diff --git a/src/events/trigger.js b/src/events/trigger.js index ee911c7..f5efafb 100644 --- a/src/events/trigger.js +++ b/src/events/trigger.js @@ -6,19 +6,26 @@ define([ "shoestring" ], function(){ var evts = evt.split( " " ); return this.each(function(){ + var split, evt, namespace; for( var i = 0, il = evts.length; i < il; i++ ){ + split = evts[ i ].split( "." ), + evt = split[ 0 ], + namespace = split.length > 0 ? split[ 1 ] : null; + if( document.createEvent ){ var event = document.createEvent( "Event" ); - event.initEvent( evts[ i ], true, true ); + event.initEvent( evt, true, true ); event._args = args; + event._namespace = namespace; this.dispatchEvent( event ); } else if ( document.createEventObject ) { - if( ( "" + this[ evts[ i ] ] ).indexOf( "function" ) > -1 ) { - this[ evts[ i ] ](); + if( ( "" + this[ evt ] ).indexOf( "function" ) > -1 ) { + this[ evt ](); } else { - document.documentElement[ evts[ i ] ] = { + document.documentElement[ evt ] = { "el": this, + _namespace: namespace, _args: args }; } diff --git a/test/unit/extensions.js b/test/unit/extensions.js index 4b27113..b134cb8 100644 --- a/test/unit/extensions.js +++ b/test/unit/extensions.js @@ -1209,6 +1209,84 @@ $( "#child" ).trigger( "click" ); }); + asyncTest( 'Namespaced Custom Event: namespaced bind, namespaced trigger', function() { + expect( 2 ); + + shoestring( '#qunit-fixture' ).html( '
' ); + + $( "#el" ).bind( "customEvent.myNamespace", function( e ) { + ok( true, 'event callback should execute.' ); + ok( e.namespace, 'namespace property should exist.' ); + }) + .trigger( "customEvent.myNamespace" ); + + setTimeout(function() { + start(); + }, 15); + }); + + asyncTest( 'Namespaced Custom Event: namespaced bind, unnamespaced trigger', function() { + expect( 2 ); + + shoestring( '#qunit-fixture' ).html( '
' ); + + $( "#el" ).bind( "customEvent.myNamespace", function( e ) { + ok( true, 'event callback should execute.' ); + ok( !e.namespace, 'namespace property should not exist.' ); + }) + .trigger( "customEvent" ); + + setTimeout(function() { + start(); + }, 15); + }); + + asyncTest( 'Namespaced DOM Event: namespaced bind, namespaced trigger', function() { + expect( 2 ); + + shoestring( '#qunit-fixture' ).html( '
' ); + + $( "#el" ).bind( "click.myNamespace", function( e ) { + ok( true, 'event callback should execute.' ); + ok( e.namespace, 'namespace property should exist.' ); + }) + .trigger( "click.myNamespace" ); + + setTimeout(function() { + start(); + }, 15); + }); + + asyncTest( 'Namespaced DOM Event: namespaced bind, unnamespaced trigger', function() { + expect( 2 ); + + shoestring( '#qunit-fixture' ).html( '
' ); + + $( "#el2" ).bind( "click.myNamespace", function( e ) { + ok( true, 'event callback should execute.' ); + ok( !e.namespace, 'namespace property should not exist.' ); + }) + .trigger( "click" ); + + setTimeout(function() { + start(); + }, 15); + }); + + asyncTest( 'unnamespaced bind, namespaced trigger', function() { + expect( 0 ); + + shoestring( '#qunit-fixture' ).html( '
' ); + + $( "#el" ).bind( "click", function( e ) { + ok( true, 'event callback should not execute.' ); + }).trigger( "click.myNamespace" ); + + setTimeout(function() { + start(); + }, 15); + }); + if( window.JSON && 'localStorage' in window ) { module( "util", config ); @@ -1226,7 +1304,7 @@ }); } - module( 'events', config ); + module( 'ajax', config ); test( "ajax doesn't override default options", function() { equal( shoestring.ajax.settings.method, "GET" ); From c87851fc86195c67e9a671101b449fb8caa9e5cf Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Thu, 28 Aug 2014 11:52:51 -0500 Subject: [PATCH 2/3] Adds support for argumentless .unbind() as well as unbind with namespaces. Pending: IE8 testing --- src/events/bind.js | 2 +- src/events/unbind.js | 78 ++++++++------ src/util/errors.js | 1 - test/unit/extensions.js | 225 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 262 insertions(+), 44 deletions(-) diff --git a/src/events/bind.js b/src/events/bind.js index 0dd9b5e..153722a 100644 --- a/src/events/bind.js +++ b/src/events/bind.js @@ -150,7 +150,7 @@ define([ "shoestring", "dom/closest" ], function(){ } } - addToEventCache( this, evts[ i ], { + addToEventCache( this, evt, { callfunc: domEventCallback || encasedCallback, customCallfunc: customEventCallback, originalCallback: originalCallback, diff --git a/src/events/unbind.js b/src/events/unbind.js index bcb5db6..a024524 100644 --- a/src/events/unbind.js +++ b/src/events/unbind.js @@ -2,41 +2,61 @@ define([ "shoestring" ], function(){ //>>excludeEnd("exclude"); - shoestring.fn.unbind = function( evt, callback ){ - var evts = evt.split( " " ), - docEl = document.documentElement; + function unbind( evt, namespace, callback ) { + var bound = this.shoestringData.events[ evt ]; + if( !bound.length ) { + return; + } + + for( var j = 0, jl = bound.length; j < jl; j++ ) { + if( !namespace || namespace === bound[ j ].namespace ) { + if( "removeEventListener" in window ){ + if( callback === undefined ) { + this.removeEventListener( evt, bound[ j ].callback, false ); + } else if( callback === bound[ j ].originalCallback ) { + this.removeEventListener( evt, bound[ j ].callback, false ); + } + } else if( this.detachEvent ){ + if( callback === undefined ) { + this.detachEvent( "on" + evt, bound[ j ].callback ); + // custom event + document.documentElement.detachEvent( "onpropertychange", bound[ j ].callback ); + } else if( callback === bound[ j ].originalCallback ) { + this.detachEvent( "on" + evt, bound[ j ].callback ); + // custom event + document.documentElement.detachEvent( "onpropertychange", bound[ j ].callback ); + } + } + } + } + } + + function unbindAll( namespace, callback ) { + for( var evtKey in this.shoestringData.events ) { + unbind.call( this, evtKey, namespace, callback ); + } + } + + shoestring.fn.unbind = function( str, callback ){ + var evts = str ? str.split( " " ) : []; return this.each(function(){ if( !this.shoestringData || !this.shoestringData.events ) { return; } - for( var i = 0, il = evts.length; i < il; i++ ){ - //>>includeStart("development", pragmas.development); - if( evts[ i ].indexOf( "." ) === 0 ) { - shoestring.error( 'event-namespaces' ); - } - //>>includeEnd("development"); + if( !evts.length ) { + unbindAll.call( this ); + } else { + var split, evt, namespace; + for( var i = 0, il = evts.length; i < il; i++ ){ + split = evts[ i ].split( "." ), + evt = split[ 0 ], + namespace = split.length > 0 ? split[ 1 ] : null; - var bound = this.shoestringData.events[ evts[ i ] ]; - if( bound ) { - for( var j = 0, jl = bound.length; j < jl; j++ ) { - if( "removeEventListener" in window ){ - if( callback === undefined ) { - this.removeEventListener( evts[ i ], bound[ j ].callback, false ); - } else if( callback === bound[ j ].originalCallback ) { - this.removeEventListener( evts[ i ], bound[ j ].callback, false ); - } - } else if( this.detachEvent ){ - if( callback === undefined ) { - this.detachEvent( "on" + evts[ i ], bound[ j ].callback ); - // custom event - docEl.detachEvent( "onpropertychange", bound[ j ].callback ); - } else if( callback === bound[ j ].originalCallback ) { - this.detachEvent( "on" + evts[ i ], bound[ j ].callback ); - // custom event - docEl.detachEvent( "onpropertychange", bound[ j ].callback ); - } - } + if( evt ) { + unbind.call( this, evt, namespace, callback ); + } else { + unbindAll.call( this, namespace, callback ); } } } diff --git a/src/util/errors.js b/src/util/errors.js index b186682..c102a9a 100644 --- a/src/util/errors.js +++ b/src/util/errors.js @@ -8,7 +8,6 @@ define([ "shoestring" ], function(){ "click": "the click method. Try using trigger( 'click' ) instead.", "css-get" : "getting computed attributes from the DOM.", - "event-namespaces": "event namespacing, especially on .unbind( '.myNamespace' ). An event namespace is treated as part of the event name.", "has-class" : "the hasClass method. Try using .is( '.klassname' ) instead.", "live-delegate" : "the .live or .delegate methods. Use .bind or .on instead.", "map": "the map method. Try using .each to make a new object.", diff --git a/test/unit/extensions.js b/test/unit/extensions.js index b134cb8..bc74082 100644 --- a/test/unit/extensions.js +++ b/test/unit/extensions.js @@ -895,7 +895,7 @@ }, 30); }); - asyncTest( '`.unbind()`', function() { + asyncTest( '`.unbind("click", function)`', function() { expect( 1 ); var counter = 0; @@ -915,7 +915,7 @@ }, 30); }); - asyncTest( '`.unbind() multiple dom events`', function() { + asyncTest( '`.unbind("mouseup mousedown", function) multiple dom events`', function() { expect( 1 ); var counter = 0; @@ -936,7 +936,7 @@ }, 30); }); - asyncTest( '`.unbind() multiple custom events`', function() { + asyncTest( '`.unbind("aCustomEvent anotherCustomEvent", function)`', function() { expect( 1 ); var counter = 0; @@ -957,7 +957,7 @@ }, 30); }); - asyncTest( '`.unbind()` without callback', function() { + asyncTest( '`.unbind("click")`', function() { expect( 1 ); var counter = 0; @@ -977,7 +977,7 @@ }, 30); }); - asyncTest( '`.unbind()` custom event', function() { + asyncTest( '`.unbind("aCustomEvent", function)`', function() { expect( 1 ); var counter = 0; @@ -997,7 +997,7 @@ }, 30); }); - asyncTest( '`.unbind()` without callback, custom event', function() { + asyncTest( '`.unbind("aCustomEvent")`', function() { expect( 1 ); var counter = 0; @@ -1017,7 +1017,27 @@ }, 30); }); - asyncTest( '`.unbind()` in a `.bind()` callback', function() { + asyncTest( '`.unbind()` all', function() { + expect( 1 ); + var counter = 0; + + shoestring( '#qunit-fixture' ).html( '
' ); + var f = function() { + counter++; + }; + + $( "#el" ).bind( "aCustomEvent", f ) + .trigger( "aCustomEvent" ) + .unbind() + .trigger( "aCustomEvent" ); + + setTimeout(function() { + equal( counter, 1, "callback should have fired once." ); + start(); + }, 30); + }); + + asyncTest( '`.unbind("aCustomEvent", function)` in a `.bind()` callback', function() { expect( 1 ); var counter = 0; @@ -1209,7 +1229,7 @@ $( "#child" ).trigger( "click" ); }); - asyncTest( 'Namespaced Custom Event: namespaced bind, namespaced trigger', function() { + asyncTest( 'Custom Events: namespaced bind, namespaced trigger', function() { expect( 2 ); shoestring( '#qunit-fixture' ).html( '
' ); @@ -1225,7 +1245,7 @@ }, 15); }); - asyncTest( 'Namespaced Custom Event: namespaced bind, unnamespaced trigger', function() { + asyncTest( 'Custom Events: namespaced bind, unnamespaced trigger', function() { expect( 2 ); shoestring( '#qunit-fixture' ).html( '
' ); @@ -1241,7 +1261,7 @@ }, 15); }); - asyncTest( 'Namespaced DOM Event: namespaced bind, namespaced trigger', function() { + asyncTest( 'DOM Events: namespaced bind, namespaced trigger', function() { expect( 2 ); shoestring( '#qunit-fixture' ).html( '
' ); @@ -1257,7 +1277,7 @@ }, 15); }); - asyncTest( 'Namespaced DOM Event: namespaced bind, unnamespaced trigger', function() { + asyncTest( 'DOM Events: namespaced bind, unnamespaced trigger', function() { expect( 2 ); shoestring( '#qunit-fixture' ).html( '
' ); @@ -1273,7 +1293,7 @@ }, 15); }); - asyncTest( 'unnamespaced bind, namespaced trigger', function() { + asyncTest( 'DOM Events: unnamespaced bind, namespaced trigger', function() { expect( 0 ); shoestring( '#qunit-fixture' ).html( '
' ); @@ -1287,6 +1307,186 @@ }, 15); }); +asyncTest( '`Custom Events: .bind("myCustomEvent.myNamespace") .unbind("myCustomEvent.myNamespace")`', function() { + expect( 1 ); + var counter = 0; + + shoestring( '#qunit-fixture' ).html( '
' ); + var f = function() { + counter++; + }; + + $( "#el" ).bind( "myCustomEvent.myNamespace", f ) + .trigger( "myCustomEvent.myNamespace" ) + .unbind( "myCustomEvent.myNamespace" ) + .trigger( "myCustomEvent.myNamespace" ); + + setTimeout(function() { + equal( counter, 1, "callback should have fired once." ); + start(); + }, 30); + }); + + asyncTest( '`Custom Events: .bind("myCustomEvent.myNamespace") .unbind("myCustomEvent.myNamespace", function)`', function() { + expect( 1 ); + var counter = 0; + + shoestring( '#qunit-fixture' ).html( '
' ); + var f = function() { + counter++; + }; + + $( "#el" ).bind( "myCustomEvent.myNamespace", f ) + .trigger( "myCustomEvent.myNamespace" ) + .unbind( "myCustomEvent.myNamespace", f ) + .trigger( "myCustomEvent.myNamespace" ); + + setTimeout(function() { + equal( counter, 1, "callback should have fired once." ); + start(); + }, 30); + }); + + asyncTest( '`Custom Events: .bind("myCustomEvent.myNamespace") .unbind("myCustomEvent")`', function() { + expect( 1 ); + var counter = 0; + + shoestring( '#qunit-fixture' ).html( '
' ); + var f = function() { + counter++; + }; + + $( "#el" ).bind( "myCustomEvent.myNamespace", f ) + .trigger( "myCustomEvent.myNamespace" ) + .unbind( "myCustomEvent" ) + .trigger( "myCustomEvent.myNamespace" ); + + setTimeout(function() { + equal( counter, 1, "callback should have fired once." ); + start(); + }, 30); + }); + + asyncTest( '`Custom Events: .bind("myCustomEvent") .unbind("myCustomEvent.myNamespace", function)`', function() { + expect( 1 ); + var counter = 0; + + shoestring( '#qunit-fixture' ).html( '
' ); + var f = function() { + counter++; + }; + + $( "#el" ).bind( "myCustomEvent", f ) + .trigger( "myCustomEvent" ) + .unbind( "myCustomEvent.myNamespace", f ) + .trigger( "myCustomEvent" ); + + setTimeout(function() { + equal( counter, 2, "callback should fire twice. unbind should have not matched anything." ); + start(); + }, 30); + }); + + asyncTest( '`DOM Events: .bind("click.myNamespace") .unbind("click.myNamespace")`', function() { + expect( 1 ); + var counter = 0; + + shoestring( '#qunit-fixture' ).html( '
' ); + var f = function() { + counter++; + }; + + $( "#el" ).bind( "click.myNamespace", f ) + .trigger( "click.myNamespace" ) + .unbind( "click.myNamespace" ) + .trigger( "click.myNamespace" ); + + setTimeout(function() { + equal( counter, 1, "callback should have fired once." ); + start(); + }, 30); + }); + + asyncTest( '`DOM Events: .bind("click.myNamespace") .unbind("click.myNamespace", function)`', function() { + expect( 1 ); + var counter = 0; + + shoestring( '#qunit-fixture' ).html( '
' ); + var f = function() { + counter++; + }; + + $( "#el" ).bind( "click.myNamespace", f ) + .trigger( "click.myNamespace" ) + .unbind( "click.myNamespace", f ) + .trigger( "click.myNamespace" ); + + setTimeout(function() { + equal( counter, 1, "callback should have fired once." ); + start(); + }, 30); + }); + + asyncTest( '`DOM Events: .bind("click.myNamespace") .unbind("click")`', function() { + expect( 1 ); + var counter = 0; + + shoestring( '#qunit-fixture' ).html( '
' ); + var f = function() { + counter++; + }; + + $( "#el" ).bind( "click.myNamespace", f ) + .trigger( "click.myNamespace" ) + .unbind( "click" ) + .trigger( "click.myNamespace" ); + + setTimeout(function() { + equal( counter, 1, "callback should have fired once." ); + start(); + }, 30); + }); + + asyncTest( '`DOM Events: .bind("click") .unbind("click.myNamespace", function)`', function() { + expect( 1 ); + var counter = 0; + + shoestring( '#qunit-fixture' ).html( '
' ); + var f = function() { + counter++; + }; + + $( "#el" ).bind( "click", f ) + .trigger( "click" ) + .unbind( "click.myNamespace", f ) + .trigger( "click" ); + + setTimeout(function() { + equal( counter, 2, "callback should fire twice. unbind should have not matched anything." ); + start(); + }, 30); + }); + + asyncTest( '`DOM Events: .unbind(".myNamespace")`', function() { + expect( 1 ); + var counter = 0; + + shoestring( '#qunit-fixture' ).html( '
' ); + var f = function() { + counter++; + }; + + $( "#el" ).bind( "click.myNamespace", f ) + .trigger( "click.myNamespace" ) + .unbind( ".myNamespace", f ) + .trigger( "click.myNamespace" ); + + setTimeout(function() { + equal( counter, 1, "callback should fire once." ); + start(); + }, 30); + }); + if( window.JSON && 'localStorage' in window ) { module( "util", config ); @@ -1313,5 +1513,4 @@ }); // TODO test events + arguments on callbacks and trigger - // TODO unbind events by namespace only })(); From 5aef2d0ae8504c6b1f43b003eb5ff6f10d2fa2d7 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Thu, 28 Aug 2014 13:01:39 -0500 Subject: [PATCH 3/3] Fixes IE8 tests for namespacing. Also fixes issues with custom and dom event callback arguments in IE8 (with tests). --- src/events/bind.js | 11 ++++++++++- src/events/trigger.js | 4 ++++ test/unit/extensions.js | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/events/bind.js b/src/events/bind.js index 153722a..f492023 100644 --- a/src/events/bind.js +++ b/src/events/bind.js @@ -92,9 +92,12 @@ define([ "shoestring", "dom/closest" ], function(){ // This is exclusively for custom events on browsers without addEventListener (IE8) function propChange( originalEvent, boundElement, namespace ) { - var triggeredElement = document.documentElement[ originalEvent.propertyName ].el; + var lastEventInfo = document.documentElement[ originalEvent.propertyName ], + triggeredElement = lastEventInfo.el; if( triggeredElement !== undefined && shoestring( triggeredElement ).closest( boundElement ).length ) { + originalEvent._namespace = lastEventInfo._namespace; + originalEvent._args = lastEventInfo._args; encasedCallback.call( triggeredElement, originalEvent, namespace ); } } @@ -128,6 +131,12 @@ define([ "shoestring", "dom/closest" ], function(){ namespace = split.length > 0 ? split[ 1 ] : null; domEventCallback = function( originalEvent ) { + if( oEl.ssEventTrigger ) { + originalEvent._namespace = oEl.ssEventTrigger._namespace; + originalEvent._args = oEl.ssEventTrigger._args; + + oEl.ssEventTrigger = null; + } return encasedCallback.call( oEl, originalEvent, namespace ); }; customEventCallback = null; diff --git a/src/events/trigger.js b/src/events/trigger.js index f5efafb..58cfce0 100644 --- a/src/events/trigger.js +++ b/src/events/trigger.js @@ -21,6 +21,10 @@ define([ "shoestring" ], function(){ this.dispatchEvent( event ); } else if ( document.createEventObject ) { if( ( "" + this[ evt ] ).indexOf( "function" ) > -1 ) { + this.ssEventTrigger = { + _namespace: namespace, + _args: args + }; this[ evt ](); } else { document.documentElement[ evt ] = { diff --git a/test/unit/extensions.js b/test/unit/extensions.js index bc74082..72fafd6 100644 --- a/test/unit/extensions.js +++ b/test/unit/extensions.js @@ -671,6 +671,28 @@ }).trigger( "click" ); }); + asyncTest( 'DOM Event `.bind()` and `.trigger()` with arguments', function() { + expect( 1 ); + + shoestring( '#qunit-fixture' ).html( '
' ); + + $( "#el" ).bind( "click", function( e, myArgument ) { + equal( myArgument, "Argument", 'a custom argument should exist.' ); + start(); + }).trigger( "click", [ "Argument" ] ); + }); + + asyncTest( 'Custom Event `.bind()` and `.trigger()` with arguments', function() { + expect( 1 ); + + shoestring( '#qunit-fixture' ).html( '
' ); + + $( "#el" ).bind( "myCustomEvent", function( e, myArgument ) { + equal( myArgument, "Argument", 'a custom argument should exist.' ); + start(); + }).trigger( "myCustomEvent", [ "Argument" ] ); + }); + asyncTest( '`.bind()` and `.trigger()` with data', function() { expect( 2 );