Monday, January 19, 2015

jQuery BlockUI toggle detection

I realised that our JavaScript function that's calling blockUI was triggering the overlay regardless if it was already activated. This caused the grayed out screen to flash to white and back to gray.

As suggested on http://stackoverflow.com/questions/7907013/jquery-blockui-tell-if-page-or-specific-element-is-blocked, I made a variation of the posted solution of
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
The '#element' bit was not applicable to me as much than if I were to instead use
var data = $(window).data();
if (data["blockUI.isBlocked"] == 1) {
  // is blocked
}
 The overlay was on the entire window and thus would otherwise have returned an empty [Object object] on the document alone.

No comments:

Post a Comment