f5528f7a by Michael Richards

Merge pull request #144 from mikeric/jquery-implementations-for-input

jQuery implementations for input
2 parents 169311ac fd434ad2
...@@ -251,12 +251,19 @@ unbindEvent = (el, event, fn) -> ...@@ -251,12 +251,19 @@ unbindEvent = (el, event, fn) ->
251 event = 'on' + event 251 event = 'on' + event
252 el.detachEvent event, fn 252 el.detachEvent event, fn
253 253
254 # Returns the current input value for the specified element. 254 # Cross-browser input value getter.
255 getInputValue = (el) -> 255 getInputValue = (el) ->
256 switch el.type 256 if window.jQuery?
257 when 'checkbox' then el.checked 257 el = jQuery el
258 when 'select-multiple' then o.value for o in el when o.selected 258
259 else el.value 259 switch el[0].type
260 when 'checkbox' then el.is ':checked'
261 else el.val()
262 else
263 switch el.type
264 when 'checkbox' then el.checked
265 when 'select-multiple' then o.value for o in el when o.selected
266 else el.value
260 267
261 # Core binding routines. 268 # Core binding routines.
262 Rivets.binders = 269 Rivets.binders =
...@@ -306,10 +313,16 @@ Rivets.binders = ...@@ -306,10 +313,16 @@ Rivets.binders =
306 unbind: (el) -> 313 unbind: (el) ->
307 unbindEvent el, 'change', @currentListener 314 unbindEvent el, 'change', @currentListener
308 routine: (el, value) -> 315 routine: (el, value) ->
309 if el.type is 'select-multiple' 316 if window.jQuery?
310 o.selected = o.value in value for o in el if value? 317 el = jQuery el
311 else if value?.toString() isnt el.value?.toString() 318
312 el.value = if value? then value else '' 319 if value?.toString() isnt el.val()?.toString()
320 el.val if value? then value else ''
321 else
322 if el.type is 'select-multiple'
323 o.selected = o.value in value for o in el if value?
324 else if value?.toString() isnt el.value?.toString()
325 el.value = if value? then value else ''
313 326
314 text: (el, value) -> 327 text: (el, value) ->
315 if el.innerText? 328 if el.innerText?
......