Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 9fd92cc

Browse files
Steven Sojkajeffbcross
Steven Sojka
authored andcommitted
fix(ngTouch): ngClick does not pass touchend event when jQuery is loaded
The trigger handler event in jqLite takes an event object as a second parameter, but jQuery requires an array of parameters. This is causing the touchend event to not come thtough in the click handler when jQuery is loaded.
1 parent f7fc008 commit 9fd92cc

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/jqLite.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -803,13 +803,16 @@ forEach({
803803

804804
triggerHandler: function(element, eventName, eventData) {
805805
var eventFns = (JQLiteExpandoStore(element, 'events') || {})[eventName];
806-
eventData = eventData || {
806+
807+
eventData = eventData || [];
808+
809+
var event = [{
807810
preventDefault: noop,
808811
stopPropagation: noop
809-
};
812+
}];
810813

811814
forEach(eventFns, function(fn) {
812-
fn.call(element, eventData);
815+
fn.apply(element, event.concat(eventData));
813816
});
814817
}
815818
}, function(fn, name){

src/ngTouch/directive/ngClick.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
238238
}
239239

240240
if (!angular.isDefined(attr.disabled) || attr.disabled === false) {
241-
element.triggerHandler('click', event);
241+
element.triggerHandler('click', [event]);
242242
}
243243
}
244244

@@ -255,9 +255,9 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
255255
// - On mobile browsers, the simulated "fast" click will call this.
256256
// - But the browser's follow-up slow click will be "busted" before it reaches this handler.
257257
// Therefore it's safe to use this directive on both mobile and desktop.
258-
element.on('click', function(event) {
258+
element.on('click', function(event, touchend) {
259259
scope.$apply(function() {
260-
clickHandler(scope, {$event: event});
260+
clickHandler(scope, {$event: (touchend || event)});
261261
});
262262
});
263263

test/jqLiteSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,18 @@ describe('jqLite', function() {
13431343
event = pokeSpy.mostRecentCall.args[0];
13441344
expect(event.preventDefault).toBeDefined();
13451345
});
1346+
1347+
it('should pass data as an additional argument', function() {
1348+
var element = jqLite('<a>poke</a>'),
1349+
pokeSpy = jasmine.createSpy('poke'),
1350+
data;
1351+
1352+
element.on('click', pokeSpy);
1353+
1354+
element.triggerHandler('click', [{hello: "world"}]);
1355+
data = pokeSpy.mostRecentCall.args[1];
1356+
expect(data.hello).toBe("world");
1357+
});
13461358
});
13471359

13481360

0 commit comments

Comments
 (0)