diff options
author | Chad Kieffer <chad@2tbsp.com> | 2008-12-17 00:45:52 +0000 |
---|---|---|
committer | Chad Kieffer <chad@2tbsp.com> | 2008-12-17 00:45:52 +0000 |
commit | 3c05b95620f46c7042471371a3cab9d87f7da75e (patch) | |
tree | ff94642b43c373c33055be98063d5ab44fd6871a /themes/default/js/ui.init.js | |
parent | f4c6a20149eceae01d2085264f7facf516fd6bb8 (diff) |
Added JS to set/reset simple forms' input values to their corresponding labels' value. Labels should always be used with visible inputs. Use this to style and control short form input display and behavior.
Diffstat (limited to 'themes/default/js/ui.init.js')
-rw-r--r-- | themes/default/js/ui.init.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/themes/default/js/ui.init.js b/themes/default/js/ui.init.js index 5c75fb02..a7eb7931 100644 --- a/themes/default/js/ui.init.js +++ b/themes/default/js/ui.init.js @@ -42,6 +42,37 @@ $("document").ready(function() { $(dialogLinks[i]).bind("click", {element: dialogLinks[i]}, handleDialogEvent); }; + // Declare which forms are short forms + $("#gHeader #gSearchForm").addClass("gShortForm"); + $("#gSidebar #gAddTagForm").addClass("gShortForm"); + + // Get the short forms + var shortForms = $(".gShortForm"); + + // Set up short form behavior + for (var i=0; i < shortForms.length; i++) { + // Set variables + var shortFormID = "#" + $(shortForms[i]).attr("id"); + var shortInputID = "#" + $(shortFormID + " input:first").attr("id"); + var shortLabelValue = $(shortFormID + " label:first").html(); + + // Set default input value equal to label text + $(shortInputID).val(shortLabelValue); + + // Attach event listeners to inputs + $(shortInputID).bind("focus blur", function(e){ + var eLabelVal = $(this).siblings("label").html(); + var eInputVal = $(this).val(); + // Empty input value if it equals it's label + if (eLabelVal == eInputVal) { + $(this).val(""); + // Reset the input value if it's empty + } else if ($(this).val() == "") { + $(this).val(eLabelVal); + } + }); + }; + }); /** |