-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.placeholder.js
36 lines (35 loc) · 977 Bytes
/
jquery.placeholder.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
/*
## jQuery Placeholder (2014)
## Author: Siamak Aghaeipour Motlagh
## Email: siamak.aghaeipour@gmail.com
## Website: http://blacksrc.com
*/
(function($) {
$.fn.placeholder = function(options) {
var config = $.extend({
force : false
}, options);
var el = document.createElement('input');
var support = ('placeholder' in el);
return this.each( function() {
if(config.force==true || !support) {
$(this).each(function() {
var input = $(this);
var ph = $(this).attr('placeholder');
typeof(ph) != 'undefined' ? input.val(ph) : '';
});
$(this).focus(function() {
var input = $(this);
var vl = $.trim(input.val());
var ph = $(this).attr('placeholder');
vl == ph ? $(this).val('') : '';
}).blur(function() {
var input = $(this);
var vl = $.trim(input.val());
var ph = $(this).attr('placeholder');
(vl == '' && vl != ph) ? input.val(ph) : '';
});
}
});
}
}(jQuery));