Skip to content

Instantly share code, notes, and snippets.

@ablanathtanalba
Created February 13, 2018 20:20
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 ablanathtanalba/de649114725ff57a548812e9cb071810 to your computer and use it in GitHub Desktop.
Save ablanathtanalba/de649114725ff57a548812e9cb071810 to your computer and use it in GitHub Desktop.
Merlin Guides Solution
/*
SOLUTIONS TO DETECT IF A PAGE IS LOADING
After Ajax calls are made it runs the cb function
*/
//in the rare case that jquery is not already included,
//this appends it to the head
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js";
head.appendChild(script);
//checks elements in page to see if document has any divs labeled 'loading'
//runs callback func, to be determined later
if(document.querySelector('.loading') || document.querySelector('#loading') {
$(document).ajaxComplete(function(cb){
cb();
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment