summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gallery.form.js48
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);
}
});
}