-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjquery.DefaultText.js
More file actions
50 lines (39 loc) · 1.49 KB
/
jquery.DefaultText.js
File metadata and controls
50 lines (39 loc) · 1.49 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
$.fn.DefaultText = function(options) {
var defaults = {
inactiveClass: '',
inactiveFontStyle: 'italic',
inactiveColour: 'rgb(204,204,204)',
activeFontStyle: 'normal',
activeColour: 'rgb(0,0,0)'
};
var opts = $.extend(defaults, options);
$(this).each(function(){
if(opts.inactiveClass != ''){
$(this).addClass(opts.inactiveClass);
}else{
$(this).css({'font-style' : opts.inactiveFontStyle, 'color' : opts.inactiveColour});
}
$(this).bind('focus', function(){
if($(this).val() == $(this).attr('title')){
if(opts.inactiveClass != ''){
$(this).removeClass(opts.inactiveClass);
}else{
$(this).css({'font-style' : opts.activeFontStyle, 'color' : opts.activeColour});
}
$(this).val('');
}
});
$(this).bind('blur', function(){
if($(this).val() == ''){
if(opts.inactiveClass != ''){
$(this).addClass(opts.inactiveClass);
}else{
$(this).css({'font-style' : opts.inactiveFontStyle, 'color' : opts.inactiveColour});
}
$(this).val($(this).attr('title'));
}
});
$(this).blur();
$(this).val($(this).attr('title'));
});
};