2be61616 by Michael Richards

Use jQuery to bind/unbind DOM events if loaded.

1 parent 46ef0f06
...@@ -188,8 +188,12 @@ class Rivets.View ...@@ -188,8 +188,12 @@ class Rivets.View
188 188
189 # Cross-browser event binding 189 # Cross-browser event binding
190 bindEvent = (el, event, fn) -> 190 bindEvent = (el, event, fn) ->
191 # Check to see if jQuery is loaded.
192 if window.jQuery?
193 el = jQuery el
194 if el.on? then el.on event, fn else el.bind event, fn
191 # Check to see if addEventListener is available. 195 # Check to see if addEventListener is available.
192 if window.addEventListener 196 else if window.addEventListener?
193 el.addEventListener event, fn, false 197 el.addEventListener event, fn, false
194 else 198 else
195 # Assume we are in IE and use attachEvent. 199 # Assume we are in IE and use attachEvent.
...@@ -197,8 +201,12 @@ bindEvent = (el, event, fn) -> ...@@ -197,8 +201,12 @@ bindEvent = (el, event, fn) ->
197 el.attachEvent event, fn 201 el.attachEvent event, fn
198 202
199 unbindEvent = (el, event, fn) -> 203 unbindEvent = (el, event, fn) ->
204 # Check to see if jQuery is loaded.
205 if window.jQuery?
206 el = jQuery el
207 if el.off? then el.off event, fn else el.unbind event, fn
200 # Check to see if addEventListener is available. 208 # Check to see if addEventListener is available.
201 if window.removeEventListener 209 else if window.removeEventListener
202 el.removeEventListener event, fn, false 210 el.removeEventListener event, fn, false
203 else 211 else
204 # Assume we are in IE and use attachEvent. 212 # Assume we are in IE and use attachEvent.
......