aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVojta Jina2011-07-08 01:55:47 +0200
committerIgor Minar2011-07-12 23:04:46 -0700
commit9ee9ca13da3883d06733637f9048a83d94e6f1f8 (patch)
tree127d6d356ce08c447fbd69938d6a75d106b55909
parentbb39d34279fe1e221d35f5d2a274aaf039ea62d4 (diff)
downloadangular.js-9ee9ca13da3883d06733637f9048a83d94e6f1f8.tar.bz2
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 !
-rw-r--r--src/jqLite.js5
-rw-r--r--test/jqLiteSpec.js17
2 files changed, 19 insertions, 3 deletions
diff --git a/src/jqLite.js b/src/jqLite.js
index a1203739..5e9d777a 100644
--- a/src/jqLite.js
+++ b/src/jqLite.js
@@ -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) {
diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js
index 6794c4e0..fafe7f2a 100644
--- a/test/jqLiteSpec.js
+++ b/test/jqLiteSpec.js
@@ -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);
+ });
});