mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Move delegate up and move check into undelegateEvents
This commit is contained in:
17
backbone.js
17
backbone.js
@@ -1042,7 +1042,7 @@
|
||||
// Change the view's element (`this.el` property), including event
|
||||
// re-delegation.
|
||||
setElement: function(element, delegate) {
|
||||
if (this.$el) this.undelegateEvents();
|
||||
this.undelegateEvents();
|
||||
this.$el = element instanceof Backbone.$ ? element : Backbone.$(element);
|
||||
this.el = this.$el[0];
|
||||
if (delegate !== false) this.delegateEvents();
|
||||
@@ -1079,13 +1079,6 @@
|
||||
return this;
|
||||
},
|
||||
|
||||
// Clears all callbacks previously bound to the view with `delegateEvents`.
|
||||
// You usually don't need to use this, but may wish to if you have multiple
|
||||
// Backbone views attached to the same DOM element.
|
||||
undelegateEvents: function() {
|
||||
this.$el.off('.delegateEvents' + this.cid);
|
||||
return this;
|
||||
},
|
||||
|
||||
// Add a single event listener to the element.
|
||||
delegate: function(eventName, selector, method) {
|
||||
@@ -1102,6 +1095,14 @@
|
||||
return this;
|
||||
},
|
||||
|
||||
// Clears all callbacks previously bound to the view with `delegateEvents`.
|
||||
// You usually don't need to use this, but may wish to if you have multiple
|
||||
// Backbone views attached to the same DOM element.
|
||||
undelegateEvents: function() {
|
||||
if (this.$el) this.$el.off('.delegateEvents' + this.cid);
|
||||
return this;
|
||||
},
|
||||
|
||||
// For hooking into small amounts of DOM Elements, where a full-blown template isn't
|
||||
// needed, use **make** to manufacture elements, one at a time.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user