1 |
85ad3d82
|
Assos Assos
|
|
2 |
a45e4bc1
|
Assos Assos
|
|
3 |
85ad3d82
|
Assos Assos
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
(function ($) {
|
7 |
|
|
|
8 |
a45e4bc1
|
Assos Assos
|
"use strict";
|
9 |
85ad3d82
|
Assos Assos
|
|
10 |
a45e4bc1
|
Assos Assos
|
Drupal.behaviors.webform = Drupal.behaviors.webform || {};
|
11 |
85ad3d82
|
Assos Assos
|
|
12 |
a45e4bc1
|
Assos Assos
|
Drupal.behaviors.webform.attach = function (context) {
|
13 |
|
|
|
14 |
|
|
Drupal.webform.datepicker(context);
|
15 |
85ad3d82
|
Assos Assos
|
|
16 |
a45e4bc1
|
Assos Assos
|
|
17 |
|
|
if (Drupal.settings.webform && Drupal.settings.webform.conditionals) {
|
18 |
|
|
Drupal.webform.conditional(context);
|
19 |
85ad3d82
|
Assos Assos
|
}
|
20 |
a45e4bc1
|
Assos Assos
|
};
|
21 |
|
|
|
22 |
|
|
Drupal.webform = Drupal.webform || {};
|
23 |
|
|
|
24 |
|
|
Drupal.webform.datepicker = function (context) {
|
25 |
|
|
$('div.webform-datepicker').each(function () {
|
26 |
|
|
var $webformDatepicker = $(this);
|
27 |
|
|
var $calendar = $webformDatepicker.find('input.webform-calendar');
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
if ($calendar.length == 0) {
|
31 |
|
|
return;
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
var startDate = $calendar[0].className.replace(/.*webform-calendar-start-(\d{4}-\d{2}-\d{2}).*/, '$1').split('-');
|
35 |
|
|
var endDate = $calendar[0].className.replace(/.*webform-calendar-end-(\d{4}-\d{2}-\d{2}).*/, '$1').split('-');
|
36 |
|
|
var firstDay = $calendar[0].className.replace(/.*webform-calendar-day-(\d).*/, '$1');
|
37 |
|
|
|
38 |
|
|
startDate = new Date(startDate[0], startDate[1] - 1, startDate[2]);
|
39 |
|
|
endDate = new Date(endDate[0], endDate[1] - 1, endDate[2]);
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
if (startDate > endDate) {
|
43 |
|
|
var laterDate = startDate;
|
44 |
|
|
startDate = endDate;
|
45 |
|
|
endDate = laterDate;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
var startYear = startDate.getFullYear();
|
49 |
|
|
var endYear = endDate.getFullYear();
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
$calendar.datepicker({
|
53 |
|
|
dateFormat: 'yy-mm-dd',
|
54 |
|
|
yearRange: startYear + ':' + endYear,
|
55 |
|
|
firstDay: parseInt(firstDay),
|
56 |
|
|
minDate: startDate,
|
57 |
|
|
maxDate: endDate,
|
58 |
|
|
onSelect: function (dateText, inst) {
|
59 |
|
|
var date = dateText.split('-');
|
60 |
|
|
$webformDatepicker.find('select.year, input.year').val(+date[0]).trigger('change');
|
61 |
|
|
$webformDatepicker.find('select.month').val(+date[1]).trigger('change');
|
62 |
|
|
$webformDatepicker.find('select.day').val(+date[2]).trigger('change');
|
63 |
|
|
},
|
64 |
|
|
beforeShow: function (input, inst) {
|
65 |
|
|
|
66 |
|
|
var year = $webformDatepicker.find('select.year, input.year').val();
|
67 |
|
|
var month = $webformDatepicker.find('select.month').val();
|
68 |
|
|
var day = $webformDatepicker.find('select.day').val();
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
var today = new Date();
|
72 |
|
|
year = year ? year : today.getFullYear();
|
73 |
|
|
month = month ? month : today.getMonth() + 1;
|
74 |
|
|
day = day ? day : today.getDate();
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
year = (year < startYear || year > endYear) ? startYear : year;
|
78 |
85ad3d82
|
Assos Assos
|
|
79 |
01f36513
|
Assos Assos
|
|
80 |
|
|
|
81 |
a45e4bc1
|
Assos Assos
|
$(input).val(year + '-' + month + '-' + day);
|
82 |
|
|
}
|
83 |
|
|
});
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
$calendar.click(function (event) {
|
87 |
389fb945
|
Assos Assos
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
if (event.clientX !== 0 && event.clientY !== 0) {
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
$(this).focus();
|
97 |
|
|
event.preventDefault();
|
98 |
|
|
}
|
99 |
|
|
});
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
$calendar.keyup(function (e) {
|
103 |
|
|
if (e.keyCode == 8 || e.keyCode == 46) {
|
104 |
|
|
$.datepicker._clearDate(this);
|
105 |
|
|
}
|
106 |
a45e4bc1
|
Assos Assos
|
});
|
107 |
|
|
});
|
108 |
|
|
};
|
109 |
|
|
|
110 |
|
|
Drupal.webform.conditional = function (context) {
|
111 |
|
|
|
112 |
|
|
$.each(Drupal.settings.webform.conditionals, function (formKey, settings) {
|
113 |
|
|
var $form = $('.' + formKey + ':not(.webform-conditional-processed)');
|
114 |
|
|
$form.each(function (index, currentForm) {
|
115 |
|
|
var $currentForm = $(currentForm);
|
116 |
|
|
$currentForm.addClass('webform-conditional-processed');
|
117 |
|
|
$currentForm.bind('change', {'settings': settings}, Drupal.webform.conditionalCheck);
|
118 |
|
|
|
119 |
|
|
|
120 |
8c72e82a
|
Assos Assos
|
Drupal.webform.doConditions($currentForm, settings);
|
121 |
a45e4bc1
|
Assos Assos
|
});
|
122 |
|
|
});
|
123 |
|
|
};
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
Drupal.webform.conditionalCheck = function (e) {
|
131 |
|
|
var $triggerElement = $(e.target).closest('.webform-component');
|
132 |
389fb945
|
Assos Assos
|
if (!$triggerElement.length) {
|
133 |
|
|
return;
|
134 |
|
|
}
|
135 |
a45e4bc1
|
Assos Assos
|
var $form = $triggerElement.closest('form');
|
136 |
|
|
var triggerElementKey = $triggerElement.attr('class').match(/webform-component--[^ ]+/)[0];
|
137 |
|
|
var settings = e.data.settings;
|
138 |
|
|
if (settings.sourceMap[triggerElementKey]) {
|
139 |
|
|
Drupal.webform.doConditions($form, settings);
|
140 |
85ad3d82
|
Assos Assos
|
}
|
141 |
a45e4bc1
|
Assos Assos
|
};
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
Drupal.webform.doConditions = function ($form, settings) {
|
147 |
e9984459
|
Assos Assos
|
|
148 |
|
|
var stackPointer;
|
149 |
|
|
var resultStack;
|
150 |
|
|
|
151 |
|
|
|
152 |
01f36513
|
Assos Assos
|
|
153 |
|
|
|
154 |
|
|
|
155 |
e9984459
|
Assos Assos
|
|
156 |
|
|
function executionStackInitialize(andor) {
|
157 |
|
|
stackPointer = -1;
|
158 |
|
|
resultStack = [];
|
159 |
|
|
executionStackPush(andor);
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
function executionStackPush(andor) {
|
166 |
|
|
resultStack[++stackPointer] = {
|
167 |
|
|
results: [],
|
168 |
|
|
andor: andor,
|
169 |
|
|
};
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
|
173 |
feca1e4a
|
Assos Assos
|
|
174 |
e9984459
|
Assos Assos
|
|
175 |
|
|
function executionStackAccumulate(result) {
|
176 |
|
|
resultStack[stackPointer]['results'].push(result);
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
function executionStackPop() {
|
183 |
|
|
|
184 |
|
|
var stackFrame = resultStack[stackPointer];
|
185 |
|
|
|
186 |
|
|
stackPointer = Math.max(0, stackPointer - 1);
|
187 |
|
|
var $conditionalResults = stackFrame['results'];
|
188 |
feca1e4a
|
Assos Assos
|
var filteredResults = $.map($conditionalResults, function (val) {
|
189 |
e9984459
|
Assos Assos
|
return val ? val : null;
|
190 |
|
|
});
|
191 |
|
|
return stackFrame['andor'] === 'or'
|
192 |
|
|
? filteredResults.length > 0
|
193 |
|
|
: filteredResults.length === $conditionalResults.length;
|
194 |
|
|
}
|
195 |
|
|
|
196 |
01f36513
|
Assos Assos
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
a45e4bc1
|
Assos Assos
|
$.each(settings.ruleGroups, function (rgid_key, rule_group) {
|
206 |
|
|
var ruleGroup = settings.ruleGroups[rgid_key];
|
207 |
|
|
|
208 |
|
|
|
209 |
e9984459
|
Assos Assos
|
executionStackInitialize(ruleGroup['andor']);
|
210 |
a45e4bc1
|
Assos Assos
|
$.each(ruleGroup['rules'], function (m, rule) {
|
211 |
e9984459
|
Assos Assos
|
switch (rule['source_type']) {
|
212 |
|
|
case 'component':
|
213 |
|
|
var elementKey = rule['source'];
|
214 |
|
|
var element = $form.find('.' + elementKey)[0];
|
215 |
|
|
var existingValue = settings.values[elementKey] ? settings.values[elementKey] : null;
|
216 |
|
|
executionStackAccumulate(window['Drupal']['webform'][rule.callback](element, existingValue, rule['value']));
|
217 |
|
|
break;
|
218 |
feca1e4a
|
Assos Assos
|
|
219 |
e9984459
|
Assos Assos
|
case 'conditional_start':
|
220 |
|
|
executionStackPush(rule['andor']);
|
221 |
|
|
break;
|
222 |
feca1e4a
|
Assos Assos
|
|
223 |
e9984459
|
Assos Assos
|
case 'conditional_end':
|
224 |
|
|
executionStackAccumulate(executionStackPop());
|
225 |
|
|
break;
|
226 |
a45e4bc1
|
Assos Assos
|
}
|
227 |
e9984459
|
Assos Assos
|
});
|
228 |
|
|
var conditionalResult = executionStackPop();
|
229 |
a45e4bc1
|
Assos Assos
|
|
230 |
|
|
$.each(ruleGroup['actions'], function (aid, action) {
|
231 |
|
|
var $target = $form.find('.' + action['target']);
|
232 |
|
|
var actionResult = action['invert'] ? !conditionalResult : conditionalResult;
|
233 |
|
|
switch (action['action']) {
|
234 |
|
|
case 'show':
|
235 |
01f36513
|
Assos Assos
|
var changed = actionResult != Drupal.webform.isVisible($target);
|
236 |
|
|
if (actionResult) {
|
237 |
|
|
$target.find('.webform-conditional-disabled:not(.webform-disabled-flag)')
|
238 |
|
|
.removeClass('webform-conditional-disabled')
|
239 |
|
|
.webformProp('disabled', false);
|
240 |
|
|
$target
|
241 |
|
|
.removeClass('webform-conditional-hidden')
|
242 |
|
|
.show();
|
243 |
|
|
$form.find('.chosen-disabled').prev().trigger('chosen:updated.chosen');
|
244 |
|
|
}
|
245 |
|
|
else {
|
246 |
|
|
$target
|
247 |
|
|
.hide()
|
248 |
|
|
.addClass('webform-conditional-hidden')
|
249 |
|
|
.find(':input')
|
250 |
|
|
.addClass('webform-conditional-disabled webform-disabled-flag')
|
251 |
|
|
.webformProp('disabled', true);
|
252 |
|
|
}
|
253 |
|
|
if (changed && $target.is('tr')) {
|
254 |
|
|
Drupal.webform.restripeTable($target.closest('table').first());
|
255 |
a45e4bc1
|
Assos Assos
|
}
|
256 |
|
|
break;
|
257 |
feca1e4a
|
Assos Assos
|
|
258 |
a45e4bc1
|
Assos Assos
|
case 'require':
|
259 |
|
|
var $requiredSpan = $target.find('.form-required, .form-optional').first();
|
260 |
|
|
if (actionResult != $requiredSpan.hasClass('form-required')) {
|
261 |
389fb945
|
Assos Assos
|
var $targetInputElements = $target.find("input:text,textarea,input[type='email'],select,input:radio,input:checkbox,input:file");
|
262 |
01f36513
|
Assos Assos
|
|
263 |
|
|
|
264 |
a45e4bc1
|
Assos Assos
|
Drupal.detachBehaviors($requiredSpan);
|
265 |
|
|
$targetInputElements
|
266 |
|
|
.webformProp('required', actionResult)
|
267 |
|
|
.toggleClass('required', actionResult);
|
268 |
|
|
if (actionResult) {
|
269 |
|
|
$requiredSpan.replaceWith('<span class="form-required" title="' + Drupal.t('This field is required.') + '">*</span>');
|
270 |
|
|
}
|
271 |
|
|
else {
|
272 |
|
|
$requiredSpan.replaceWith('<span class="form-optional"></span>');
|
273 |
|
|
}
|
274 |
|
|
Drupal.attachBehaviors($requiredSpan);
|
275 |
|
|
}
|
276 |
|
|
break;
|
277 |
feca1e4a
|
Assos Assos
|
|
278 |
a45e4bc1
|
Assos Assos
|
case 'set':
|
279 |
|
|
var $texts = $target.find("input:text,textarea,input[type='email']");
|
280 |
|
|
var $selects = $target.find('select,select option,input:radio,input:checkbox');
|
281 |
|
|
var $markups = $target.filter('.webform-component-markup');
|
282 |
|
|
if (actionResult) {
|
283 |
|
|
var multiple = $.map(action['argument'].split(','), $.trim);
|
284 |
01f36513
|
Assos Assos
|
$selects
|
285 |
|
|
.webformVal(multiple)
|
286 |
|
|
.webformProp('disabled', true)
|
287 |
|
|
.addClass('webform-disabled-flag');
|
288 |
|
|
$texts
|
289 |
|
|
.val([action['argument']])
|
290 |
|
|
.webformProp('readonly', true)
|
291 |
|
|
.addClass('webform-disabled-flag');
|
292 |
|
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
|
296 |
a45e4bc1
|
Assos Assos
|
$markups.html(action['argument']);
|
297 |
|
|
}
|
298 |
|
|
else {
|
299 |
01f36513
|
Assos Assos
|
$selects.not('.webform-disabled-flag')
|
300 |
|
|
.webformProp('disabled', false);
|
301 |
|
|
$texts.not('.webform-disabled-flag')
|
302 |
|
|
.webformProp('readonly', false);
|
303 |
a45e4bc1
|
Assos Assos
|
|
304 |
|
|
|
305 |
feca1e4a
|
Assos Assos
|
$markups.each(function () {
|
306 |
a45e4bc1
|
Assos Assos
|
var $this = $(this);
|
307 |
|
|
var original = $this.data('webform-markup');
|
308 |
|
|
if (original !== undefined) {
|
309 |
|
|
$this.html(original);
|
310 |
|
|
}
|
311 |
|
|
});
|
312 |
|
|
}
|
313 |
|
|
break;
|
314 |
|
|
}
|
315 |
01f36513
|
Assos Assos
|
});
|
316 |
feca1e4a
|
Assos Assos
|
});
|
317 |
01f36513
|
Assos Assos
|
|
318 |
|
|
$form.find('.webform-disabled-flag').removeClass('webform-disabled-flag');
|
319 |
a45e4bc1
|
Assos Assos
|
};
|
320 |
|
|
|
321 |
|
|
|
322 |
01f36513
|
Assos Assos
|
|
323 |
|
|
|
324 |
|
|
|
325 |
a45e4bc1
|
Assos Assos
|
|
326 |
|
|
Drupal.webform.stopEvent = function () {
|
327 |
|
|
return false;
|
328 |
|
|
};
|
329 |
|
|
|
330 |
|
|
Drupal.webform.conditionalOperatorStringEqual = function (element, existingValue, ruleValue) {
|
331 |
|
|
var returnValue = false;
|
332 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
333 |
|
|
$.each(currentValue, function (n, value) {
|
334 |
|
|
if (value.toLowerCase() === ruleValue.toLowerCase()) {
|
335 |
|
|
returnValue = true;
|
336 |
|
|
return false;
|
337 |
|
|
}
|
338 |
|
|
});
|
339 |
|
|
return returnValue;
|
340 |
|
|
};
|
341 |
|
|
|
342 |
|
|
Drupal.webform.conditionalOperatorStringNotEqual = function (element, existingValue, ruleValue) {
|
343 |
|
|
var found = false;
|
344 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
345 |
|
|
$.each(currentValue, function (n, value) {
|
346 |
|
|
if (value.toLowerCase() === ruleValue.toLowerCase()) {
|
347 |
|
|
found = true;
|
348 |
|
|
}
|
349 |
|
|
});
|
350 |
|
|
return !found;
|
351 |
|
|
};
|
352 |
|
|
|
353 |
|
|
Drupal.webform.conditionalOperatorStringContains = function (element, existingValue, ruleValue) {
|
354 |
|
|
var returnValue = false;
|
355 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
356 |
|
|
$.each(currentValue, function (n, value) {
|
357 |
|
|
if (value.toLowerCase().indexOf(ruleValue.toLowerCase()) > -1) {
|
358 |
|
|
returnValue = true;
|
359 |
|
|
return false;
|
360 |
|
|
}
|
361 |
|
|
});
|
362 |
|
|
return returnValue;
|
363 |
|
|
};
|
364 |
85ad3d82
|
Assos Assos
|
|
365 |
a45e4bc1
|
Assos Assos
|
Drupal.webform.conditionalOperatorStringDoesNotContain = function (element, existingValue, ruleValue) {
|
366 |
|
|
var found = false;
|
367 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
368 |
|
|
$.each(currentValue, function (n, value) {
|
369 |
|
|
if (value.toLowerCase().indexOf(ruleValue.toLowerCase()) > -1) {
|
370 |
|
|
found = true;
|
371 |
85ad3d82
|
Assos Assos
|
}
|
372 |
|
|
});
|
373 |
a45e4bc1
|
Assos Assos
|
return !found;
|
374 |
|
|
};
|
375 |
|
|
|
376 |
|
|
Drupal.webform.conditionalOperatorStringBeginsWith = function (element, existingValue, ruleValue) {
|
377 |
|
|
var returnValue = false;
|
378 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
379 |
|
|
$.each(currentValue, function (n, value) {
|
380 |
|
|
if (value.toLowerCase().indexOf(ruleValue.toLowerCase()) === 0) {
|
381 |
|
|
returnValue = true;
|
382 |
|
|
return false;
|
383 |
|
|
}
|
384 |
|
|
});
|
385 |
|
|
return returnValue;
|
386 |
|
|
};
|
387 |
|
|
|
388 |
|
|
Drupal.webform.conditionalOperatorStringEndsWith = function (element, existingValue, ruleValue) {
|
389 |
|
|
var returnValue = false;
|
390 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
391 |
|
|
$.each(currentValue, function (n, value) {
|
392 |
|
|
if (value.toLowerCase().lastIndexOf(ruleValue.toLowerCase()) === value.length - ruleValue.length) {
|
393 |
|
|
returnValue = true;
|
394 |
|
|
return false;
|
395 |
|
|
}
|
396 |
|
|
});
|
397 |
|
|
return returnValue;
|
398 |
|
|
};
|
399 |
|
|
|
400 |
|
|
Drupal.webform.conditionalOperatorStringEmpty = function (element, existingValue, ruleValue) {
|
401 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
402 |
|
|
var returnValue = true;
|
403 |
|
|
$.each(currentValue, function (n, value) {
|
404 |
|
|
if (value !== '') {
|
405 |
|
|
returnValue = false;
|
406 |
|
|
return false;
|
407 |
|
|
}
|
408 |
|
|
});
|
409 |
|
|
return returnValue;
|
410 |
|
|
};
|
411 |
|
|
|
412 |
|
|
Drupal.webform.conditionalOperatorStringNotEmpty = function (element, existingValue, ruleValue) {
|
413 |
|
|
return !Drupal.webform.conditionalOperatorStringEmpty(element, existingValue, ruleValue);
|
414 |
|
|
};
|
415 |
|
|
|
416 |
|
|
Drupal.webform.conditionalOperatorSelectGreaterThan = function (element, existingValue, ruleValue) {
|
417 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
418 |
|
|
return Drupal.webform.compare_select(currentValue[0], ruleValue, element) > 0;
|
419 |
|
|
};
|
420 |
|
|
|
421 |
|
|
Drupal.webform.conditionalOperatorSelectGreaterThanEqual = function (element, existingValue, ruleValue) {
|
422 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
423 |
|
|
var comparison = Drupal.webform.compare_select(currentValue[0], ruleValue, element);
|
424 |
|
|
return comparison > 0 || comparison === 0;
|
425 |
|
|
};
|
426 |
85ad3d82
|
Assos Assos
|
|
427 |
a45e4bc1
|
Assos Assos
|
Drupal.webform.conditionalOperatorSelectLessThan = function (element, existingValue, ruleValue) {
|
428 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
429 |
|
|
return Drupal.webform.compare_select(currentValue[0], ruleValue, element) < 0;
|
430 |
|
|
};
|
431 |
|
|
|
432 |
|
|
Drupal.webform.conditionalOperatorSelectLessThanEqual = function (element, existingValue, ruleValue) {
|
433 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
434 |
|
|
var comparison = Drupal.webform.compare_select(currentValue[0], ruleValue, element);
|
435 |
|
|
return comparison < 0 || comparison === 0;
|
436 |
|
|
};
|
437 |
|
|
|
438 |
|
|
Drupal.webform.conditionalOperatorNumericEqual = function (element, existingValue, ruleValue) {
|
439 |
|
|
|
440 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
441 |
|
|
var epsilon = 0.000001;
|
442 |
|
|
|
443 |
|
|
return currentValue[0] === '' ? false : (Math.abs(parseFloat(currentValue[0]) - parseFloat(ruleValue)) < epsilon);
|
444 |
|
|
};
|
445 |
|
|
|
446 |
|
|
Drupal.webform.conditionalOperatorNumericNotEqual = function (element, existingValue, ruleValue) {
|
447 |
|
|
|
448 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
449 |
|
|
var epsilon = 0.000001;
|
450 |
|
|
|
451 |
|
|
return currentValue[0] === '' ? true : (Math.abs(parseFloat(currentValue[0]) - parseFloat(ruleValue)) >= epsilon);
|
452 |
|
|
};
|
453 |
|
|
|
454 |
|
|
Drupal.webform.conditionalOperatorNumericGreaterThan = function (element, existingValue, ruleValue) {
|
455 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
456 |
|
|
return parseFloat(currentValue[0]) > parseFloat(ruleValue);
|
457 |
|
|
};
|
458 |
|
|
|
459 |
|
|
Drupal.webform.conditionalOperatorNumericGreaterThanEqual = function (element, existingValue, ruleValue) {
|
460 |
|
|
return Drupal.webform.conditionalOperatorNumericGreaterThan(element, existingValue, ruleValue) ||
|
461 |
|
|
Drupal.webform.conditionalOperatorNumericEqual(element, existingValue, ruleValue);
|
462 |
|
|
};
|
463 |
|
|
|
464 |
|
|
Drupal.webform.conditionalOperatorNumericLessThan = function (element, existingValue, ruleValue) {
|
465 |
|
|
var currentValue = Drupal.webform.stringValue(element, existingValue);
|
466 |
|
|
return parseFloat(currentValue[0]) < parseFloat(ruleValue);
|
467 |
|
|
};
|
468 |
|
|
|
469 |
|
|
Drupal.webform.conditionalOperatorNumericLessThanEqual = function (element, existingValue, ruleValue) {
|
470 |
|
|
return Drupal.webform.conditionalOperatorNumericLessThan(element, existingValue, ruleValue) ||
|
471 |
|
|
Drupal.webform.conditionalOperatorNumericEqual(element, existingValue, ruleValue);
|
472 |
|
|
};
|
473 |
|
|
|
474 |
|
|
Drupal.webform.conditionalOperatorDateEqual = function (element, existingValue, ruleValue) {
|
475 |
|
|
var currentValue = Drupal.webform.dateValue(element, existingValue);
|
476 |
|
|
return currentValue === ruleValue;
|
477 |
|
|
};
|
478 |
|
|
|
479 |
|
|
Drupal.webform.conditionalOperatorDateNotEqual = function (element, existingValue, ruleValue) {
|
480 |
|
|
return !Drupal.webform.conditionalOperatorDateEqual(element, existingValue, ruleValue);
|
481 |
|
|
};
|
482 |
|
|
|
483 |
|
|
Drupal.webform.conditionalOperatorDateBefore = function (element, existingValue, ruleValue) {
|
484 |
|
|
var currentValue = Drupal.webform.dateValue(element, existingValue);
|
485 |
|
|
return (currentValue !== false) && currentValue < ruleValue;
|
486 |
|
|
};
|
487 |
|
|
|
488 |
|
|
Drupal.webform.conditionalOperatorDateBeforeEqual = function (element, existingValue, ruleValue) {
|
489 |
|
|
var currentValue = Drupal.webform.dateValue(element, existingValue);
|
490 |
|
|
return (currentValue !== false) && (currentValue < ruleValue || currentValue === ruleValue);
|
491 |
|
|
};
|
492 |
|
|
|
493 |
|
|
Drupal.webform.conditionalOperatorDateAfter = function (element, existingValue, ruleValue) {
|
494 |
|
|
var currentValue = Drupal.webform.dateValue(element, existingValue);
|
495 |
|
|
return (currentValue !== false) && currentValue > ruleValue;
|
496 |
|
|
};
|
497 |
|
|
|
498 |
|
|
Drupal.webform.conditionalOperatorDateAfterEqual = function (element, existingValue, ruleValue) {
|
499 |
|
|
var currentValue = Drupal.webform.dateValue(element, existingValue);
|
500 |
|
|
return (currentValue !== false) && (currentValue > ruleValue || currentValue === ruleValue);
|
501 |
|
|
};
|
502 |
|
|
|
503 |
|
|
Drupal.webform.conditionalOperatorTimeEqual = function (element, existingValue, ruleValue) {
|
504 |
|
|
var currentValue = Drupal.webform.timeValue(element, existingValue);
|
505 |
|
|
return currentValue === ruleValue;
|
506 |
|
|
};
|
507 |
|
|
|
508 |
|
|
Drupal.webform.conditionalOperatorTimeNotEqual = function (element, existingValue, ruleValue) {
|
509 |
|
|
return !Drupal.webform.conditionalOperatorTimeEqual(element, existingValue, ruleValue);
|
510 |
|
|
};
|
511 |
|
|
|
512 |
|
|
Drupal.webform.conditionalOperatorTimeBefore = function (element, existingValue, ruleValue) {
|
513 |
|
|
|
514 |
|
|
var currentValue = Drupal.webform.timeValue(element, existingValue);
|
515 |
|
|
return (currentValue !== false) && (currentValue < ruleValue);
|
516 |
|
|
};
|
517 |
|
|
|
518 |
|
|
Drupal.webform.conditionalOperatorTimeBeforeEqual = function (element, existingValue, ruleValue) {
|
519 |
|
|
|
520 |
|
|
var currentValue = Drupal.webform.timeValue(element, existingValue);
|
521 |
|
|
return (currentValue !== false) && (currentValue < ruleValue || currentValue === ruleValue);
|
522 |
|
|
};
|
523 |
|
|
|
524 |
|
|
Drupal.webform.conditionalOperatorTimeAfter = function (element, existingValue, ruleValue) {
|
525 |
|
|
|
526 |
|
|
var currentValue = Drupal.webform.timeValue(element, existingValue);
|
527 |
|
|
return (currentValue !== false) && (currentValue > ruleValue);
|
528 |
|
|
};
|
529 |
|
|
|
530 |
|
|
Drupal.webform.conditionalOperatorTimeAfterEqual = function (element, existingValue, ruleValue) {
|
531 |
|
|
|
532 |
|
|
var currentValue = Drupal.webform.timeValue(element, existingValue);
|
533 |
|
|
return (currentValue !== false) && (currentValue > ruleValue || currentValue === ruleValue);
|
534 |
|
|
};
|
535 |
|
|
|
536 |
|
|
|
537 |
|
|
|
538 |
feca1e4a
|
Assos Assos
|
|
539 |
a45e4bc1
|
Assos Assos
|
|
540 |
|
|
|
541 |
|
|
|
542 |
|
|
|
543 |
|
|
|
544 |
|
|
|
545 |
feca1e4a
|
Assos Assos
|
|
546 |
a45e4bc1
|
Assos Assos
|
|
547 |
|
|
|
548 |
|
|
|
549 |
|
|
|
550 |
|
|
|
551 |
|
|
Drupal.webform.compare_select = function (a, b, element) {
|
552 |
|
|
var optionList = [];
|
553 |
|
|
$('option,input:radio,input:checkbox', element).each(function () {
|
554 |
|
|
optionList.push($(this).val());
|
555 |
|
|
});
|
556 |
|
|
var a_position = optionList.indexOf(a);
|
557 |
|
|
var b_position = optionList.indexOf(b);
|
558 |
|
|
return (a_position < 0 || b_position < 0) ? null : a_position - b_position;
|
559 |
|
|
};
|
560 |
|
|
|
561 |
|
|
|
562 |
01f36513
|
Assos Assos
|
|
563 |
|
|
|
564 |
|
|
|
565 |
|
|
|
566 |
a45e4bc1
|
Assos Assos
|
|
567 |
|
|
Drupal.webform.isVisible = function ($element) {
|
568 |
|
|
return $element.hasClass('webform-component-hidden')
|
569 |
|
|
? !$element.find('input').first().hasClass('webform-conditional-disabled')
|
570 |
|
|
: $element.closest('.webform-conditional-hidden').length == 0;
|
571 |
|
|
};
|
572 |
|
|
|
573 |
|
|
|
574 |
01f36513
|
Assos Assos
|
|
575 |
a45e4bc1
|
Assos Assos
|
|
576 |
|
|
Drupal.webform.stringValue = function (element, existingValue) {
|
577 |
|
|
var value = [];
|
578 |
|
|
if (element) {
|
579 |
|
|
var $element = $(element);
|
580 |
|
|
if (Drupal.webform.isVisible($element)) {
|
581 |
|
|
|
582 |
|
|
$element.find('input[type=checkbox]:checked,input[type=radio]:checked').each(function () {
|
583 |
|
|
value.push(this.value);
|
584 |
|
|
});
|
585 |
|
|
|
586 |
|
|
if (!value.length) {
|
587 |
|
|
var selectValue = $element.find('select').val();
|
588 |
|
|
if (selectValue) {
|
589 |
|
|
if ($.isArray(selectValue)) {
|
590 |
|
|
value = selectValue;
|
591 |
|
|
}
|
592 |
|
|
else {
|
593 |
|
|
value.push(selectValue);
|
594 |
|
|
}
|
595 |
|
|
}
|
596 |
|
|
}
|
597 |
01f36513
|
Assos Assos
|
|
598 |
|
|
|
599 |
a45e4bc1
|
Assos Assos
|
if (!value.length) {
|
600 |
|
|
$element.find('input:not([type=checkbox],[type=radio]),textarea').each(function () {
|
601 |
|
|
value.push(this.value);
|
602 |
|
|
});
|
603 |
|
|
}
|
604 |
|
|
}
|
605 |
|
|
}
|
606 |
|
|
else {
|
607 |
|
|
switch ($.type(existingValue)) {
|
608 |
|
|
case 'array':
|
609 |
|
|
value = existingValue;
|
610 |
|
|
break;
|
611 |
feca1e4a
|
Assos Assos
|
|
612 |
a45e4bc1
|
Assos Assos
|
case 'string':
|
613 |
|
|
value.push(existingValue);
|
614 |
|
|
break;
|
615 |
|
|
}
|
616 |
|
|
}
|
617 |
|
|
return value;
|
618 |
|
|
};
|
619 |
|
|
|
620 |
|
|
|
621 |
01d522a6
|
Assos Assos
|
|
622 |
a45e4bc1
|
Assos Assos
|
|
623 |
|
|
Drupal.webform.dateValue = function (element, existingValue) {
|
624 |
|
|
var value = false;
|
625 |
|
|
if (element) {
|
626 |
|
|
var $element = $(element);
|
627 |
|
|
if (Drupal.webform.isVisible($element)) {
|
628 |
|
|
var day = $element.find('[name*=day]').val();
|
629 |
|
|
var month = $element.find('[name*=month]').val();
|
630 |
|
|
var year = $element.find('[name*=year]').val();
|
631 |
|
|
|
632 |
|
|
if (month) {
|
633 |
|
|
month--;
|
634 |
|
|
}
|
635 |
|
|
if (year !== '' && month !== '' && day !== '') {
|
636 |
|
|
value = Date.UTC(year, month, day) / 1000;
|
637 |
|
|
}
|
638 |
|
|
}
|
639 |
|
|
}
|
640 |
|
|
else {
|
641 |
|
|
if ($.type(existingValue) === 'array' && existingValue.length) {
|
642 |
|
|
existingValue = existingValue[0];
|
643 |
|
|
}
|
644 |
|
|
if ($.type(existingValue) === 'string') {
|
645 |
|
|
existingValue = existingValue.split('-');
|
646 |
|
|
}
|
647 |
|
|
if (existingValue.length === 3) {
|
648 |
|
|
value = Date.UTC(existingValue[0], existingValue[1], existingValue[2]) / 1000;
|
649 |
|
|
}
|
650 |
|
|
}
|
651 |
|
|
return value;
|
652 |
|
|
};
|
653 |
|
|
|
654 |
|
|
|
655 |
|
|
|
656 |
|
|
|
657 |
|
|
Drupal.webform.timeValue = function (element, existingValue) {
|
658 |
|
|
var value = false;
|
659 |
|
|
if (element) {
|
660 |
|
|
var $element = $(element);
|
661 |
|
|
if (Drupal.webform.isVisible($element)) {
|
662 |
|
|
var hour = $element.find('[name*=hour]').val();
|
663 |
|
|
var minute = $element.find('[name*=minute]').val();
|
664 |
|
|
var ampm = $element.find('[name*=ampm]:checked').val();
|
665 |
|
|
|
666 |
|
|
|
667 |
|
|
hour = (hour === '') ? hour : parseInt(hour);
|
668 |
|
|
minute = (minute === '') ? minute : parseInt(minute);
|
669 |
|
|
|
670 |
|
|
if (hour !== '') {
|
671 |
|
|
hour = (hour < 12 && ampm == 'pm') ? hour + 12 : hour;
|
672 |
|
|
hour = (hour === 12 && ampm == 'am') ? 0 : hour;
|
673 |
|
|
}
|
674 |
|
|
if (hour !== '' && minute !== '') {
|
675 |
|
|
value = Date.UTC(1970, 0, 1, hour, minute) / 1000;
|
676 |
|
|
}
|
677 |
|
|
}
|
678 |
|
|
}
|
679 |
|
|
else {
|
680 |
|
|
if ($.type(existingValue) === 'array' && existingValue.length) {
|
681 |
|
|
existingValue = existingValue[0];
|
682 |
|
|
}
|
683 |
|
|
if ($.type(existingValue) === 'string') {
|
684 |
|
|
existingValue = existingValue.split(':');
|
685 |
|
|
}
|
686 |
|
|
if (existingValue.length >= 2) {
|
687 |
|
|
value = Date.UTC(1970, 0, 1, existingValue[0], existingValue[1]) / 1000;
|
688 |
|
|
}
|
689 |
|
|
}
|
690 |
|
|
return value;
|
691 |
|
|
};
|
692 |
|
|
|
693 |
|
|
|
694 |
|
|
|
695 |
|
|
|
696 |
|
|
$.fn.webformProp = $.fn.webformProp || function (name, value) {
|
697 |
|
|
if (value) {
|
698 |
|
|
return $.fn.prop ? this.prop(name, true) : this.attr(name, true);
|
699 |
|
|
}
|
700 |
|
|
else {
|
701 |
|
|
return $.fn.prop ? this.prop(name, false) : this.removeAttr(name);
|
702 |
|
|
}
|
703 |
|
|
};
|
704 |
|
|
|
705 |
|
|
|
706 |
01f36513
|
Assos Assos
|
|
707 |
|
|
|
708 |
|
|
|
709 |
a45e4bc1
|
Assos Assos
|
|
710 |
|
|
$.fn.webformVal = function (values) {
|
711 |
|
|
this.each(function () {
|
712 |
|
|
var $this = $(this);
|
713 |
|
|
var value = $this.val();
|
714 |
|
|
var on = $.inArray($this.val(), values) != -1;
|
715 |
|
|
if (this.nodeName == 'OPTION') {
|
716 |
|
|
$this.webformProp('selected', on ? value : false);
|
717 |
|
|
}
|
718 |
|
|
else {
|
719 |
|
|
$this.val(on ? [value] : false);
|
720 |
|
|
}
|
721 |
85ad3d82
|
Assos Assos
|
});
|
722 |
a45e4bc1
|
Assos Assos
|
return this;
|
723 |
|
|
};
|
724 |
85ad3d82
|
Assos Assos
|
|
725 |
ba09eb79
|
Assos Assos
|
|
726 |
|
|
|
727 |
|
|
|
728 |
|
|
Drupal.webform.restripeTable = function (table) {
|
729 |
|
|
|
730 |
|
|
|
731 |
|
|
|
732 |
|
|
$('> tbody > tr, > tr', table)
|
733 |
|
|
.filter(':visible:odd').filter('.odd')
|
734 |
|
|
.removeClass('odd').addClass('even')
|
735 |
|
|
.end().end()
|
736 |
|
|
.filter(':visible:even').filter('.even')
|
737 |
|
|
.removeClass('even').addClass('odd');
|
738 |
|
|
};
|
739 |
|
|
|
740 |
85ad3d82
|
Assos Assos
|
})(jQuery); |