[Pkg-javascript-commits] [backbone] 16/211: Make Backbone View's delegateEvents only ever unbind the events that it adds itself.
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 16:59:57 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.5.0
in repository backbone.
commit 17602c39278810c46a265631935c69b5ab059de7
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date: Fri Dec 10 09:58:32 2010 -0500
Make Backbone View's delegateEvents only ever unbind the events that it adds itself.
---
backbone.js | 3 ++-
test/view.js | 10 ++++++----
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/backbone.js b/backbone.js
index 8e2b58a..824c19a 100644
--- a/backbone.js
+++ b/backbone.js
@@ -842,12 +842,13 @@
// not `change`, `submit`, and `reset` in Internet Explorer.
delegateEvents : function(events) {
if (!(events || (events = this.events))) return;
- $(this.el).unbind();
+ $(this.el).unbind('.delegateEvents');
for (var key in events) {
var methodName = events[key];
var match = key.match(eventSplitter);
var eventName = match[1], selector = match[2];
var method = _.bind(this[methodName], this);
+ eventName += '.delegateEvents';
if (selector === '') {
$(this.el).bind(eventName, method);
} else {
diff --git a/test/view.js b/test/view.js
index 29adc78..1fdfb71 100644
--- a/test/view.js
+++ b/test/view.js
@@ -38,20 +38,22 @@ $(document).ready(function() {
});
test("View: delegateEvents", function() {
- var counter = 0;
+ var counter = counter2 = 0;
view.el = document.body;
- view.increment = function() {
- return ++counter;
- };
+ view.increment = function(){ counter++; };
+ $(view.el).bind('click', function(){ counter2++; });
var events = {"click #qunit-banner": "increment"};
view.delegateEvents(events);
$('#qunit-banner').trigger('click');
equals(counter, 1);
+ equals(counter2, 1);
$('#qunit-banner').trigger('click');
equals(counter, 2);
+ equals(counter2, 2);
view.delegateEvents(events);
$('#qunit-banner').trigger('click');
equals(counter, 3);
+ equals(counter2, 3);
});
test("View: _ensureElement", function() {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list