2016-12-27 17:24:28 +00:00
|
|
|
(() => {
|
2016-08-18 13:12:48 +00:00
|
|
|
// Add datepickers to all `js-access-expiration-date` elements. If those elements are
|
|
|
|
// children of an element with the `clearable-input` class, and have a sibling
|
|
|
|
// `js-clear-input` element, then show that element when there is a value in the
|
|
|
|
// datepicker, and make clicking on that element clear the field.
|
|
|
|
//
|
2017-01-03 18:55:36 +00:00
|
|
|
window.gl = window.gl || {};
|
2016-12-27 17:24:28 +00:00
|
|
|
gl.MemberExpirationDate = (selector = '.js-access-expiration-date') => {
|
2016-08-19 00:41:18 +00:00
|
|
|
function toggleClearInput() {
|
|
|
|
$(this).closest('.clearable-input').toggleClass('has-value', $(this).val() !== '');
|
|
|
|
}
|
2017-01-03 18:55:36 +00:00
|
|
|
const inputs = $(selector);
|
2016-08-18 13:12:48 +00:00
|
|
|
|
2016-08-19 00:41:18 +00:00
|
|
|
inputs.datepicker({
|
|
|
|
dateFormat: 'yy-mm-dd',
|
|
|
|
minDate: 1,
|
2017-01-04 19:51:40 +00:00
|
|
|
onSelect: function onSelect() {
|
2016-09-01 10:56:21 +00:00
|
|
|
$(this).trigger('change');
|
|
|
|
toggleClearInput.call(this);
|
2017-01-03 18:55:36 +00:00
|
|
|
},
|
2016-08-19 00:41:18 +00:00
|
|
|
});
|
2016-08-18 13:12:48 +00:00
|
|
|
|
2017-01-04 19:51:40 +00:00
|
|
|
inputs.next('.js-clear-input').on('click', function clicked(event) {
|
2016-08-19 00:41:18 +00:00
|
|
|
event.preventDefault();
|
2016-08-18 13:12:48 +00:00
|
|
|
|
2017-01-03 18:55:36 +00:00
|
|
|
const input = $(this).closest('.clearable-input').find(selector);
|
2016-09-01 10:56:21 +00:00
|
|
|
input.datepicker('setDate', null)
|
|
|
|
.trigger('change');
|
2016-08-19 00:41:18 +00:00
|
|
|
toggleClearInput.call(input);
|
|
|
|
});
|
2016-08-18 13:12:48 +00:00
|
|
|
|
2016-08-19 00:41:18 +00:00
|
|
|
inputs.on('blur', toggleClearInput);
|
2016-08-18 13:12:48 +00:00
|
|
|
|
2016-08-19 00:41:18 +00:00
|
|
|
inputs.each(toggleClearInput);
|
2016-08-18 13:12:48 +00:00
|
|
|
};
|
|
|
|
}).call(this);
|