Created
January 28, 2012 14:38
-
-
Save dmohl/1694545 to your computer and use it in GitHub Desktop.
Placeholder jQuery Plugin in CoffeeScript
This file contains hidden or 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
| # Ported from Josh Bush's example at http://digitalbush.com/2011/03/29/testing-jquery-plugins-with-node-js-and-jasmine/ | |
| $ = jQuery | |
| $.fn.placeholder = (description) -> | |
| @.each -> | |
| input = $(@) | |
| # Note: We should use "on" instead of "bind" with the latest version of jQuery, but | |
| # we'll leave this just like the original for now. | |
| input.bind("blur.placeholder", -> input.val(input.val() or description)) | |
| .bind("focus.placeholder", -> if input.val() is description then input.val('')) | |
| .trigger "blur.placeholder" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment