Skip to content

Instantly share code, notes, and snippets.

@y-ogi
Created February 6, 2012 10:53
Show Gist options
  • Save y-ogi/1751448 to your computer and use it in GitHub Desktop.
Save y-ogi/1751448 to your computer and use it in GitHub Desktop.
jquery plugin (coffee script)
jQuery.fn.fillin = (options) ->
default_options =
border_color: 'red',
background_color: 'red'
options = $.extend {}, default_options, options
# change color
change_color = (el)->
that = $(el)
if that.val().length is 0
that.css 'border-color', options.border_color
that.css 'background-color', options.background_color
return
# events
on_focus = ->
that = $(@)
that.css 'border-color', ''
that.css 'background-color', ''
return
on_blur = ->
change_color @
return
@.each(() ->
that = $(@)
that.focus on_focus
that.blur on_blur
change_color @
return
)
return this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment