Skip to content

Commit 3eec0df

Browse files
committed
Don't remove class if the input is equal to the placeholder text.
This should fix issue mathiasbynens#109 upstream.
1 parent b7f508e commit 3eec0df

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

jquery.placeholder.js

+31-14
Original file line numberDiff line numberDiff line change
@@ -115,43 +115,60 @@
115115
}
116116
}
117117
}
118-
119118
function setPlaceholder() {
120-
var $replacement,
121-
input = this,
122-
$input = $(input),
123-
$origInput = $input,
124-
id = this.id;
125-
if (input.value == '') {
126-
if (input.type == 'password') {
119+
var
120+
$replacement,
121+
input,
122+
$input,
123+
id;
124+
125+
id = this.id;
126+
input = this;
127+
$input = $(input);
128+
129+
if (input.value === '') {
130+
if (input.type === 'password') {
127131
if (!$input.data('placeholder-textinput')) {
128132
try {
129-
$replacement = $input.clone().attr({ 'type': 'text' });
133+
$replacement = $input
134+
.clone()
135+
.attr({
136+
type: 'text'
137+
});
130138
} catch(e) {
131-
$replacement = $('<input>').attr($.extend(args(this), { 'type': 'text' }));
139+
$replacement = $('<input>')
140+
.attr($.extend(args(this), {
141+
type: 'text'
142+
}));
132143
}
144+
133145
$replacement
134146
.removeAttr('name')
135147
.data({
136148
'placeholder-password': true,
137149
'placeholder-id': id
138150
})
139151
.bind('focus.placeholder', clearPlaceholder);
152+
140153
$input
141154
.data({
142155
'placeholder-textinput': $replacement,
143156
'placeholder-id': id
144157
})
145158
.before($replacement);
146159
}
147-
$input = $input.removeAttr('id').hide().prev().attr('id', id).show();
160+
$input = $input
161+
.removeAttr('id')
162+
.hide()
163+
.prev()
164+
.attr('id', id)
165+
.show();
148166
// Note: `$input[0] != input` now!
149167
}
150168
$input.addClass('placeholder');
151169
$input[0].value = $input.attr('placeholder');
152-
} else {
170+
} else if (input.value !== $input.attr('placeholder')) {
153171
$input.removeClass('placeholder');
154172
}
155173
}
156-
157-
}(this, document, jQuery));
174+
}(this, document, jQuery));

0 commit comments

Comments
 (0)