wip renaming plugins elements
This commit is contained in:
8
plugins/fipfcard_plugin/js/example_init.js
Normal file
8
plugins/fipfcard_plugin/js/example_init.js
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
const title = document.querySelector(".first_el_to_change");
|
||||
title.innerHTML = "--- coucou ;) " + myvar_1;
|
||||
|
||||
const ajax_button_1 = document.querySelector("#test_ajax_1");
|
||||
ajax_button_1.addEventListener('click', () => {
|
||||
ajax_post(ajax_button_1, 'get_data');
|
||||
});
|
||||
3
plugins/fipfcard_plugin/js/example_script2.js
Normal file
3
plugins/fipfcard_plugin/js/example_script2.js
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
const title2 = document.querySelector(".second_el_to_change");
|
||||
title2.innerHTML = "--- ho boy !";
|
||||
3
plugins/fipfcard_plugin/js/example_script3.js
Normal file
3
plugins/fipfcard_plugin/js/example_script3.js
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
const title3 = document.querySelector(".third_el_to_change");
|
||||
title3.innerHTML = "--- bye bye, " + myvar_2;
|
||||
7
plugins/fipfcard_plugin/js/menu/example_menu.js
Normal file
7
plugins/fipfcard_plugin/js/menu/example_menu.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const inputElement = document.getElementById('mytext');
|
||||
const sendButton = document.getElementById('mybutton');
|
||||
|
||||
sendButton.addEventListener('click', () => {
|
||||
const inputValue = inputElement.value;
|
||||
ajax_post(inputValue, 'get_data');
|
||||
});
|
||||
34
plugins/fipfcard_plugin/js/utils/ajax.js
Normal file
34
plugins/fipfcard_plugin/js/utils/ajax.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
function that create an ajax post action
|
||||
it can be "overloaded" with a callback_response and _error
|
||||
*/
|
||||
function ajax_post(ajax_data, action, callback_response, callback_error) {
|
||||
const data = new FormData();
|
||||
data.append('action', action);
|
||||
data.append('_ajax_nonce', wp_ajax._nonce);
|
||||
data.append('data', ajax_data);
|
||||
|
||||
fetch(wp_ajax._url, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
body: data
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (callback_response)
|
||||
callback_response(data);
|
||||
else {
|
||||
console.log("data: ");
|
||||
console.log(data);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if (callback_error)
|
||||
callback_error(error);
|
||||
else {
|
||||
console.log("error: ");
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user