Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const RESULT_ELEMENT = '#result-1';
- const WEB_URL = 'https://pipedream.com/r/en3q7l2t3db32';
- function request(module, data = {}, target = RESULT_ELEMENT) {
- const params = {
- request: module,
- data
- };
- showLoader(target);
- return fetch(WEB_URL, {
- mode: 'cors',
- method: 'POST',
- body: JSON.stringify(params),
- headers: {
- 'Content-Type': 'application/json'
- },
- }).then(response => {
- if (!response.ok) {
- throw new Error(`[Request] Module <${module}> not found!`);
- }
- return response.text();
- }).then(response => {
- display(response, target);
- }).finally(() => {
- setTimeout(() => {
- hideLoader(target);
- }, 5000);
- });
- }
- function showLoader(selector) {
- const loadingElement = document.querySelector(selector);
- const loader = getLoaderElement();
- loadingElement.innerHTML = loader;
- loadingElement.classList.add('spinning');
- }
- function hideLoader(selector) {
- document.querySelector(selector).classList.remove('spinning');
- }
- function getLoaderElement() {
- return '<span>Loading...</span>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement