diff options
author | Christopher Lenz <cmlenz@apache.org> | 2010-01-19 22:37:41 +0000 |
---|---|---|
committer | Christopher Lenz <cmlenz@apache.org> | 2010-01-19 22:37:41 +0000 |
commit | ca66fa917c8e297e1403dc916de96f50130af270 (patch) | |
tree | 240944c89c3f28cb9e9e18372b9856dd97891a13 /share/www/script | |
parent | 30a45a978e3b6aa6c206fccab66a6ca383fc5fe6 (diff) |
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
Diffstat (limited to 'share/www/script')
-rw-r--r-- | share/www/script/futon.js | 39 |
1 files changed, 15 insertions, 24 deletions
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); } }); - }); }); |