-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.fieldhint.js
35 lines (35 loc) · 1.05 KB
/
jquery.fieldhint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*!
* fieldHint jQuery Plugin
* Examples and documentation at: http://fordinteractive.com/tools/jquery/fieldhint/
* Copyright (c) 2010 Andy Ford
* Version: 1.0 (2010-06-01)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Requires: jQuery v1.2.6+
*/
;(function($) {
$.fn.fieldHint = function(options) {
var opts = $.extend({
hint: this.val(),
useClass: true,
defaultClass: 'default'
},options);
return this.each(function() {
if( $(this).val() != opts.hint ) { $(this).val(opts.hint); }
if ( ($(this).val() == opts.hint) && (opts.useClass) ) { $(this).addClass(opts.defaultClass); }
$(this).focus(function() {
if ( $(this).val() == opts.hint ) {
$(this).val('');
if ( opts.useClass ) { $(this).removeClass(opts.defaultClass); }
}
});
$(this).blur(function() {
if ( $(this).val() == '' ) {
$(this).val(opts.hint);
if ( opts.useClass ) { $(this).addClass(opts.defaultClass); }
}
});
});
};
})(jQuery);