Add support for passing in the current model when processing data-on.
Showing
3 changed files
with
11 additions
and
10 deletions
... | @@ -18,13 +18,14 @@ | ... | @@ -18,13 +18,14 @@ |
18 | 18 | ||
19 | Rivets.Binding = (function() { | 19 | Rivets.Binding = (function() { |
20 | 20 | ||
21 | function Binding(el, type, model, keypath, options) { | 21 | function Binding(el, type, model, keypath, options, bindContext) { |
22 | var identifier, regexp, value, _ref; | 22 | var identifier, regexp, value, _ref; |
23 | this.el = el; | 23 | this.el = el; |
24 | this.type = type; | 24 | this.type = type; |
25 | this.model = model; | 25 | this.model = model; |
26 | this.keypath = keypath; | 26 | this.keypath = keypath; |
27 | this.options = options != null ? options : {}; | 27 | this.options = options != null ? options : {}; |
28 | this.bindContext = bindContext; | ||
28 | this.unbind = __bind(this.unbind, this); | 29 | this.unbind = __bind(this.unbind, this); |
29 | 30 | ||
30 | this.bind = __bind(this.bind, this); | 31 | this.bind = __bind(this.bind, this); |
... | @@ -278,7 +279,7 @@ | ... | @@ -278,7 +279,7 @@ |
278 | if (dependencies = context.shift()) { | 279 | if (dependencies = context.shift()) { |
279 | options.dependencies = dependencies.split(/\s+/); | 280 | options.dependencies = dependencies.split(/\s+/); |
280 | } | 281 | } |
281 | binding = new Rivets.Binding(node, type, model, keypath, options); | 282 | binding = new Rivets.Binding(node, type, model, keypath, options, _this.models); |
282 | binding.view = _this; | 283 | binding.view = _this; |
283 | _this.bindings.push(binding); | 284 | _this.bindings.push(binding); |
284 | } | 285 | } |
... | @@ -366,10 +367,10 @@ | ... | @@ -366,10 +367,10 @@ |
366 | 367 | ||
367 | })(); | 368 | })(); |
368 | 369 | ||
369 | bindEvent = function(el, event, handler, context) { | 370 | bindEvent = function(el, event, handler, context, bindContext) { |
370 | var fn; | 371 | var fn; |
371 | fn = function(e) { | 372 | fn = function(e) { |
372 | return handler.call(context, e); | 373 | return handler.call(context, e, bindContext); |
373 | }; | 374 | }; |
374 | if (window.jQuery != null) { | 375 | if (window.jQuery != null) { |
375 | el = jQuery(el); | 376 | el = jQuery(el); |
... | @@ -508,7 +509,7 @@ | ... | @@ -508,7 +509,7 @@ |
508 | if (this.currentListener) { | 509 | if (this.currentListener) { |
509 | unbindEvent(el, this.args[0], this.currentListener); | 510 | unbindEvent(el, this.args[0], this.currentListener); |
510 | } | 511 | } |
511 | return this.currentListener = bindEvent(el, this.args[0], value, this.model); | 512 | return this.currentListener = bindEvent(el, this.args[0], value, this.model, this.bindContext); |
512 | } | 513 | } |
513 | }, | 514 | }, |
514 | "each-*": { | 515 | "each-*": { | ... | ... |
This diff is collapsed.
Click to expand it.
... | @@ -14,7 +14,7 @@ class Rivets.Binding | ... | @@ -14,7 +14,7 @@ class Rivets.Binding |
14 | # All information about the binding is passed into the constructor; the DOM | 14 | # All information about the binding is passed into the constructor; the DOM |
15 | # element, the type of binding, the model object and the keypath at which | 15 | # element, the type of binding, the model object and the keypath at which |
16 | # to listen for changes. | 16 | # to listen for changes. |
17 | constructor: (@el, @type, @model, @keypath, @options = {}) -> | 17 | constructor: (@el, @type, @model, @keypath, @options = {}, @bindContext) -> |
18 | unless @binder = Rivets.binders[type] | 18 | unless @binder = Rivets.binders[type] |
19 | for identifier, value of Rivets.binders | 19 | for identifier, value of Rivets.binders |
20 | if identifier isnt '*' and identifier.indexOf('*') isnt -1 | 20 | if identifier isnt '*' and identifier.indexOf('*') isnt -1 |
... | @@ -184,7 +184,7 @@ class Rivets.View | ... | @@ -184,7 +184,7 @@ class Rivets.View |
184 | if dependencies = context.shift() | 184 | if dependencies = context.shift() |
185 | options.dependencies = dependencies.split /\s+/ | 185 | options.dependencies = dependencies.split /\s+/ |
186 | 186 | ||
187 | binding = new Rivets.Binding node, type, model, keypath, options | 187 | binding = new Rivets.Binding node, type, model, keypath, options, @models |
188 | binding.view = @ | 188 | binding.view = @ |
189 | 189 | ||
190 | @bindings.push binding | 190 | @bindings.push binding |
... | @@ -220,8 +220,8 @@ class Rivets.View | ... | @@ -220,8 +220,8 @@ class Rivets.View |
220 | binding.publish() for binding in @select (b) -> b.binder.publishes | 220 | binding.publish() for binding in @select (b) -> b.binder.publishes |
221 | 221 | ||
222 | # Cross-browser event binding. | 222 | # Cross-browser event binding. |
223 | bindEvent = (el, event, handler, context) -> | 223 | bindEvent = (el, event, handler, context, bindContext) -> |
224 | fn = (e) -> handler.call context, e | 224 | fn = (e) -> handler.call context, e, bindContext |
225 | 225 | ||
226 | # Check to see if jQuery is loaded. | 226 | # Check to see if jQuery is loaded. |
227 | if window.jQuery? | 227 | if window.jQuery? |
... | @@ -321,7 +321,7 @@ Rivets.binders = | ... | @@ -321,7 +321,7 @@ Rivets.binders = |
321 | function: true | 321 | function: true |
322 | routine: (el, value) -> | 322 | routine: (el, value) -> |
323 | unbindEvent el, @args[0], @currentListener if @currentListener | 323 | unbindEvent el, @args[0], @currentListener if @currentListener |
324 | @currentListener = bindEvent el, @args[0], value, @model | 324 | @currentListener = bindEvent el, @args[0], value, @model, @bindContext |
325 | 325 | ||
326 | "each-*": | 326 | "each-*": |
327 | block: true | 327 | block: true | ... | ... |
-
Please register or sign in to post a comment