| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 // $Id: webform-admin.js,v 1.1.2.4 2010/09/04 18:14:04 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 // Enhance the normal tableselect.js file to support indentations. 15 Drupal.webform.tableSelectIndentation(context); 16 } 17 18 Drupal.webform = Drupal.webform || {}; 19 20 Drupal.webform.defaultValues = function(context) { 21 var $fields = $('.webform-default-value:not(.error)', context); 22 var $forms = $fields.parents('form:first'); 23 $fields.each(function() { 24 this.defaultValue = $(this).attr('rel'); 25 if (this.value != this.defaultValue) { 26 $(this).removeClass('webform-default-value'); 27 } 28 $(this).focus(function() { 29 if (this.value == this.defaultValue) { 30 this.value = ''; 31 $(this).removeClass('webform-default-value'); 32 } 33 }); 34 $(this).blur(function() { 35 if (this.value == '') { 36 $(this).addClass('webform-default-value'); 37 this.value = this.defaultValue; 38 } 39 }); 40 }); 41 42 // Clear all the form elements before submission. 43 $forms.submit(function() { 44 $fields.focus(); 45 }); 46 }; 47 48 Drupal.webform.setActive = function(context) { 49 var setActive = function(e) { 50 $('.form-radio', $(this).parent().parent()).attr('checked', true); 51 e.preventDefault(); 52 }; 53 $('.webform-set-active', context).click(setActive).change(setActive); 54 }; 55 56 Drupal.webform.updateTemplate = function(context) { 57 var defaultTemplate = $('#edit-templates-default').val(); 58 var $templateSelect = $('#webform-template-fieldset select', context); 59 var $templateTextarea = $('#webform-template-fieldset textarea', context); 60 61 var updateTemplateSelect = function() { 62 if ($(this).val() == defaultTemplate) { 63 $templateSelect.val('default'); 64 } 65 else { 66 $templateSelect.val('custom'); 67 } 68 } 69 70 var updateTemplateText = function() { 71 if ($(this).val() == 'default' && $templateTextarea.val() != defaultTemplate) { 72 if (confirm(Drupal.settings.webform.revertConfirm)) { 73 $templateTextarea.val(defaultTemplate); 74 } 75 else { 76 $(this).val('custom'); 77 } 78 } 79 } 80 81 $templateTextarea.keyup(updateTemplateSelect); 82 $templateSelect.change(updateTemplateText); 83 } 84 85 Drupal.webform.tableSelectIndentation = function(context) { 86 var $tables = $('th.select-all', context).parents('table'); 87 $tables.find('input.form-checkbox').change(function() { 88 var $rows = $(this).parents('table:first').find('tr'); 89 var row = $(this).parents('tr:first').get(0); 90 var rowNumber = $rows.index(row); 91 var rowTotal = $rows.size(); 92 var indentLevel = $(row).find('div.indentation').size(); 93 for (var n = rowNumber + 1; n < rowTotal; n++) { 94 if ($rows.eq(n).find('div.indentation').size() <= indentLevel) { 95 break; 96 } 97 $rows.eq(n).find('input.form-checkbox').attr('checked', this.checked); 98 } 99 }); 100 } 101
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |