Skip to content

Instantly share code, notes, and snippets.

@voising
Last active December 18, 2015 13:10
Show Gist options
  • Save voising/5788363 to your computer and use it in GitHub Desktop.
Save voising/5788363 to your computer and use it in GitHub Desktop.
COFFESCRIPT : Ergonomics on forms
.focus {
color: #DEDEDE;
}
.hidden {
visibility: hidden;
}
refreshErgo = ->
$(".ergo input[type=\"text\"], .ergo textarea").each ->
label = $(this).parent().parent().find("label[for=\"" + @id + "\"]")
$(this).off("focus").on "focus", ->
label.addClass "focus"
$(this).off("keydown").on "keydown", ->
label.addClass "hidden"
$(this).off("blur").on "blur", ->
label.removeClass "focus"
if @value is ""
label.removeClass "hidden"
else
label.addClass "hidden"
label.addClass "hidden" if @value isnt ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment