(main): Add module
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
(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();
|
||||
}
|
||||
}());
|
||||
Reference in New Issue
Block a user