34 lines
973 B
JavaScript
34 lines
973 B
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
function savePaperChoice(choice) {
|
|
var ajaxUrl = window.wsGiftDropdownAjaxUrl || '';
|
|
if (!ajaxUrl || !choice) {
|
|
return;
|
|
}
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open('POST', ajaxUrl, true);
|
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
xhr.send('gift_paper=' + encodeURIComponent(choice) + '&ajax=1');
|
|
}
|
|
|
|
function init() {
|
|
var checked = document.querySelector('input[name="gift_paper"]:checked');
|
|
if (checked) {
|
|
savePaperChoice(checked.value);
|
|
}
|
|
|
|
document.addEventListener('change', function (e) {
|
|
if (e.target && e.target.name === 'gift_paper') {
|
|
savePaperChoice(e.target.value);
|
|
}
|
|
});
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
} else {
|
|
init();
|
|
}
|
|
}());
|