019fa5c4 by Adam Heath

Add support for passing in the current model when processing data-on.

1 parent 5cd20248
......@@ -18,13 +18,14 @@
Rivets.Binding = (function() {
function Binding(el, type, model, keypath, options) {
function Binding(el, type, model, keypath, options, bindContext) {
var identifier, regexp, value, _ref;
this.el = el;
this.type = type;
this.model = model;
this.keypath = keypath;
this.options = options != null ? options : {};
this.bindContext = bindContext;
this.unbind = __bind(this.unbind, this);
this.bind = __bind(this.bind, this);
......@@ -278,7 +279,7 @@
if (dependencies = context.shift()) {
options.dependencies = dependencies.split(/\s+/);
}
binding = new Rivets.Binding(node, type, model, keypath, options);
binding = new Rivets.Binding(node, type, model, keypath, options, _this.models);
binding.view = _this;
_this.bindings.push(binding);
}
......@@ -366,10 +367,10 @@
})();
bindEvent = function(el, event, handler, context) {
bindEvent = function(el, event, handler, context, bindContext) {
var fn;
fn = function(e) {
return handler.call(context, e);
return handler.call(context, e, bindContext);
};
if (window.jQuery != null) {
el = jQuery(el);
......@@ -508,7 +509,7 @@
if (this.currentListener) {
unbindEvent(el, this.args[0], this.currentListener);
}
return this.currentListener = bindEvent(el, this.args[0], value, this.model);
return this.currentListener = bindEvent(el, this.args[0], value, this.model, this.bindContext);
}
},
"each-*": {
......
......@@ -14,7 +14,7 @@ class Rivets.Binding
# All information about the binding is passed into the constructor; the DOM
# element, the type of binding, the model object and the keypath at which
# to listen for changes.
constructor: (@el, @type, @model, @keypath, @options = {}) ->
constructor: (@el, @type, @model, @keypath, @options = {}, @bindContext) ->
unless @binder = Rivets.binders[type]
for identifier, value of Rivets.binders
if identifier isnt '*' and identifier.indexOf('*') isnt -1
......@@ -184,7 +184,7 @@ class Rivets.View
if dependencies = context.shift()
options.dependencies = dependencies.split /\s+/
binding = new Rivets.Binding node, type, model, keypath, options
binding = new Rivets.Binding node, type, model, keypath, options, @models
binding.view = @
@bindings.push binding
......@@ -220,8 +220,8 @@ class Rivets.View
binding.publish() for binding in @select (b) -> b.binder.publishes
# Cross-browser event binding.
bindEvent = (el, event, handler, context) ->
fn = (e) -> handler.call context, e
bindEvent = (el, event, handler, context, bindContext) ->
fn = (e) -> handler.call context, e, bindContext
# Check to see if jQuery is loaded.
if window.jQuery?
......@@ -321,7 +321,7 @@ Rivets.binders =
function: true
routine: (el, value) ->
unbindEvent el, @args[0], @currentListener if @currentListener
@currentListener = bindEvent el, @args[0], value, @model
@currentListener = bindEvent el, @args[0], value, @model, @bindContext
"each-*":
block: true
......