aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);
+ });
});