-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathjquery.simpleplaceholder.js
More file actions
61 lines (50 loc) · 1.46 KB
/
jquery.simpleplaceholder.js
File metadata and controls
61 lines (50 loc) · 1.46 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
51
52
53
54
55
56
57
58
59
60
61
/******************************
Simple Placeholder
******************************/
(function($) {
$.simplePlaceholder = {
placeholder_class: null,
hide_placeholder: function(){
var $this = $(this);
if($this.val() == $this.attr('placeholder')){
$this.val("").removeClass($.simplePlaceholder.placeholder_class);
}
},
show_placeholder: function(){
var $this = $(this);
if($this.val() == ""){
$this.val($this.attr('placeholder')).addClass($.simplePlaceholder.placeholder_class);
}
},
prevent_placeholder_submit: function(){
$(this).find(".simple-placeholder").each(function(e){
var $this = $(this);
if($this.val() == $this.attr('placeholder')){
$this.val('');
}
});
return true;
}
};
$.fn.simplePlaceholder = function(options) {
if(document.createElement('input').placeholder == undefined){
var config = {
placeholder_class : 'placeholding'
};
if(options) $.extend(config, options);
$.simplePlaceholder.placeholder_class = config.placeholder_class;
this.each(function() {
var $this = $(this);
$this.focus($.simplePlaceholder.hide_placeholder);
$this.blur($.simplePlaceholder.show_placeholder);
if($this.val()='') {
$this.val($this.attr("placeholder"));
$this.addClass($.simplePlaceholder.placeholder_class);
}
$this.addClass("simple-placeholder");
$(this.form).submit($.simplePlaceholder.prevent_placeholder_submit);
});
}
return this;
};
})(jQuery);