Skip to content

Instantly share code, notes, and snippets.

@jemgold
Created March 17, 2014 18:20
Show Gist options
  • Save jemgold/9605170 to your computer and use it in GitHub Desktop.
Save jemgold/9605170 to your computer and use it in GitHub Desktop.
Batman.DOM.nodeIsEditable = (node) ->
if node.nodeName.toUpperCase() in ['INPUT', 'TEXTAREA', 'SELECT'] or node.hasAttribute('contenteditable')
return true
else return false
Batman.DOM.events.change = (node, callback, view) ->
eventNames = switch node.nodeName.toUpperCase()
when 'TEXTAREA' then ['input', 'keyup', 'change']
when 'INPUT'
if node.type.toLowerCase() in Batman.DOM.textInputTypes
oldCallback = callback
callback = (node, event, view) ->
return if event.type is 'keyup' and Batman.DOM.events.isEnter(event)
oldCallback(node, event, view)
['input', 'keyup', 'change']
else
['input', 'change']
else
if node.hasAttribute('contenteditable')
['input', 'change']
else
['change']
for eventName in eventNames
Batman.DOM.addEventListener node, eventName, (args...) ->
callback node, args..., view
return
Batman.DOM.ValueBinding.prototype.nodeChange = (node, context) ->
if @isTwoWay()
@set('filteredValue', (@node.value or @node.textContent))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment