mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-30 04:50:28 +00:00
fix:jqLite: Fix binding to more events separated by space
The var eventHandler was defined outside forEach loop, so registering more
events caused calling listeners registered by the last one.
Regression:
elm.bind('click keyup', callback1);
elm.bind('click', callback2);
elm.bind('keyup', callback3);
Firing click event would have executed callback1, callback3 !
This commit is contained in:
parent
bb39d34279
commit
9ee9ca13da
2 changed files with 19 additions and 3 deletions
|
|
@ -351,11 +351,10 @@ forEach({
|
|||
dealoc: JQLiteDealoc,
|
||||
|
||||
bind: function(element, type, fn){
|
||||
var bind = JQLiteData(element, 'bind'),
|
||||
eventHandler;
|
||||
var bind = JQLiteData(element, 'bind');
|
||||
if (!bind) JQLiteData(element, 'bind', bind = {});
|
||||
forEach(type.split(' '), function(type){
|
||||
eventHandler = bind[type];
|
||||
var eventHandler = bind[type];
|
||||
if (!eventHandler) {
|
||||
bind[type] = eventHandler = function(event) {
|
||||
if (!event.preventDefault) {
|
||||
|
|
|
|||
|
|
@ -331,6 +331,23 @@ describe('jqLite', function(){
|
|||
browserTrigger(b, 'click');
|
||||
expect(log).toEqual('click on: A;click on: B;');
|
||||
});
|
||||
|
||||
it('should bind to all events separated by space', function() {
|
||||
var elm = jqLite(a),
|
||||
callback = jasmine.createSpy('callback');
|
||||
|
||||
elm.bind('click keypress', callback);
|
||||
elm.bind('click', callback);
|
||||
|
||||
browserTrigger(a, 'click');
|
||||
expect(callback).toHaveBeenCalled();
|
||||
expect(callback.callCount).toBe(2);
|
||||
|
||||
callback.reset();
|
||||
browserTrigger(a, 'keypress');
|
||||
expect(callback).toHaveBeenCalled();
|
||||
expect(callback.callCount).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue