Created
April 29, 2010 19:47
-
-
Save jferris/384126 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(); | |
| } | |
| if (this.prefilledValue) { | |
| this.prefilledValue = this.prefilledValue.replace(/\*$/, ''); | |
| } | |
| }; | |
| 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 () { | |
| var form = this.form || this; | |
| $(form).find("input.prefilled, textarea.prefilled").val(""); | |
| }; | |
| var prefilledSetup = function () { | |
| $('input.prefilled, textarea.prefilled').prefilledInput(); | |
| $('form').submit(clearPrefilledInputs); | |
| $('input:submit, button:submit').click(clearPrefilledInputs); | |
| }; | |
| $(document).ready(prefilledSetup); | |
| $(document).ajaxComplete(prefilledSetup); | |
| }(jQuery); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment