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

Commit

Permalink
fix(ngTouch): ngClick does not pass touchend event when jQuery is loaded
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Steven Sojka authored and jeffbcross committed Oct 8, 2013
1 parent f7fc008 commit 9fd92cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,16 @@ forEach({

triggerHandler: function(element, eventName, eventData) {
var eventFns = (JQLiteExpandoStore(element, 'events') || {})[eventName];
eventData = eventData || {

eventData = eventData || [];

var event = [{
preventDefault: noop,
stopPropagation: noop
};
}];

forEach(eventFns, function(fn) {
fn.call(element, eventData);
fn.apply(element, event.concat(eventData));
});
}
}, function(fn, name){
Expand Down
6 changes: 3 additions & 3 deletions src/ngTouch/directive/ngClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
}

if (!angular.isDefined(attr.disabled) || attr.disabled === false) {
element.triggerHandler('click', event);
element.triggerHandler('click', [event]);
}
}

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

Expand Down
12 changes: 12 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,18 @@ describe('jqLite', function() {
event = pokeSpy.mostRecentCall.args[0];
expect(event.preventDefault).toBeDefined();
});

it('should pass data as an additional argument', function() {
var element = jqLite('<a>poke</a>'),
pokeSpy = jasmine.createSpy('poke'),
data;

element.on('click', pokeSpy);

element.triggerHandler('click', [{hello: "world"}]);

This comment has been minimized.

Copy link
@webuniverseio

webuniverseio Nov 2, 2013

Please take a look at following commit: #4744
I'm trying to make jqLite triggerHandler behave like in jQuery. Angular do have issues when you pass false values as data (like 0, '', false).

data = pokeSpy.mostRecentCall.args[1];
expect(data.hello).toBe("world");
});
});


Expand Down

0 comments on commit 9fd92cc

Please sign in to comment.