20
$.fn._fadeIn = $.fn.fadeIn;
22
var noOp = $.noop || function() {};
26
var msie = /MSIE/.test(navigator.userAgent);
27
var ie6 = /MSIE 6.0/.test(navigator.userAgent) && ! /MSIE 8.0/.test(navigator.userAgent);
28
var mode = document.documentMode || 0;
29
var setExpr = $.isFunction( document.createElement('div').style.setExpression );
32
$.blockUI = function(opts) { install(window, opts); };
33
$.unblockUI = function(opts) { remove(window, opts); };
36
$.growlUI = function(title, message, timeout, onClose) {
37
var $m = $('<div class="growlUI"></div>');
38
if (title) $m.append('<h1>'+title+'</h1>');
39
if (message) $m.append('<h2>'+message+'</h2>');
40
if (timeout === undefined) timeout = 3000;
43
var callBlock = function(opts) {
48
fadeIn : typeof opts.fadeIn !== 'undefined' ? opts.fadeIn : 700,
49
fadeOut: typeof opts.fadeOut !== 'undefined' ? opts.fadeOut : 1000,
50
timeout: typeof opts.timeout !== 'undefined' ? opts.timeout : timeout,
54
css: $.blockUI.defaults.growlCSS
59
var nonmousedOpacity = $m.css('opacity');
60
$m.mouseover(function() {
66
var displayBlock = $('.blockMsg');
68
displayBlock.fadeTo(300, 1);
69
}).mouseout(function() {
70
$('.blockMsg').fadeOut(1000);
76
$.fn.block = function(opts) {
77
if ( this[0] === window ) {
81
var fullOpts = $.extend({}, $.blockUI.defaults, opts || {});
82
this.each(function() {
84
if (fullOpts.ignoreIfBlocked && $el.data('blockUI.isBlocked'))
86
$el.unblock({ fadeOut: 0 });
89
return this.each(function() {
90
if ($.css(this,'position') == 'static') {
91
this.style.position = 'relative';
92
$(this).data('blockUI.static', true);
100
$.fn.unblock = function(opts) {
101
if ( this[0] === window ) {
105
return this.each(function() {
110
$.blockUI.version = 2.70;
113
$.blockUI.defaults = {
115
message: '<h1>Please wait...</h1>',
133
border: '3px solid #aaa',
134
backgroundColor:'#fff',
147
backgroundColor: '#000',
154
cursorReset: 'default',
167
backgroundColor: '#000',
168
'-webkit-border-radius':'10px',
169
'-moz-border-radius': '10px',
170
'border-radius': '10px'
176
iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank',
190
allowBodyStretch: true,
197
constrainTabKey: true,
216
focusableElements: ':input:enabled:visible',
233
onOverlayClick: null,
236
quirksmodeOffsetHack: 4,
239
blockMsgClass: 'blockMsg',
242
ignoreIfBlocked: false
247
var pageBlock = null;
248
var pageBlockEls = [];
250
function install(el, opts) {
252
var full = (el == window);
253
var msg = (opts && opts.message !== undefined ? opts.message : undefined);
254
opts = $.extend({}, $.blockUI.defaults, opts || {});
256
if (opts.ignoreIfBlocked && $(el).data('blockUI.isBlocked'))
259
opts.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, opts.overlayCSS || {});
260
css = $.extend({}, $.blockUI.defaults.css, opts.css || {});
261
if (opts.onOverlayClick)
262
opts.overlayCSS.cursor = 'pointer';
264
themedCSS = $.extend({}, $.blockUI.defaults.themedCSS, opts.themedCSS || {});
265
msg = msg === undefined ? opts.message : msg;
268
if (full && pageBlock)
269
remove(window, {fadeOut:0});
274
if (msg && typeof msg != 'string' && (msg.parentNode || msg.jquery)) {
275
var node = msg.jquery ? msg[0] : msg;
277
$(el).data('blockUI.history', data);
279
data.parent = node.parentNode;
280
data.display = node.style.display;
281
data.position = node.style.position;
283
data.parent.removeChild(node);
286
$(el).data('blockUI.onUnblock', opts.onUnblock);
293
var lyr1, lyr2, lyr3, s;
294
if (msie || opts.forceIframe)
295
lyr1 = $('<iframe class="blockUI" style="z-index:'+ (z++) +';display:none;border:none;margin:0;padding:0;position:absolute;width:100%;height:100%;top:0;left:0" src="'+opts.iframeSrc+'"></iframe>');
297
lyr1 = $('<div class="blockUI" style="display:none"></div>');
300
lyr2 = $('<div class="blockUI blockOverlay ui-widget-overlay" style="z-index:'+ (z++) +';display:none"></div>');
302
lyr2 = $('<div class="blockUI blockOverlay" style="z-index:'+ (z++) +';display:none;border:none;margin:0;padding:0;width:100%;height:100%;top:0;left:0"></div>');
304
if (opts.theme && full) {
305
s = '<div class="blockUI ' + opts.blockMsgClass + ' blockPage ui-dialog ui-widget ui-corner-all" style="z-index:'+(z+10)+';display:none;position:fixed">';
307
s += '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || ' ')+'</div>';
309
s += '<div class="ui-widget-content ui-dialog-content"></div>';
312
else if (opts.theme) {
313
s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement ui-dialog ui-widget ui-corner-all" style="z-index:'+(z+10)+';display:none;position:absolute">';
315
s += '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || ' ')+'</div>';
317
s += '<div class="ui-widget-content ui-dialog-content"></div>';
321
s = '<div class="blockUI ' + opts.blockMsgClass + ' blockPage" style="z-index:'+(z+10)+';display:none;position:fixed"></div>';
324
s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement" style="z-index:'+(z+10)+';display:none;position:absolute"></div>';
332
lyr3.addClass('ui-widget-content');
340
lyr2.css(opts.overlayCSS);
341
lyr2.css('position', full ? 'fixed' : 'absolute');
344
if (msie || opts.forceIframe)
345
lyr1.css('opacity',0.0);
348
var layers = [lyr1,lyr2,lyr3], $par = full ? $('body') : $(el);
349
$.each(layers, function() {
353
if (opts.theme && opts.draggable && $.fn.draggable) {
355
handle: '.ui-dialog-titlebar',
361
var expr = setExpr && (!$.support.boxModel || $('object,embed', full ? null : el).length > 0);
364
if (full && opts.allowBodyStretch && $.support.boxModel)
365
$('html,body').css('height','100%');
368
if ((ie6 || !$.support.boxModel) && !full) {
369
var t = sz(el,'borderTopWidth'), l = sz(el,'borderLeftWidth');
370
var fixT = t ? '(0 - '+t+')' : 0;
371
var fixL = l ? '(0 - '+l+')' : 0;
375
$.each(layers, function(i,o) {
377
s.position = 'absolute';
380
s.setExpression('height','Math.max(document.body.scrollHeight, document.body.offsetHeight) - (jQuery.support.boxModel?0:'+opts.quirksmodeOffsetHack+') + "px"');
382
s.setExpression('height','this.parentNode.offsetHeight + "px"');
384
s.setExpression('width','jQuery.support.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"');
386
s.setExpression('width','this.parentNode.offsetWidth + "px"');
387
if (fixL) s.setExpression('left', fixL);
388
if (fixT) s.setExpression('top', fixT);
390
else if (opts.centerY) {
391
if (full) s.setExpression('top','(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"');
394
else if (!opts.centerY && full) {
395
var top = (opts.css && opts.css.top) ? parseInt(opts.css.top, 10) : 0;
396
var expression = '((document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + '+top+') + "px"';
397
s.setExpression('top',expression);
405
lyr3.find('.ui-widget-content').append(msg);
408
if (msg.jquery || msg.nodeType)
412
if ((msie || opts.forceIframe) && opts.showOverlay)
415
var cb = opts.onBlock ? opts.onBlock : noOp;
416
var cb1 = (opts.showOverlay && !msg) ? cb : noOp;
417
var cb2 = msg ? cb : noOp;
418
if (opts.showOverlay)
419
lyr2._fadeIn(opts.fadeIn, cb1);
421
lyr3._fadeIn(opts.fadeIn, cb2);
424
if (opts.showOverlay)
429
opts.onBlock.bind(lyr3)();
437
pageBlockEls = $(opts.focusableElements,pageBlock);
439
setTimeout(focus, 20);
442
center(lyr3[0], opts.centerX, opts.centerY);
446
var to = setTimeout(function() {
452
$(el).data('blockUI.timeout', to);
457
function remove(el, opts) {
459
var full = (el == window);
461
var data = $el.data('blockUI.history');
462
var to = $el.data('blockUI.timeout');
465
$el.removeData('blockUI.timeout');
467
opts = $.extend({}, $.blockUI.defaults, opts || {});
470
if (opts.onUnblock === null) {
471
opts.onUnblock = $el.data('blockUI.onUnblock');
472
$el.removeData('blockUI.onUnblock');
477
els = $('body').children().filter('.blockUI').add('body > .blockUI');
479
els = $el.find('>.blockUI');
482
if ( opts.cursorReset ) {
483
if ( els.length > 1 )
484
els[1].style.cursor = opts.cursorReset;
485
if ( els.length > 2 )
486
els[2].style.cursor = opts.cursorReset;
490
pageBlock = pageBlockEls = null;
494
els.stop().fadeOut(opts.fadeOut, function() {
496
reset(els,data,opts,el);
500
reset(els, data, opts, el);
504
function reset(els,data,opts,el) {
506
if ( $el.data('blockUI.isBlocked') )
509
els.each(function(i,o) {
512
this.parentNode.removeChild(this);
515
if (data && data.el) {
516
data.el.style.display = data.display;
517
data.el.style.position = data.position;
518
data.el.style.cursor = 'default';
520
data.parent.appendChild(data.el);
521
$el.removeData('blockUI.history');
524
if ($el.data('blockUI.static')) {
525
$el.css('position', 'static');
528
if (typeof opts.onUnblock == 'function')
529
opts.onUnblock(el,opts);
532
var body = $(document.body), w = body.width(), cssW = body[0].style.width;
533
body.width(w-1).width(w);
534
body[0].style.width = cssW;
538
function bind(b, el, opts) {
539
var full = el == window, $el = $(el);
542
if (!b && (full && !pageBlock || !full && !$el.data('blockUI.isBlocked')))
545
$el.data('blockUI.isBlocked', b);
548
if (!full || !opts.bindEvents || (b && !opts.showOverlay))
552
var events = 'mousedown mouseup keydown keypress keyup touchstart touchend touchmove';
554
$(document).bind(events, opts, handler);
556
$(document).unbind(events, handler);
564
function handler(e) {
566
if (e.type === 'keydown' && e.keyCode && e.keyCode == 9) {
567
if (pageBlock && e.data.constrainTabKey) {
568
var els = pageBlockEls;
569
var fwd = !e.shiftKey && e.target === els[els.length-1];
570
var back = e.shiftKey && e.target === els[0];
572
setTimeout(function(){focus(back);},10);
578
var target = $(e.target);
579
if (target.hasClass('blockOverlay') && opts.onOverlayClick)
580
opts.onOverlayClick(e);
583
if (target.parents('div.' + opts.blockMsgClass).length > 0)
587
return target.parents().children().filter('div.blockUI').length === 0;
590
function focus(back) {
593
var e = pageBlockEls[back===true ? pageBlockEls.length-1 : 0];
598
function center(el, x, y) {
599
var p = el.parentNode, s = el.style;
600
var l = ((p.offsetWidth - el.offsetWidth)/2) - sz(p,'borderLeftWidth');
601
var t = ((p.offsetHeight - el.offsetHeight)/2) - sz(p,'borderTopWidth');
602
if (x) s.left = l > 0 ? (l+'px') : '0';
603
if (y) s.top = t > 0 ? (t+'px') : '0';
607
return parseInt($.css(el,p),10)||0;
614
if (typeof define === 'function' && define.amd) {
616
define(['jquery'], setup);
617
} else if (typeof exports === 'object') {
619
setup(require('jquery'));