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

@ -1,51 +1,47 @@
(function($) {
$.fn.replaceholder = function(options) {
var $placeholder;
(this.length > 0) ? $this = $(this) : $this = $('input[placeholder]');
return $this.each(function() {
settings = jQuery.extend({
focusColor: '#000',
blurColor: '#aaa'
}, options);
settings = jQuery.extend(options);
var $placeholder = $(this);
if ($placeholder.length > 0) {
var attrPh = $placeholder.attr('placeholder');
$placeholder.attr('value', attrPh);
$placeholder.css('color',settings.blurColor)
.bind('focus', function() {
$placeholder.bind('focus', function() {
var $this = $(this);
if($this.val() === attrPh)
$this.val('').css('color',settings.focusColor);
$this.val('').removeClass('placeholder');
}).bind('blur', function() {
var $this = $(this);
if($this.val() === '')
$this.val(attrPh).css('color',settings.blurColor);
$this.val(attrPh).addClass('placeholder');
});
}
});
};
})(jQuery);
jQuery(function($){
$(document).ready(function(){
if (!Modernizr.input.placeholder) { $("input[placeholder], textarea[placeholder]").replaceholder() }
})
})
})