```coffeescript
_ = require 'underscore'
{ isTouchDevice } = require '../util/device.coffee'

module.exports =
  firstVisibleInput: ($el) ->
    $el.find('input:visible, textarea:visible').first()

  moveCursorToEnd: ($input) ->
    val = $input.val()
    $input.val('').val val

  autofocus: ($input, defer = false) ->
    return if isTouchDevice()

    focus = =>
      $input.focus()
      @moveCursorToEnd $input

    if defer then _.defer(focus) else focus()
```

Allow autofocus to accept a container element
user
```coffeescript
_ = require 'underscore'
{ isTouchDevice } = require '../util/device.coffee'

module.exports =
  firstVisibleInput: ($el) ->
    $el.find('input:visible, textarea:visible').first()

  moveCursorToEnd: ($input) ->
    val = $input.val()
    $input.val('').val val

  isFocusable: ($el) ->
    $el.is('input') or $el.is('textarea')

  autofocus: ($el, defer = false) ->
    return if isTouchDevice()

    focus = =>
      if not @isFocusable $el
        $el = @firstVisibleInput $el

      $el.focus()
      @moveCursorToEnd $el

    if defer then _.defer(focus) else focus()
```
assistant