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) ->
event = 'on' + event
el.detachEvent event, fn
# Returns the current input value for the specified element.
# Cross-browser input value getter.
getInputValue = (el) ->
switch el.type
when 'checkbox' then el.checked
when 'select-multiple' then o.value for o in el when o.selected
else el.value
if window.jQuery?
el = jQuery el
switch el[0].type
when 'checkbox' then el.is ':checked'
else el.val()
else
switch el.type
when 'checkbox' then el.checked
when 'select-multiple' then o.value for o in el when o.selected
else el.value
# Core binding routines.
Rivets.binders =
......@@ -306,10 +313,16 @@ Rivets.binders =
unbind: (el) ->
unbindEvent el, 'change', @currentListener
routine: (el, value) ->
if el.type is 'select-multiple'
o.selected = o.value in value for o in el if value?
else if value?.toString() isnt el.value?.toString()
el.value = if value? then value else ''
if window.jQuery?
el = jQuery el
if value?.toString() isnt el.val()?.toString()
el.val if value? then value else ''
else
if el.type is 'select-multiple'
o.selected = o.value in value for o in el if value?
else if value?.toString() isnt el.value?.toString()
el.value = if value? then value else ''
text: (el, value) ->
if el.innerText?
......