From 02d6292af6d778c6a0ad060037f35e342286571b Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sat, 18 Dec 2010 21:53:03 -0600 Subject: [PATCH] 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 --- doc-src/assets/javascripts/placeholder.js | 50 +++++++++++------------ 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/doc-src/assets/javascripts/placeholder.js b/doc-src/assets/javascripts/placeholder.js index 7081fb74..af978437 100644 --- a/doc-src/assets/javascripts/placeholder.js +++ b/doc-src/assets/javascripts/placeholder.js @@ -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() } }) -}) \ No newline at end of file +})