From ca66fa917c8e297e1403dc916de96f50130af270 Mon Sep 17 00:00:00 2001 From: Christopher Lenz Date: Tue, 19 Jan 2010 22:37:41 +0000 Subject: Futon: Simplify placeholder fallback using jQuery live focus events. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@900989 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/futon.js | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) (limited to 'share/www/script/futon.js') diff --git a/share/www/script/futon.js b/share/www/script/futon.js index e2bdb468..18843eb7 100644 --- a/share/www/script/futon.js +++ b/share/www/script/futon.js @@ -362,31 +362,21 @@ storage: new Storage() }); - $.fn.addPlaceholder = function(text) { - return this.each(function() { + $.fn.addPlaceholder = function() { + if (this[0] && "placeholder" in document.createElement("input")) { + return; // found native placeholder support + } + return this.live('focusin', function() { var input = $(this); - if ($.browser.safari) { - input.attr("placeholder", text); - return; + if (input.val() === input.attr("placeholder")) { + input.removeClass("placeholder").val(""); } - input.blur(function() { - if ($.trim(input.val()) == "") { - input.addClass("placeholder").val(text); - } else { - input.removeClass("placeholder"); - } - }).triggerHandler("blur") - input.focus(function() { - if (input.is(".placeholder")) { - input.val("").removeClass("placeholder"); - } - }); - $(this.form).submit(function() { - if (input.is(".placeholder")) { - input.val(""); - } - }); - }); + }).live("focusout", function() { + var input = $(this); + if (input.val() === "") { + input.val(input.attr("placeholder")).addClass("placeholder"); + } + }).trigger("focusout"); } $.fn.enableTabInsertion = function(chars) { @@ -422,6 +412,8 @@ // doing this as early as possible prevents flickering $(document.body).addClass("fullwidth"); } + $("input[placeholder]").addPlaceholder(); + $.get("_sidebar.html", function(resp) { $("#wrap").append(resp) .find("#sidebar-toggle").click(function(e) { @@ -443,7 +435,6 @@ $("#version").text(info.version); } }); - }); }); -- cgit v1.2.3