Skip to content

Instantly share code, notes, and snippets.

@JPaulDuncan
Last active February 8, 2017 21:04
Show Gist options
  • Select an option

  • Save JPaulDuncan/890f49f7cead7f6c7698126a2589af11 to your computer and use it in GitHub Desktop.

Select an option

Save JPaulDuncan/890f49f7cead7f6c7698126a2589af11 to your computer and use it in GitHub Desktop.
Notify a user that an ajax action is happening and prevent clicks. JQuery
/*
* Throws up a notification to tell the end-user a
* server call (ajax) is happening and prevents them
* from clicking elsewhere on the screen while it's
* working.
* USAGE: $.ajaxWorking();
*/
; (function ($) {
$.extend({
ajaxWorking: function () {
$(document).ajaxStart(function () {
var block = document.createElement('div');
$(block).attr("id", "blocker");
$(block).css('position', 'fixed');
$(block).css('top', '0');
$(block).css('left', '0');
$(block).css('width', '100%');
$(block).css('height', '100%');
$(block).css('z-index', '1050');
$(block).html("<h1 class='text-center' style='margin-top:350px;font-size:48px;'><span class='glyphicon glyphicon-time'></span><br /><small>LOADING</small></h1>");
$('body').append(block);
});
$(document).ajaxStop(function () {
$('#blocker').remove();
});
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment