Created
February 24, 2010 23:01
-
-
Save jferris/313993 to your computer and use it in GitHub Desktop.
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
| // clear inputs with starter values | |
| new function($) { | |
| $.fn.prefilledInput = function() { | |
| var focus = function () { | |
| $(this).removeClass('prefilled'); | |
| if (this.value == this.prefilledValue) { | |
| this.value = ''; | |
| } | |
| }; | |
| var blur = function () { | |
| if (this.value == '') { | |
| $(this).addClass('prefilled').val(this.prefilledValue); | |
| } else if (this.value != this.prefilledValue) { | |
| $(this).removeClass('prefilled'); | |
| } | |
| }; | |
| var extractPrefilledValue = function () { | |
| if (this.title) { | |
| this.prefilledValue = this.title; | |
| this.title = ''; | |
| } else if (this.id) { | |
| this.prefilledValue = $('label[for=' + this.id + ']').hide().text(); | |
| } | |
| }; | |
| var initialize = function (index) { | |
| if (!this.prefilledValue) { | |
| this.extractPrefilledValue = extractPrefilledValue; | |
| this.extractPrefilledValue(); | |
| $(this).trigger('blur'); | |
| } | |
| }; | |
| return this.filter(":input"). | |
| focus(focus). | |
| blur(blur). | |
| each(initialize); | |
| }; | |
| var clearPrefilledInputs = function () { | |
| $(this).find("input.prefilled").val(""); | |
| }; | |
| var prefilledSetup = function () { | |
| $('input.prefilled').prefilledInput(); | |
| $('form').submit(clearPrefilledInputs); | |
| }; | |
| $(document).ready(prefilledSetup); | |
| }(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment