/** * 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. */ window.acsUnblockUI = function() { if (typeof $ === 'undefined' || typeof $.unblockUI === 'undefined') return; $.unblockUI(); }; // 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' }); var $template = $('.blockui-loading-message').first(); if ($template.length > 0) { $.blockUI.defaults.message = $template.clone().show(); } } }); })(window.jQuery);