Skip to content

Commit

Permalink
Merge pull request #2 from sidnair/master
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
msingleton committed Feb 4, 2014
2 parents 900ceb9 + 0ce01f5 commit 485b98f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions jquery.placeholder.js
Expand Up @@ -6,7 +6,7 @@
var clearOnFocus = (options && options['clearOnFocus']) || false;

// If we find a placeholder attribute on the element
if(placeholder != undefined && placeholder != '') {
if (placeholder) {
// Remove the placeholder attribute
$this.removeAttr('placeholder');

Expand All @@ -21,22 +21,27 @@
inputDefault.click(function() { $this.focus(); });

var updateDisplay = function() {
if($this.val().length == 0) {
if ($this.val().length === 0) {
inputDefault.show();
} else {
inputDefault.hide();
}
};

if(clearOnFocus) {
// Hide placeholder if there is text in the input field
updateDisplay();

if (clearOnFocus) {
$this.focus(function(event) {
inputDefault.hide();
});

$this.blur(updateDisplay);
} else {
$this.keydown(function(event) {
if(event.keyCode != '8' && event.keyCode != '9' && event.keyCode != '16') { updateDisplay(); }
if (event.keyCode !== '8' && event.keyCode !== '9' && event.keyCode !== '16') {
updateDisplay();
}
});

$this.keyup(updateDisplay);
Expand All @@ -46,4 +51,4 @@
}
});
};
})(jQuery);
})(jQuery);
4 changes: 2 additions & 2 deletions jquery.placeholder.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 485b98f

Please sign in to comment.