Skip to content

Instantly share code, notes, and snippets.

@vendethiel
Forked from anonymous/gist:5546895
Last active December 17, 2015 03:59
Show Gist options
  • Save vendethiel/5546966 to your computer and use it in GitHub Desktop.
Save vendethiel/5546966 to your computer and use it in GitHub Desktop.
$ ->
class AjaxDateUpdater
constructor: (@id, @url) ->
$(@id).hover @hover_in, @hover_out
@old = ""
@has_focus = false
hover_in: (ev) =>
return if @has_focus
$el = $ ev.target
@old = $el.html()
width = $el.width()
$el.html ""
props =
type: 'name'
name: @id
value: @old
style: "width: #{width}px"
input = $ "<input>", props
input.appendTo this
input.focusin @grab_focus
input.focusout @leave_focus
hover_out: (ev) =>
unless @has_focus
$(ev.target).html @old
grab_focus: =>
@has_focus = true
leave_focus: =>
@has_focus = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment