Merge pull request #144 from mikeric/jquery-implementations-for-input
jQuery implementations for input
Showing
1 changed file
with
14 additions
and
1 deletions
... | @@ -251,8 +251,15 @@ unbindEvent = (el, event, fn) -> | ... | @@ -251,8 +251,15 @@ 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 | if window.jQuery? | ||
257 | el = jQuery el | ||
258 | |||
259 | switch el[0].type | ||
260 | when 'checkbox' then el.is ':checked' | ||
261 | else el.val() | ||
262 | else | ||
256 | switch el.type | 263 | switch el.type |
257 | when 'checkbox' then el.checked | 264 | when 'checkbox' then el.checked |
258 | when 'select-multiple' then o.value for o in el when o.selected | 265 | when 'select-multiple' then o.value for o in el when o.selected |
... | @@ -306,6 +313,12 @@ Rivets.binders = | ... | @@ -306,6 +313,12 @@ 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) -> |
316 | if window.jQuery? | ||
317 | el = jQuery el | ||
318 | |||
319 | if value?.toString() isnt el.val()?.toString() | ||
320 | el.val if value? then value else '' | ||
321 | else | ||
309 | if el.type is 'select-multiple' | 322 | if el.type is 'select-multiple' |
310 | o.selected = o.value in value for o in el if value? | 323 | o.selected = o.value in value for o in el if value? |
311 | else if value?.toString() isnt el.value?.toString() | 324 | else if value?.toString() isnt el.value?.toString() | ... | ... |
-
Please register or sign in to post a comment