jquery blockUI tell if page or specific element is blocked
Asked Answered
S

4

16

Is there a way to tell if $.blockUI(); has been called but $.unblockUI() has not been called? Ideally this should be able to work for both blocking the full page and specific elements.

I'd expect it to work something like this

> $.blockUI();
> $.isBlockUI?():
>> true
> $.unblockUI();
> $.isBlockUI?();
>> false
Shiva answered 26/10, 2011 at 18:15 Comment(0)
C
10

Look what I found here

  $(document).ready(function() { 
    $('#demo14').click(function() { 
        $.blockUI({ 
            fadeIn: 1000, 
            timeout:   2000, 
            onBlock: function() { 
                alert('Page is now blocked; fadeIn complete'); 
            } 
        }); 
    });

Evidently there's one for Block and unBlock sorta like a onSuccess function. So on the onBlock function you'd simply just set a global boolean value.

Hope this helps!

Happy Coding! ;)

Cott answered 26/10, 2011 at 18:44 Comment(0)
F
32
var data = $('#element').data();
//will return Object like: { blockUI.isBlocked=1, blockUI.onUnblock=null} 

if (data["blockUI.isBlocked"] == 1)
// is blocked
else
// is not blocked
Focal answered 23/5, 2012 at 7:18 Comment(1)
Agreed. It more directly answers the question.Irradiant
C
10

Look what I found here

  $(document).ready(function() { 
    $('#demo14').click(function() { 
        $.blockUI({ 
            fadeIn: 1000, 
            timeout:   2000, 
            onBlock: function() { 
                alert('Page is now blocked; fadeIn complete'); 
            } 
        }); 
    });

Evidently there's one for Block and unBlock sorta like a onSuccess function. So on the onBlock function you'd simply just set a global boolean value.

Hope this helps!

Happy Coding! ;)

Cott answered 26/10, 2011 at 18:44 Comment(0)
S
4

I use a more primitive hack :

var isUIBlocked = $('.ui-widget-overlay:visible').length > 0;

if(isUIBlocked){
  // something is displayed with an active overlay, hence stop
}

This works for me even when using .dialog() with modal:true

Straightforward answered 9/11, 2012 at 11:19 Comment(1)
Can you tell if a SPECIFIC element is blocked? That's half the question asked. (I know this is super old. Was just looking for the answer myself.)Ashcraft
A
0

This can find all specific elements that are currently blocked:

const $blockedElements = $("*").filter(function() { return $(this).data("blockUI.isBlocked") === 1 });
Aixlachapelle answered 5/7 at 14:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.