From 992eb8dcf5e50bd73e413d49bd965ed469ca4d62 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sat, 18 Dec 2010 13:34:36 -0800 Subject: [PATCH] Make the placeholder attribute work in older browsers. --- doc-src/assets/javascripts/placeholder.js | 51 +++++++++++++++++++++++ doc-src/layouts/partials/js-core.haml | 1 + 2 files changed, 52 insertions(+) create mode 100644 doc-src/assets/javascripts/placeholder.js diff --git a/doc-src/assets/javascripts/placeholder.js b/doc-src/assets/javascripts/placeholder.js new file mode 100644 index 00000000..7081fb74 --- /dev/null +++ b/doc-src/assets/javascripts/placeholder.js @@ -0,0 +1,51 @@ +(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); + + var $placeholder = $(this); + + if ($placeholder.length > 0) { + + var attrPh = $placeholder.attr('placeholder'); + + $placeholder.attr('value', attrPh); + $placeholder.css('color',settings.blurColor) + .bind('focus', function() { + + var $this = $(this); + + if($this.val() === attrPh) + $this.val('').css('color',settings.focusColor); + + }).bind('blur', function() { + + var $this = $(this); + + if($this.val() === '') + $this.val(attrPh).css('color',settings.blurColor); + + }); + + } + + }); + + }; + +})(jQuery); + +jQuery(function($){ + $(document).ready(function(){ + if (!Modernizr.input.placeholder) { $("input[placeholder], textarea[placeholder]").replaceholder() } + }) +}) \ No newline at end of file diff --git a/doc-src/layouts/partials/js-core.haml b/doc-src/layouts/partials/js-core.haml index b7c3d547..3db68129 100644 --- a/doc-src/layouts/partials/js-core.haml +++ b/doc-src/layouts/partials/js-core.haml @@ -1,5 +1,6 @@ %script(src="/javascripts/modernizr-1.6.min.js" type="text/javascript") %script(src="/javascripts/jquery-1.3.2.min.js" type="text/javascript") %script(src="/javascripts/jquery.cookie.js" type="text/javascript") +%script(src="/javascripts/placeholder.js" type="text/javascript" deferred) %script(src="/javascripts/site.js" type="text/javascript") %script(src="/javascripts/fixups.js" type="text/javascript" deferred)