Change the event binders on Rivets.Util to use the handler directly.
Showing
1 changed file
with
15 additions
and
19 deletions
... | @@ -251,30 +251,26 @@ class Rivets.View | ... | @@ -251,30 +251,26 @@ class Rivets.View |
251 | # Houses common utility functions used internally by Rivets.js. | 251 | # Houses common utility functions used internally by Rivets.js. |
252 | Rivets.Util = | 252 | Rivets.Util = |
253 | # Create a single DOM event binding. | 253 | # Create a single DOM event binding. |
254 | bindEvent: (el, event, handler, view) -> | 254 | bindEvent: (el, event, handler) -> |
255 | fn = (ev) -> handler.call @, ev, view | ||
256 | |||
257 | if window.jQuery? | 255 | if window.jQuery? |
258 | el = jQuery el | 256 | el = jQuery el |
259 | if el.on? then el.on event, fn else el.bind event, fn | 257 | if el.on? then el.on event, handler else el.bind event, handler |
260 | else if window.addEventListener? | 258 | else if window.addEventListener? |
261 | el.addEventListener event, fn, false | 259 | el.addEventListener event, handler, false |
262 | else | 260 | else |
263 | event = 'on' + event | 261 | event = 'on' + event |
264 | el.attachEvent event, fn | 262 | el.attachEvent event, handler |
265 | |||
266 | fn | ||
267 | 263 | ||
268 | # Remove a single DOM event binding. | 264 | # Remove a single DOM event binding. |
269 | unbindEvent: (el, event, fn) -> | 265 | unbindEvent: (el, event, handler) -> |
270 | if window.jQuery? | 266 | if window.jQuery? |
271 | el = jQuery el | 267 | el = jQuery el |
272 | if el.off? then el.off event, fn else el.unbind event, fn | 268 | if el.off? then el.off event, handler else el.unbind event, handler |
273 | else if window.removeEventListener | 269 | else if window.removeEventListener? |
274 | el.removeEventListener event, fn, false | 270 | el.removeEventListener event, handler, false |
275 | else | 271 | else |
276 | event = 'on' + event | 272 | event = 'on' + event |
277 | el.detachEvent event, fn | 273 | el.detachEvent event, handler |
278 | 274 | ||
279 | # Get the current value of an input node. | 275 | # Get the current value of an input node. |
280 | getInputValue: (el) -> | 276 | getInputValue: (el) -> |
... | @@ -306,9 +302,9 @@ Rivets.binders = | ... | @@ -306,9 +302,9 @@ Rivets.binders = |
306 | checked: | 302 | checked: |
307 | publishes: true | 303 | publishes: true |
308 | bind: (el) -> | 304 | bind: (el) -> |
309 | @currentListener = Rivets.Util.bindEvent el, 'change', @publish | 305 | Rivets.Util.bindEvent el, 'change', @publish |
310 | unbind: (el) -> | 306 | unbind: (el) -> |
311 | Rivets.Util.unbindEvent el, 'change', @currentListener | 307 | Rivets.Util.unbindEvent el, 'change', @publish |
312 | routine: (el, value) -> | 308 | routine: (el, value) -> |
313 | if el.type is 'radio' | 309 | if el.type is 'radio' |
314 | el.checked = el.value?.toString() is value?.toString() | 310 | el.checked = el.value?.toString() is value?.toString() |
... | @@ -318,9 +314,9 @@ Rivets.binders = | ... | @@ -318,9 +314,9 @@ Rivets.binders = |
318 | unchecked: | 314 | unchecked: |
319 | publishes: true | 315 | publishes: true |
320 | bind: (el) -> | 316 | bind: (el) -> |
321 | @currentListener = Rivets.Util.bindEvent el, 'change', @publish | 317 | Rivets.Util.bindEvent el, 'change', @publish |
322 | unbind: (el) -> | 318 | unbind: (el) -> |
323 | Rivets.Util.unbindEvent el, 'change', @currentListener | 319 | Rivets.Util.unbindEvent el, 'change', @publish |
324 | routine: (el, value) -> | 320 | routine: (el, value) -> |
325 | if el.type is 'radio' | 321 | if el.type is 'radio' |
326 | el.checked = el.value?.toString() isnt value?.toString() | 322 | el.checked = el.value?.toString() isnt value?.toString() |
... | @@ -339,9 +335,9 @@ Rivets.binders = | ... | @@ -339,9 +335,9 @@ Rivets.binders = |
339 | value: | 335 | value: |
340 | publishes: true | 336 | publishes: true |
341 | bind: (el) -> | 337 | bind: (el) -> |
342 | @currentListener = Rivets.Util.bindEvent el, 'change', @publish | 338 | Rivets.Util.bindEvent el, 'change', @publish |
343 | unbind: (el) -> | 339 | unbind: (el) -> |
344 | Rivets.Util.unbindEvent el, 'change', @currentListener | 340 | Rivets.Util.unbindEvent el, 'change', @publish |
345 | routine: (el, value) -> | 341 | routine: (el, value) -> |
346 | if window.jQuery? | 342 | if window.jQuery? |
347 | el = jQuery el | 343 | el = jQuery el | ... | ... |
-
Please register or sign in to post a comment