Skip to content
Snippets Groups Projects
Commit a96e817b authored by Martin Anderson-Clutz's avatar Martin Anderson-Clutz
Browse files

Fixed validation and code standards issues.

parent f47afb4a
No related branches found
Tags 7.x-1.3 7x-1.3
No related merge requests found
......@@ -6,10 +6,13 @@
once('smartDateDuration', '.smartdate--widget select.field-duration', context).forEach(function (element) {
setInitialDuration(element);
augmentInputs(element);
element.addEventListener("change", function () {
durationChanged(element);
}, false);
});
once('smartDateAllDay', '.allday', context).forEach(function (element) {
setAllDay(element);
element.addEventListener("change", function (event) {
element.addEventListener("change", function () {
checkAllDay(element);
}, false);
});
......@@ -17,20 +20,15 @@
element.step = 60;
});
once('smartDateStartChange', '.smartdate--widget .time-start input', context).forEach(function (element) {
element.addEventListener("change", function (event) {
element.addEventListener("change", function () {
setEndDate(element);
}, false);
});
once('smartDateEndChange', '.smartdate--widget .time-end', context).forEach(function (element) {
element.addEventListener("change", function (event) {
element.addEventListener("change", function () {
setDuration(element);
}, false);
});
once('smartDateDurationChange', '.smartdate--widget select.field-duration', context).forEach(function (element) {
element.addEventListener("change", function (event) {
durationChanged(element);
}, false);
});
function setEndDate(element) {
let wrapper = element.closest('.smartdate--widget');
......@@ -52,7 +50,7 @@
if (!start_time && start_date) {
// If only the start date has been specified update only the end date.
wrapper.querySelector('.time-end.form-date').value = start_date;
return
return;
}
let start_array = start_time.split(':');
......@@ -129,32 +127,32 @@
duration = calcDuration(wrapper);
}
else if (duration == 0) {
// call this to hide the end date and time
// Call this to hide the end date and time.
durationChanged(element);
}
// Store the numeric value in a property so it can be used programmatically
// Store the numeric value in a property so it can be used programmatically.
element.dataset.duration = duration;
}
// Add/change inputs based on initial config
// Add/change inputs based on initial config.
function augmentInputs(element) {
// Add "All day checkbox" if config permits
// Add "All day checkbox" if config permits.
if (element.querySelectorAll('select [value="custom"]').length > 0 || element.querySelectorAll('select [value="1439"]').length > 0) {
// Create the input element
// Create the input element.
let checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.classList.add('allday');
// Create the label element
let label = document.createElement('label')
// Create the label element.
let label = document.createElement('label');
label.classList.add('allday-label');
// Insert the input into the label
// Insert the input into the label.
label.appendChild(checkbox);
label.appendChild(document.createTextNode(Drupal.t('All day')));
element.parentElement.insertAdjacentElement('beforebegin', label);
}
// if a forced duration, make end date and time read only
// If a forced duration, make end date and time read only.
if (element.querySelectorAll('select [value="custom"]').length == 0) {
let wrapper = element.closest('fieldset');
let end_time_input = wrapper.querySelector('.time-end.form-time');
......@@ -174,9 +172,9 @@
return;
}
let duration_select = wrapper.querySelector('select.field-duration');
// Store the numeric value in a property so it can be used programmatically
// Store the numeric value in a property so it can be used programmatically.
duration_select.dataset.duration = duration;
// Update the select to show the appropriate value
// Update the select to show the appropriate value.
if (duration_select.querySelectorAll('option[value="' + duration + '"]').length != 0){
duration_select.value = duration;
} else {
......@@ -298,7 +296,7 @@
duration_wrapper.style.visibility = 'visible';
hideLabels(wrapper, false);
if (duration.value == 0) {
// call this to hide the end date and time
// Call this to hide the end date and time.
durationChanged(duration);
}
checkEndDate(wrapper);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment