1 |
85ad3d82
|
Assos Assos
|
(function ($) {
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
Drupal.behaviors.webformAdmin = {};
|
8 |
|
|
Drupal.behaviors.webformAdmin.attach = function(context) {
|
9 |
|
|
|
10 |
|
|
Drupal.webform.defaultValues(context);
|
11 |
|
|
|
12 |
|
|
Drupal.webform.setActive(context);
|
13 |
|
|
|
14 |
|
|
Drupal.webform.updateTemplate(context);
|
15 |
|
|
|
16 |
|
|
Drupal.webform.selectCheckboxesLink(context);
|
17 |
|
|
|
18 |
|
|
Drupal.webform.tableSelectIndentation(context);
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
Drupal.webform = Drupal.webform || {};
|
22 |
|
|
|
23 |
|
|
Drupal.webform.defaultValues = function(context) {
|
24 |
|
|
var $fields = $('.webform-default-value:not(.error)', context);
|
25 |
|
|
var $forms = $fields.parents('form:first');
|
26 |
|
|
$fields.each(function() {
|
27 |
|
|
this.defaultValue = $(this).attr('rel');
|
28 |
|
|
if (this.value != this.defaultValue) {
|
29 |
|
|
$(this).removeClass('webform-default-value');
|
30 |
|
|
}
|
31 |
|
|
$(this).focus(function() {
|
32 |
|
|
if (this.value == this.defaultValue) {
|
33 |
|
|
this.value = '';
|
34 |
|
|
$(this).removeClass('webform-default-value');
|
35 |
|
|
}
|
36 |
|
|
});
|
37 |
|
|
$(this).blur(function() {
|
38 |
|
|
if (this.value == '') {
|
39 |
|
|
$(this).addClass('webform-default-value');
|
40 |
|
|
this.value = this.defaultValue;
|
41 |
|
|
}
|
42 |
|
|
});
|
43 |
|
|
});
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
$forms.submit(function() {
|
47 |
|
|
$fields.focus();
|
48 |
|
|
});
|
49 |
|
|
};
|
50 |
|
|
|
51 |
|
|
Drupal.webform.setActive = function(context) {
|
52 |
|
|
var setActive = function(e) {
|
53 |
|
|
$('.form-radio', $(this).parent().parent()).attr('checked', true);
|
54 |
|
|
e.preventDefault();
|
55 |
|
|
};
|
56 |
|
|
$('.webform-set-active', context).click(setActive).change(setActive);
|
57 |
|
|
};
|
58 |
|
|
|
59 |
|
|
Drupal.webform.updateTemplate = function(context) {
|
60 |
|
|
var defaultTemplate = $('#edit-templates-default').val();
|
61 |
|
|
var $templateSelect = $('#webform-template-fieldset select#edit-template-option', context);
|
62 |
|
|
var $templateTextarea = $('#webform-template-fieldset textarea:visible', context);
|
63 |
|
|
|
64 |
|
|
var updateTemplateSelect = function() {
|
65 |
|
|
if ($(this).val() == defaultTemplate) {
|
66 |
|
|
$templateSelect.val('default');
|
67 |
|
|
}
|
68 |
|
|
else {
|
69 |
|
|
$templateSelect.val('custom');
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
var updateTemplateText = function() {
|
74 |
|
|
if ($(this).val() == 'default' && $templateTextarea.val() != defaultTemplate) {
|
75 |
|
|
if (confirm(Drupal.settings.webform.revertConfirm)) {
|
76 |
|
|
$templateTextarea.val(defaultTemplate);
|
77 |
|
|
}
|
78 |
|
|
else {
|
79 |
|
|
$(this).val('custom');
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
$templateTextarea.keyup(updateTemplateSelect);
|
85 |
|
|
$templateSelect.change(updateTemplateText);
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
Drupal.webform.selectCheckboxesLink = function(context) {
|
89 |
|
|
function selectCheckboxes() {
|
90 |
|
|
var group = this.className.replace(/.*?webform-select-link-([^ ]*).*/, '$1');
|
91 |
|
|
var $checkboxes = $('.webform-select-group-' + group + ' input[type=checkbox]');
|
92 |
|
|
var reverseCheck = !$checkboxes[0].checked;
|
93 |
|
|
$checkboxes.each(function() {
|
94 |
|
|
this.checked = reverseCheck;
|
95 |
|
|
});
|
96 |
|
|
$checkboxes.trigger('change');
|
97 |
|
|
return false;
|
98 |
|
|
}
|
99 |
|
|
$('a.webform-select-link', context).click(selectCheckboxes);
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
Drupal.webform.tableSelectIndentation = function(context) {
|
103 |
|
|
var $tables = $('th.select-all', context).parents('table');
|
104 |
|
|
$tables.find('input.form-checkbox').change(function() {
|
105 |
|
|
var $rows = $(this).parents('table:first').find('tr');
|
106 |
|
|
var row = $(this).parents('tr:first').get(0);
|
107 |
|
|
var rowNumber = $rows.index(row);
|
108 |
|
|
var rowTotal = $rows.size();
|
109 |
|
|
var indentLevel = $(row).find('div.indentation').size();
|
110 |
|
|
for (var n = rowNumber + 1; n < rowTotal; n++) {
|
111 |
|
|
if ($rows.eq(n).find('div.indentation').size() <= indentLevel) {
|
112 |
|
|
break;
|
113 |
|
|
}
|
114 |
|
|
$rows.eq(n).find('input.form-checkbox').attr('checked', this.checked);
|
115 |
|
|
}
|
116 |
|
|
});
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
})(jQuery); |