[Pkg-javascript-commits] [backbone] 31/34: Issue #28 -- handleEvents -> delegateEvents, which is now called in the constructor.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:58:55 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.2.0
in repository backbone.

commit a7195a975d781da9f87c98f5af84c5953a003293
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Mon Oct 25 10:51:23 2010 -0400

    Issue #28 -- handleEvents -> delegateEvents, which is now called in the constructor.
---
 backbone.js  | 13 +++++++------
 test/view.js |  6 +++---
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/backbone.js b/backbone.js
index 0d8871f..8e48b32 100644
--- a/backbone.js
+++ b/backbone.js
@@ -534,6 +534,7 @@
   Backbone.View = function(options) {
     this._configure(options || {});
     this._ensureElement();
+    this.delegateEvents();
     if (this.initialize) this.initialize(options);
   };
 
@@ -544,7 +545,7 @@
     return $(selector, this.el);
   };
 
-  // Cached regex to split keys for `handleEvents`.
+  // Cached regex to split keys for `delegate`.
   var eventSplitter = /^(\w+)\s*(.*)$/;
 
   // Set up all inheritable **Backbone.View** properties and methods.
@@ -588,17 +589,17 @@
     // pairs. Callbacks will be bound to the view, with `this` set properly.
     // Uses jQuery event delegation for efficiency.
     // Omitting the selector binds the event to `this.el`.
-    // `"change"` events are not delegated through the view because IE does not
-    // bubble change events at all.
-    handleEvents : function(events) {
-      $(this.el).unbind();
+    // This only works for delegate-able events: not `focus`, `blur`, and
+    // not `change`, `submit`, and `reset` in Internet Explorer.
+    delegateEvents : function(events) {
       if (!(events || (events = this.events))) return this;
+      $(this.el).unbind();
       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);
-        if (selector === '' || eventName == 'change') {
+        if (selector === '') {
           $(this.el).bind(eventName, method);
         } else {
           $(this.el).delegate(selector, eventName, method);
diff --git a/test/view.js b/test/view.js
index 27f610a..2f343e2 100644
--- a/test/view.js
+++ b/test/view.js
@@ -37,19 +37,19 @@ $(document).ready(function() {
     equals(view.one, 1);
   });
 
-  test("View: handleEvents", function() {
+  test("View: delegateEvents", function() {
     var counter = 0;
     view.el = document.body;
     view.increment = function() {
       return ++counter;
     };
     var events = {"click #qunit-banner": "increment"};
-    view.handleEvents(events);
+    view.delegateEvents(events);
     $('#qunit-banner').trigger('click');
     equals(counter, 1);
     $('#qunit-banner').trigger('click');
     equals(counter, 2);
-    view.handleEvents(events);
+    view.delegateEvents(events);
     $('#qunit-banner').trigger('click');
     equals(counter, 3);
   });

-- 
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