blob: e1a24290c9ca1f2d8a957461c553c6ccb17e36c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/**
* 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", 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("");
}
});
$(inputID).bind("blur", function(e){
var eLabelVal = $(this).siblings("label").html();
// Reset the input value if it's empty
if ($(this).val() == "") {
$(this).val(eLabelVal);
}
});
}
|