/** * HTML5 Placeholders for old browsers * by Rutger Laurman * * Adds HTML5 placeholders to non-supported browsers with jQuery * Fork from Marc Görtz */ var HTML5Placeholders; HTML5Placeholders = { addPlaceholders: function(props) { var config, key, testform; config = { "class": "placeholder" }; for (key in props) { if (config.hasOwnProperty(key)) { config[key] = props[key]; } } testform = $("
"); $.extend($.support, { placeHolder: !!($("input", testform)[0].placeholder !== undefined || $("input", testform)[0].placeHolder !== undefined) }); if (!$.support.placeHolder) { $("html").addClass("no-placeholder"); return $("input[placeholder], textarea[placeholder]").each(function() { var placeholder; placeholder = $(this).attr("placeholder"); $(this).bind({ focus: function() { if ($(this).val() === placeholder) { $(this).val(""); $(this).removeClass(config["class"]); } return $(this).attr("data-focused", "yes"); }, blur: function() { if ($(this).val() === "") { $(this).val(placeholder); $(this).addClass(config["class"]); } return $(this).removeAttr("data-focused"); } }); if ((($(this).val() === "") || ($(this).val() === placeholder)) && (!$(this).attr("data-focused"))) { $(this).val(placeholder); return $(this).addClass(config["class"]); } }); } else { $("html").addClass("placeholder"); } } }; $(document).ready(function() { return HTML5Placeholders.addPlaceholders(); });