Skip to content

Commit

Permalink
Don't remove class if the input is equal to the placeholder text.
Browse files Browse the repository at this point in the history
This should fix issue mathiasbynens#109 upstream.
  • Loading branch information
mrhmouse committed Jun 13, 2013
1 parent b7f508e commit 3eec0df
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions jquery.placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,43 +115,60 @@
}
}
}

function setPlaceholder() {
var $replacement,
input = this,
$input = $(input),
$origInput = $input,
id = this.id;
if (input.value == '') {
if (input.type == 'password') {
var
$replacement,
input,
$input,
id;

id = this.id;
input = this;
$input = $(input);

if (input.value === '') {
if (input.type === 'password') {
if (!$input.data('placeholder-textinput')) {
try {
$replacement = $input.clone().attr({ 'type': 'text' });
$replacement = $input
.clone()
.attr({
type: 'text'
});
} catch(e) {
$replacement = $('<input>').attr($.extend(args(this), { 'type': 'text' }));
$replacement = $('<input>')
.attr($.extend(args(this), {
type: 'text'
}));
}

$replacement
.removeAttr('name')
.data({
'placeholder-password': true,
'placeholder-id': id
})
.bind('focus.placeholder', clearPlaceholder);

$input
.data({
'placeholder-textinput': $replacement,
'placeholder-id': id
})
.before($replacement);
}
$input = $input.removeAttr('id').hide().prev().attr('id', id).show();
$input = $input
.removeAttr('id')
.hide()
.prev()
.attr('id', id)
.show();
// Note: `$input[0] != input` now!
}
$input.addClass('placeholder');
$input[0].value = $input.attr('placeholder');
} else {
} else if (input.value !== $input.attr('placeholder')) {
$input.removeClass('placeholder');
}
}

}(this, document, jQuery));
}(this, document, jQuery));

0 comments on commit 3eec0df

Please sign in to comment.