From aa5d1c27e9ed5a3d0b06c313e2669d2625c338f4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 21 Oct 2010 20:03:41 +0200 Subject: [PATCH] Make input field/textarea replacement working when input field does not start out empty. --- src/main/resources/static/javascript/sone.js | 34 +++++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 53e2369..1d6f0f8 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -5,26 +5,38 @@ function registerInputTextareaSwap(inputSelector, defaultText, inputFieldName, o textarea = $("").blur(function() { if ($(this).val() == "") { $(this).hide(); - $(this).data("inputField").show().removeAttr("disabled"); + inputField = $(this).data("inputField"); + inputField.show().removeAttr("disabled").addClass("default"); + (function(inputField) { + getTranslation(defaultText, function(translation) { + inputField.val(translation); + }); + })(inputField); } - }).hide().data("inputField", $(this)); + }).hide().data("inputField", $(this)).val($(this).val()); $(this).after(textarea); (function(inputField, textarea) { - $(inputField).focus(function() { + inputField.focus(function() { $(this).hide().attr("disabled", "disabled"); textarea.show().focus(); - }).addClass("default"); - (function(inputField) { - getTranslation(defaultText, function(translation) { - $(inputField).val(translation); - }); - })(inputField); - $(inputField.form).submit(function() { + }); + if (inputField.val() == "") { + inputField.addClass("default"); + (function(inputField) { + getTranslation(defaultText, function(translation) { + inputField.val(translation); + }); + })(inputField); + } else { + inputField.hide().attr("disabled", "disabled"); + textarea.show(); + } + $(inputField.get(0).form).submit(function() { if (!optional && (textarea.val() == "")) { return false; } }); - })(this, textarea); + })($(this), textarea); }); } -- 2.7.4