fixed placeholder js to add classname when placeholder is active. this should allow me to style placeholders with css (allowing for multiple color scheme support) rather than the default assignment of colors via javascript options

This commit is contained in:
Brandon Mathis 2010-12-18 21:53:03 -06:00
parent 638fd8f543
commit 02d6292af6

View File

@ -7,10 +7,7 @@
(this.length > 0) ? $this = $(this) : $this = $('input[placeholder]'); (this.length > 0) ? $this = $(this) : $this = $('input[placeholder]');
return $this.each(function() { return $this.each(function() {
settings = jQuery.extend({ settings = jQuery.extend(options);
focusColor: '#000',
blurColor: '#aaa'
}, options);
var $placeholder = $(this); var $placeholder = $(this);
@ -19,20 +16,19 @@
var attrPh = $placeholder.attr('placeholder'); var attrPh = $placeholder.attr('placeholder');
$placeholder.attr('value', attrPh); $placeholder.attr('value', attrPh);
$placeholder.css('color',settings.blurColor) $placeholder.bind('focus', function() {
.bind('focus', function() {
var $this = $(this); var $this = $(this);
if($this.val() === attrPh) if($this.val() === attrPh)
$this.val('').css('color',settings.focusColor); $this.val('').removeClass('placeholder');
}).bind('blur', function() { }).bind('blur', function() {
var $this = $(this); var $this = $(this);
if($this.val() === '') if($this.val() === '')
$this.val(attrPh).css('color',settings.blurColor); $this.val(attrPh).addClass('placeholder');
}); });