Skip to content

Commit

Permalink
removed redundant checks for password inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstocks committed Jul 8, 2010
1 parent ecc9b9d commit 235f7cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script src="jquery.placeholder.js"></script>
<title>jQuery-Placeholder</title>
<style>
input {padding:4px; width:200px;}
input {padding:4px; width:225px;}
</style>
</head>
<body>
Expand Down
10 changes: 4 additions & 6 deletions jquery.placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
// Special treatment for password inputs
if (input.attr('type') == 'password') {
input.attr('realType', 'password');
this.isPassword = true;
}
this.input = input;
// IE doesn't allow changing the type of password inputs
this.fakePassword = $("<input>").val(input.attr('placeholder')).focus(function() {
input.trigger("focus")
$(this).hide();
}).css({width : input.width()});
});
}
Placeholder.prototype = {
show : function(loading) {
// FF and IE saves values when you refresh the page. If the user refreshes the page with
// the placeholders showing they will be the default values and the input fields won't be empty.
if (this.input[0].value == '' || (loading && this.valueIsPlaceholder())) {
if (this.isPassword()) {
if (this.isPassword) {
try { // IE doesn't allow us to change the input type
this.input[0].setAttribute('type', 'input');
} catch (e) {
Expand All @@ -35,7 +36,7 @@
},
hide : function() {
if (this.valueIsPlaceholder() && this.input.hasClass('placeholder')) {
if (this.isPassword()) {
if (this.isPassword) {
try {
this.input[0].setAttribute('type', 'password');
} catch (e) { }
Expand All @@ -47,9 +48,6 @@
this.input.removeClass('placeholder');
}
},
isPassword: function() {
return this.input.attr('realType') == 'password';
},
valueIsPlaceholder : function() {
return this.input[0].value == this.input.attr('placeholder');
}
Expand Down

0 comments on commit 235f7cd

Please sign in to comment.