summaryrefslogtreecommitdiff
path: root/lib/gallery.form.js
diff options
context:
space:
mode:
authorChad Kieffer <chad@2tbsp.com>2009-05-26 03:59:35 +0000
committerChad Kieffer <chad@2tbsp.com>2009-05-26 03:59:35 +0000
commit88e1f02c1a250dae7b8dabeeaf9f6209f4c84942 (patch)
tree810150dedf2aa0bbc273942959202f8c3621bf07 /lib/gallery.form.js
parent916405bc4b572ded4b60a2a2eaececb8402dba0a (diff)
Split out re-used JavaScript for common functions (messages, valign), panel toggle, and forms to external files.
Diffstat (limited to 'lib/gallery.form.js')
-rw-r--r--lib/gallery.form.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/gallery.form.js b/lib/gallery.form.js
new file mode 100644
index 00000000..e69be326
--- /dev/null
+++ b/lib/gallery.form.js
@@ -0,0 +1,42 @@
+/**
+ * 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 #
+ */
+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");
+
+ // Set the input value equal to label text
+ if ($(inputID).val() == "") {
+ $(inputID).val(labelValue);
+ }
+
+ // Attach event listeners to the input
+ $(inputID).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);
+ }
+ });
+}