Last active
January 24, 2017 07:57
-
-
Save gregrickaby/6529091 to your computer and use it in GitHub Desktop.
Simple jQuery Ajax Modal with fail-safe.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Loading Modal | |
*/ | |
$(body).on({ | |
// When ajaxStart is fired, add 'loading' to body class | |
ajaxStart: function() { | |
$(this).addClass('modal-loading'); | |
// After 6 seconds, change button text | |
timer = setTimeout(function() { | |
$('.nav-previous a').html("Still Loading..."); | |
}, 6000); | |
// After 12 seconds, die. Reload page from scratch | |
timer = setTimeout(function() { | |
$(this).removeClass('modal-loading'); | |
$('.nav-previous a').html("Error has occured. Reloading page."); | |
window.location.reload(); | |
}, 12000); | |
}, | |
// When ajaxStop is fired, clear the timer and remove 'loading' from body class | |
ajaxStop: function() { | |
clearTimeout(timer); | |
$(this).removeClass('modal-loading'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Loading Modal | |
-------------------------------------------- */ | |
.modal { | |
background: url('images/ajax-loader.gif') 50% 50% no-repeat; | |
display: none; | |
height: 32px; | |
} | |
body.modal-loading { | |
overflow: hidden; | |
} | |
body.modal-loading .modal { | |
display: block; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="modal"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment