From: David ‘Bombe’ Roden Date: Thu, 21 Oct 2010 18:03:41 +0000 (+0200) Subject: Make input field/textarea replacement working when input field does not start out... X-Git-Tag: 0.1-RC1~109 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=aa5d1c27e9ed5a3d0b06c313e2669d2625c338f4;p=Sone.git Make input field/textarea replacement working when input field does not start out empty. --- 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); }); }