| 1 |
// $Id: webform.js,v 1.4 2009/05/07 22:38:13 quicksketch Exp $
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Webform node form interface enhancments.
|
| 5 |
*/
|
| 6 |
|
| 7 |
Drupal.behaviors.webform = function(context) {
|
| 8 |
// Apply special behaviors to fields with default values.
|
| 9 |
Drupal.webform.defaultValues(context);
|
| 10 |
// On click or change, make a parent radio button selected.
|
| 11 |
Drupal.webform.setActive(context);
|
| 12 |
// Update the template select list upon changing a template.
|
| 13 |
Drupal.webform.updateTemplate(context);
|
| 14 |
}
|
| 15 |
|
| 16 |
Drupal.webform = new Object();
|
| 17 |
|
| 18 |
Drupal.webform.defaultValues = function(context) {
|
| 19 |
var $fields = $('.webform-default-value', context);
|
| 20 |
var $forms = $('.webform-default-value', context).parents('form:first');
|
| 21 |
$fields.each(function() {
|
| 22 |
this.defaultValue = this.value;
|
| 23 |
$(this).focus(function() {
|
| 24 |
if (this.value == this.defaultValue) {
|
| 25 |
this.value = '';
|
| 26 |
$(this).removeClass('webform-default-value');
|
| 27 |
}
|
| 28 |
});
|
| 29 |
$(this).blur(function() {
|
| 30 |
if (this.value == '') {
|
| 31 |
$(this).addClass('webform-default-value');
|
| 32 |
this.value = this.defaultValue;
|
| 33 |
}
|
| 34 |
});
|
| 35 |
});
|
| 36 |
|
| 37 |
// Clear all the form elements before submission.
|
| 38 |
$forms.submit(function() {
|
| 39 |
$fields.focus();
|
| 40 |
});
|
| 41 |
};
|
| 42 |
|
| 43 |
Drupal.webform.setActive = function(context) {
|
| 44 |
var setActive = function() {
|
| 45 |
$('.form-radio', $(this).parent().parent()).attr('checked', true);
|
| 46 |
};
|
| 47 |
$('.webform-set-active', context).click(setActive).change(setActive);
|
| 48 |
};
|
| 49 |
|
| 50 |
Drupal.webform.updateTemplate = function(context) {
|
| 51 |
var defaultTemplate = $('#edit-templates-default').val();
|
| 52 |
var $templateSelect = $('#webform-template-fieldset select', context);
|
| 53 |
var $templateTextarea = $('#webform-template-fieldset textarea', context);
|
| 54 |
|
| 55 |
var updateTemplateSelect = function() {
|
| 56 |
if ($(this).val() == defaultTemplate) {
|
| 57 |
$templateSelect.val('default');
|
| 58 |
}
|
| 59 |
else {
|
| 60 |
$templateSelect.val('custom');
|
| 61 |
}
|
| 62 |
}
|
| 63 |
|
| 64 |
var updateTemplateText = function() {
|
| 65 |
if ($(this).val() == 'default') {
|
| 66 |
$templateTextarea.val(defaultTemplate);
|
| 67 |
}
|
| 68 |
}
|
| 69 |
|
| 70 |
$templateTextarea.keyup(updateTemplateSelect);
|
| 71 |
$templateSelect.change(updateTemplateText);
|
| 72 |
}
|