Screen lock not removed sometimes when ajax response returned. It's because in same time can be send other ajax, which set unblock=false and not runed blockUI().
First simple solution, check if screen lock already showed. For this we should use condition and check onblock variable.
Here my example, which contain other my patches:
(function($) {
var unblock;
$(document).ajaxSend(function(event, jqxhr, settings) {
if (unblock != true) {
unblock = false;
var target = settings.url;
var pages = Drupal.settings.ajax_screen_lock.pages;
var visibility = Drupal.settings.ajax_screen_lock.visibility;
var throbber_hide = Drupal.settings.ajax_screen_lock.throbber_hide;
var disabled = Drupal.settings.ajax_screen_lock.disabled;
var blockui = function () {
unblock = true;
if (throbber_hide) {
$('.ajax-progress-throbber').hide();
}
$.blockUI({
message: Drupal.settings.ajax_screen_lock.message,
css: {
top: ($(window).height() - 400) / 2 + 'px',
left: ($(window).width() - 400) / 2 + 'px',
width: '400px'
},
timeout: Drupal.settings.ajax_screen_lock.timeout
});
}
// If is not disabled.
if (!disabled) {
if (!$.isEmptyObject(pages)) {
// Handle pages.
$.each(pages, function (num, page) {
if (target.length >= page.trim().length) {
if (target.substr(0, page.trim().length) == page.trim() && visibility == 1) {
blockui();
}
else if (visibility == 0 && target.substr(0, page.trim().length) != page.trim()) {
blockui();
}
}
});
}
else {
blockui();
}
}
}
});
$(document).ajaxStop(function(r, s) {
if (unblock) {
$.unblockUI();
}
});
}(jQuery));
Comments
Comment #1
samvel commentedAlso it's not working example, i will update it soon
Comment #2
samvel commentedPatch attached.
But pay attention, in this case ajax screen will be unlocked after first ajax responsed. Second Ajax request won't be processed.
Comment #3
eugene.ilyin commentedHello Samvel
Sorry, but I can't reproduce this problem.
Can you provide more details?
I tryed to use this PoC in console:
Comment #4
eugene.ilyin commentedI'm closing this issue, but not hesitate to open it again if you'll have troubles.
Comment #5
eugene.ilyin commented