/** * ACS BlockUI Helpers */ (function($) { /** * Blocks the UI with the modern template and a custom message. * @param {string|null|object} message - The custom message to display or options object. * @param {object} [options] - Additional blockUI options. */ window.acsBlockUI = function(message, options) { if (typeof $ === 'undefined' || typeof $.blockUI === 'undefined') return; // Handle case where first argument is an options object if (typeof message === 'object' && message !== null && typeof options === 'undefined' && !message.nodeType && !(message instanceof $)) { options = message; message = options.message || undefined; } options = options || {}; var $template = $('.blockui-loading-message').first(); var $msg = $template.clone().show(); // If we didn't find a template, but have a string message, use it directly if ($msg.length === 0 && typeof message === 'string') { options.message = message; $.blockUI(options); return; } if (typeof message !== 'undefined') { if (message === '') { $msg.find('.blockui-message-text').remove(); $msg.find('i').css('margin-right', '0'); } else if (typeof message === 'string') { $msg.find('.blockui-message-text').html(message); } else if (message instanceof $ || (typeof message === 'object' && message.nodeType)) { // If message is already a DOM element or jQuery object, just use it $msg.find('.blockui-message-text').html('').append(message); } } if ($msg.length > 0) { options.message = $msg; } $.blockUI(options); }; /** * Unblocks the UI. * * Wrapped in try/catch to guard against HierarchyRequestError in blockUI's * reset() when data.parent is a non-element node (Rollbar #10708, #45516). * The overlay elements are already removed before appendChild runs, so the * visual unblock always succeeds even when the catch path is taken. */ window.acsUnblockUI = function() { if (typeof $ === 'undefined' || typeof $.unblockUI === 'undefined') return; try { $.unblockUI(); } catch (e) { // Swallow HierarchyRequestError from blockUI's reset() when the // stored parent node is not a valid element target for appendChild. // Clear any lingering blockUI history to avoid repeated errors. $(window).removeData('blockUI.history'); } }; // Initialize defaults on document ready $(function() { if (typeof $.blockUI !== 'undefined') { $.blockUI.defaults.css = $.extend({}, $.blockUI.defaults.css, { padding: '20px', margin: 0, width: '400px', top: '40%', left: 'calc(50% - 200px)', textAlign: 'center', color: '#fff', border: 'none', backgroundColor: 'rgba(0,0,0,0.8)', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', 'border-radius': '10px', cursor: 'wait' }); $.blockUI.defaults.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, { backgroundColor: '#000', opacity: 0.6, cursor: 'wait' }); // NOTE: Do NOT set $.blockUI.defaults.message to a shared DOM clone here. // Reusing the same jQuery object across block/unblock cycles means // blockUI stores that clone's parentNode in the history, which can // become stale or invalid, triggering HierarchyRequestError in reset() // when the parent node is a non-element (Rollbar #10708, #45516). // Each acsBlockUI() call already creates a fresh clone — that is sufficient. } }); })(window.jQuery);