From afbcb3d186afd4e63c86954f8dc211cfa11b832b Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Mon, 29 Aug 2011 10:47:06 -0300 Subject: [PATCH] Beautify html alts and titles automagically --- public/javascripts/application.js | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+), 0 deletions(-) diff --git a/public/javascripts/application.js b/public/javascripts/application.js index c368626..34cc445 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -694,3 +694,82 @@ jQuery(function() { target: "#ajax-form-message-area" }) }); + +/** +* @author Remy Sharp +* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/ +*/ + +(function ($) { + +$.fn.hint = function (blurClass) { + if (!blurClass) { + blurClass = 'blur'; + } + + return this.each(function () { + // get jQuery version of 'this' + var $input = $(this), + + // capture the rest of the variable to allow for reuse + title = $input.attr('title'), + $form = $(this.form), + $win = $(window); + + function remove() { + if ($input.val() === title && $input.hasClass(blurClass)) { + $input.val('').removeClass(blurClass); + } + } + + // only apply logic if the element has the attribute + if (title) { + // on blur, set value to title attr if text is blank + $input.blur(function () { + if (this.value === '') { + $input.val(title).addClass(blurClass); + } + }).focus(remove).blur(); // now change all inputs to title + + // clear the pre-defined text when form is submitted + $form.submit(remove); + $win.unload(remove); // handles Firefox's autocomplete + } + }); +}; + +})(jQuery); + +var altBeautify = jQuery('