-
Notifications
You must be signed in to change notification settings - Fork 12
/
backbone.raphael.js
40 lines (33 loc) · 1.27 KB
/
backbone.raphael.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Backbone.RaphaelView = Backbone.View.extend({
setElement: function(element, delegate, undelegateEvents) {
if (this.el && undelegateEvents) this.undelegateEvents();
// el and $el will be the same, $el would have no special meaning...
this.el = this.$el = element;
if (delegate !== false) this.delegateEvents();
return this;
},
delegateEvents: function(events, undelegateEvents) {
if (!(events || (events = _.result(this, 'events')))) return this;
if(undelegateEvents) this.undelegateEvents();
for (var eventName in events) {
var method = events[eventName];
if (!_.isFunction(method)) method = this[events[eventName]];
if (!method) continue;
method = _.bind(method, this);
//If it is one of the svg/vml events
if(this.el[eventName]){
this.el[eventName](method);
}
// Custom events for RaphaelView object
else{
this.on(eventName, method);
}
}
return this;
},
// Clears all callbacks previously bound to the view with `delegateEvents`.
undelegateEvents: function() {
if(this.el.type) this.el.unbindAll();
return this;
}
});