-
Notifications
You must be signed in to change notification settings - Fork 0
/
placehold.jquery.js
44 lines (35 loc) · 988 Bytes
/
placehold.jquery.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
// placehold. Yet Another Placeholder Plugin.. (c) Joseph Giuffrida MIT/GPLv2 Lic. http://www.github.com/hots0uce/placehold
(function($) {
$.fn.placehold = function() {
var nativeSupport = (function() {
var el = document.createElement('input');
return ('placeholder' in el);
})();
return this.each(function() {
if(!nativeSupport) {
var $this = $(this),
$wrapper = $('<span />').addClass('placeholder-wrapper').css('position','relative'),
$cover = $('<span />').css({'position':'absolute','top':'0','left':'0','z-index':1}),
that = this,
val = $this.attr('value');
$cover.text($this.attr('placeholder'));
$this.wrap($wrapper);
$this.parent().append($cover);
$cover.click(function() {
$this.focus();
});
$this.blur(function() {
if(!val) {
$cover.show();
}
});
$this.focus(function() {
$cover.hide();
});
if(val) {
$cover.hide();
}
}
});
};
})(jQuery);