diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-09-16 07:02:22 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-09-16 07:02:22 -0700 |
commit | b8201a71127a096a51ed03e0e08a98a66f847c8f (patch) | |
tree | d806f0b9f35fc3aa912126ad3cf8d67c19ec0def /lib/gallery.form.js | |
parent | 15515fd3c64dd626746468862d5b8777679d88f6 (diff) | |
parent | f1887422f8b4ba68dc273fe6f7d3f1123681e89a (diff) |
Merge branch 'master' of git@github.com:gallery/gallery3 into talmdal_dev
Diffstat (limited to 'lib/gallery.form.js')
-rw-r--r-- | lib/gallery.form.js | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/lib/gallery.form.js b/lib/gallery.form.js index e69be326..77ce3b7d 100644 --- a/lib/gallery.form.js +++ b/lib/gallery.form.js @@ -1,42 +1,34 @@ /** - * Handle initialization of all short forms - * - * @param shortForms array Array of short form IDs - */ -function handleShortFormEvent(shortForms) { - for (var i in shortForms) { - shortFormInit(shortForms[i]); - } -} - -/** * Initialize a short form. Short forms may contain only one text input. * - * @param formID string The form's ID, including # + * @param form_id string The form's CSS id */ -function shortFormInit(formID) { - $(formID).addClass("gShortForm"); - - // Get the input ID and it's label text - var labelValue = $(formID + " label:first").html(); - var inputID = "#" + $(formID + " input[type=text]:first").attr("id"); +function short_form_init(form_id) { + var form = $(form_id); + var label = form.find("label:first"); + var input = form.find("input[type=text]:first"); + var button = form.find("input[type=submit]"); // Set the input value equal to label text - if ($(inputID).val() == "") { - $(inputID).val(labelValue); + if (input.val() == "") { + input.val(label.html()); + button.enable(false); } // Attach event listeners to the input - $(inputID).bind("focus blur", function(e){ - var eLabelVal = $(this).siblings("label").html(); - var eInputVal = $(this).val(); - + input.bind("focus", function(e) { // Empty input value if it equals it's label - if (eLabelVal == eInputVal) { - $(this).val(""); + if ($(this).val() == label.html()) { + $(this).val(""); + } + button.enable(true); + }); + + input.bind("blur", function(e){ // Reset the input value if it's empty - } else if ($(this).val() == "") { - $(this).val(eLabelVal); + if ($(this).val() == "") { + $(this).val(label.html()); + button.enable(false); } }); } |