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.
This commit is contained in:
Steven Sojka 2013-09-04 11:20:33 -05:00 committed by Jeff Cross
parent f7fc00841b
commit 9fd92cc3c9
3 changed files with 21 additions and 6 deletions

View file

@ -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){

View file

@ -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]);
}
}
@ -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)});
});
});

View file

@ -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"}]);
data = pokeSpy.mostRecentCall.args[1];
expect(data.hello).toBe("world");
});
});