-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.placeholder-label.js
61 lines (51 loc) · 1.55 KB
/
jquery.placeholder-label.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Placeholder label
* https://github.com/AbleTech/jquery.placeholder-label
*
* Copyright (c) 2010 Able Technology Consulting Limited
* http://www.abletech.co.nz/
*/
(function($) {
$.placeholderLabel = {
placeholder_class: null,
add_placeholder: function(){
if($(this).val() == $(this).attr('placeholder')){
$(this).val('').removeClass($.placeholderLabel.placeholder_class);
}
},
remove_placeholder: function(){
if($(this).val() == ''){
$(this).val($(this).attr('placeholder')).addClass($.placeholderLabel.placeholder_class);
}
},
disable_placeholder_fields: function(){
$(this).find("input[placeholder]").each(function(){
if($(this).val() == $(this).attr('placeholder')){
$(this).val('');
}
});
return true;
}
};
$.fn.placeholderLabel = function(options) {
// detect modern browsers
var dummy = document.createElement('input');
if(dummy.placeholder != undefined){
return this;
}
var config = {
placeholder_class : 'placeholder'
};
if(options) $.extend(config, options);
$.placeholderLabel.placeholder_class = config.placeholder_class;
this.each(function() {
var input = $(this);
input.focus($.placeholderLabel.add_placeholder);
input.blur($.placeholderLabel.remove_placeholder);
input.triggerHandler('focus');
input.triggerHandler('blur');
$(this.form).submit($.placeholderLabel.disable_placeholder_fields);
});
return this;
}
})(jQuery);