-
Notifications
You must be signed in to change notification settings - Fork 20
/
gf.placeholders.js
executable file
·50 lines (40 loc) · 1.2 KB
/
gf.placeholders.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
(function($){
var gf_placeholder = function() {
$('.gform_wrapper .gplaceholder')
.find('input, textarea').filter(function(i){
var $field = $(this);
if (this.nodeName == 'INPUT') {
var type = this.type;
return !(type == 'hidden' || type == 'file' || type == 'radio' || type == 'checkbox');
}
return true;
})
.each(function(){
var $field = $(this);
var id = this.id;
var $labels = $('label[for=' + id + ']').hide();
var label = $labels.last().text();
if (label.length > 0 && label[ label.length-1 ] == '*') {
label = label.substring(0, label.length-1) + ' *';
}
$field[0].setAttribute('placeholder', label);
});
var support = (!('placeholder' in document.createElement('input'))); // borrowed from Modernizr.com
if ( support && jquery_placeholder_url )
$.ajax({
cache: true,
dataType: 'script',
url: jquery_placeholder_url,
success: function() {
$('input[placeholder], textarea[placeholder]').placeholder({
blankSubmit: true
});
},
type: 'get'
});
};
$(document).ready(function(){
gf_placeholder();
$(document).bind('gform_post_render', gf_placeholder);
});
})(jQuery);