﻿
// Super sweet focus behavior for textboxes!
// clears out & replaces hint text in form textbox fields on focus
// put initial value back in if user blurs & hasn't entered new value
// ex: <input type="text" value="initial value" class="efHoverImage" />
// when called: $().efTextboxFocus(); will automatically set up focus behavior on all inputs with class .efTextboxFocus
// or can call function on specific element(s) $('.selector').efTextboxFocus();

(function ($) {
    $.fn.extend({
        efTextboxFocus: function (args) {
            // if no selector passed in, get set of specifically named class elements
            var textboxes = (args !== "" && jQuery(args).length > 0) ? jQuery(args) : jQuery('.efTextboxFocus');

            return textboxes.each(function () {
                var $this = $(this);

                // get init text val and save into the object
                $this.data("initVal", $this.val());

                // show/hide text in field on focus
                $this.focus(function () {
                    var v = $(this).val();
                    $(this).val(v === $this.data("initVal") ? '' : v);
                }).blur(function () {
                    var v = $(this).val();
                    $(this).val(v === '' ? $this.data("initVal") : v);
                });
            });
        }
    });
})(jQuery);
