summaryrefslogtreecommitdiff
path: root/themes/default/js
diff options
context:
space:
mode:
authorChad Kieffer <chad@2tbsp.com>2008-12-30 02:50:52 +0000
committerChad Kieffer <chad@2tbsp.com>2008-12-30 02:50:52 +0000
commit27009ad852d987319f37b38660cd91fc46375b17 (patch)
tree103e843b74914a7e89bf52221ca1b10b89c3f94c /themes/default/js
parent96a2f929ca6b07d25be70273151738ebda719883 (diff)
Drop .gShortForm in favor of using specific form ids (gSearchForm, gAddTagForm). This maintains styles when forms are are reloaded into the DOM. Haven't figured out how to fire shortFormInit() when a form is reloaded into the DOM, as gAddTagForm is :(
Diffstat (limited to 'themes/default/js')
-rw-r--r--themes/default/js/ui.init.js79
1 files changed, 49 insertions, 30 deletions
diff --git a/themes/default/js/ui.init.js b/themes/default/js/ui.init.js
index cb9fa07c..c282ce74 100644
--- a/themes/default/js/ui.init.js
+++ b/themes/default/js/ui.init.js
@@ -1,6 +1,14 @@
/**
* Initialize jQuery UI and Plugin elements
+ *
+ * @todo Standardize how elements requiring listeners are identified (class or id)
*/
+
+var shortForms = new Array(
+ "#gSearchForm",
+ "#gAddTagForm"
+);
+
$("document").ready(function() {
// Vertical align thumbnails/metadata in album grid
@@ -49,36 +57,8 @@ $("document").ready(function() {
};
// 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);
- }
- });
- };
-
+ handleShortFormEvent(shortForms);
+
});
// Vertically align a block element's content
@@ -179,6 +159,45 @@ function openDialog(element) {
}
/**
+ * Handle initialization of all short forms
+ *
+ * @param array shortForms 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 string formID The form's ID, including #
+ */
+function shortFormInit(formID) {
+ // 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
+ $(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);
+ }
+ });
+}
+
+/**
* Toggle the processing indicator, both large and small
*
* @param element ID to which to apply the loading class, including #