Created
February 6, 2012 10:53
-
-
Save y-ogi/1751448 to your computer and use it in GitHub Desktop.
jquery plugin (coffee script)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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