Skip to content

Instantly share code, notes, and snippets.

@Alexkurd
Last active February 21, 2021 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alexkurd/f5f04757f8167883938105aa4208e8be to your computer and use it in GitHub Desktop.
Save Alexkurd/f5f04757f8167883938105aa4208e8be to your computer and use it in GitHub Desktop.
Long action js part.
<div class="bar hidden">
<i class="icon16 loading float-right" style="margin-top: 15px;"></i>
<div class="progressbar width400px green">
<div class="progressbar-outer">
<div class="progressbar-inner" id="progressbar-id" style="width: 0;">
</div>
</div>
</div>
</div>
$('#my_button').click(async () => {
const done = await $.my.sync();
}
)
$.my = {
long_url: '?plugin=plugin_id&action=long',
sync: async function () {
const wait = ms => new Promise((resolve) => setTimeout(resolve, ms));
const process = async (processId) => {
if (!processId) {
$('.bar').show();
let init = await $.get($.my.long_url);
processId = init.processId;
}
let response = await $.post($.my.long_url, { processId: processId});
if (!response.ready) {
await wait(5000);
$('.bar').show();
$('#progressbar-id').css('width', response.progress+'%');
await process(processId);
} else {
$('#progressbar-id').css('width', response.progress+'%');
setTimeout(function (){
$('.bar').hide();
}, 3000);
return response.ready;
}
}
process();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment