PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / includes / blockui / jquery.blockUI.js

jquery.blockUI.js in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 4.7.0, at includes/blockui/jquery.blockUI.js

624 lines 19.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*!
2 * jQuery blockUI plugin
3 * Version 2.71.0-2020.12.08
4 * Requires jQuery v1.12 or later
5 *
6 * Examples at: http://malsup.com/jquery/block/
7 * Copyright (c) 2007-2013 M. Alsup
8 * Dual licensed under the MIT and GPL licenses:
9 * http://www.opensource.org/licenses/mit-license.php
10 * http://www.gnu.org/licenses/gpl.html
11 *
12 * Thanks to Amir-Hossein Sobhi for some excellent contributions!
13 */
14
15 ;(function() {
16 /*jshint eqeqeq:false curly:false latedef:false */
17 "use strict";
18
19 function setup($) {
20 var migrateDeduplicateWarnings = jQuery.migrateDeduplicateWarnings || false;
21 jQuery.migrateDeduplicateWarnings = false;
22
23 $.fn._fadeIn = $.fn.fadeIn;
24
25 var noOp = $.noop || function() {};
26
27 // this bit is to ensure we don't call setExpression when we shouldn't (with extra muscle to handle
28 // confusing userAgent strings on Vista)
29 var msie = /MSIE/.test(navigator.userAgent);
30 var ie6 = /MSIE 6.0/.test(navigator.userAgent) && ! /MSIE 8.0/.test(navigator.userAgent);
31 var mode = document.documentMode || 0;
32 var setExpr = "function" === typeof document.createElement('div').style.setExpression;
33
34 // global $ methods for blocking/unblocking the entire page
35 $.blockUI = function(opts) { install(window, opts); };
36 $.unblockUI = function(opts) { remove(window, opts); };
37
38 // convenience method for quick growl-like notifications (http://www.google.com/search?q=growl)
39 $.growlUI = function(title, message, timeout, onClose) {
40 var $m = $('<div class="growlUI"></div>');
41 if (title) $m.append('<h1>'+title+'</h1>');
42 if (message) $m.append('<h2>'+message+'</h2>');
43 if (timeout === undefined) timeout = 3000;
44
45 // Added by konapun: Set timeout to 30 seconds if this growl is moused over, like normal toast notifications
46 var callBlock = function(opts) {
47 opts = opts || {};
48
49 $.blockUI({
50 message: $m,
51 fadeIn : typeof opts.fadeIn !== 'undefined' ? opts.fadeIn : 700,
52 fadeOut: typeof opts.fadeOut !== 'undefined' ? opts.fadeOut : 1000,
53 timeout: typeof opts.timeout !== 'undefined' ? opts.timeout : timeout,
54 centerY: false,
55 showOverlay: false,
56 onUnblock: onClose,
57 css: $.blockUI.defaults.growlCSS
58 });
59 };
60
61 callBlock();
62 var nonmousedOpacity = $m.css('opacity');
63 $m.on('mouseover', function() {
64 callBlock({
65 fadeIn: 0,
66 timeout: 30000
67 });
68
69 var displayBlock = $('.blockMsg');
70 displayBlock.stop(); // cancel fadeout if it has started
71 displayBlock.fadeTo(300, 1); // make it easier to read the message by removing transparency
72 }).on('mouseout', function() {
73 $('.blockMsg').fadeOut(1000);
74 });
75 // End konapun additions
76 };
77
78 // plugin method for blocking element content
79 $.fn.block = function(opts) {
80 if ( this[0] === window ) {
81 $.blockUI( opts );
82 return this;
83 }
84 var fullOpts = $.extend({}, $.blockUI.defaults, opts || {});
85 this.each(function() {
86 var $el = $(this);
87 if (fullOpts.ignoreIfBlocked && $el.data('blockUI.isBlocked'))
88 return;
89 $el.unblock({ fadeOut: 0 });
90 });
91
92 return this.each(function() {
93 if ($.css(this,'position') == 'static') {
94 this.style.position = 'relative';
95 $(this).data('blockUI.static', true);
96 }
97 this.style.zoom = 1; // force 'hasLayout' in ie
98 install(this, opts);
99 });
100 };
101
102 // plugin method for unblocking element content
103 $.fn.unblock = function(opts) {
104 if ( this[0] === window ) {
105 $.unblockUI( opts );
106 return this;
107 }
108 return this.each(function() {
109 remove(this, opts);
110 });
111 };
112
113 $.blockUI.version = 2.70; // 2nd generation blocking at no extra cost!
114
115 // override these in your code to change the default behavior and style
116 $.blockUI.defaults = {
117 // message displayed when blocking (use null for no message)
118 message: '<h1>Please wait...</h1>',
119
120 title: null, // title string; only used when theme == true
121 draggable: true, // only used when theme == true (requires jquery-ui.js to be loaded)
122
123 theme: false, // set to true to use with jQuery UI themes
124
125 // styles for the message when blocking; if you wish to disable
126 // these and use an external stylesheet then do this in your code:
127 // $.blockUI.defaults.css = {};
128 css: {
129 padding: 0,
130 margin: 0,
131 width: '30%',
132 top: '40%',
133 left: '35%',
134 textAlign: 'center',
135 color: '#000',
136 border: '3px solid #aaa',
137 backgroundColor:'#fff',
138 cursor: 'wait'
139 },
140
141 // minimal style set used when themes are used
142 themedCSS: {
143 width: '30%',
144 top: '40%',
145 left: '35%'
146 },
147
148 // styles for the overlay
149 overlayCSS: {
150 backgroundColor: '#000',
151 opacity: 0.6,
152 cursor: 'wait'
153 },
154
155 // style to replace wait cursor before unblocking to correct issue
156 // of lingering wait cursor
157 cursorReset: 'default',
158
159 // styles applied when using $.growlUI
160 growlCSS: {
161 width: '350px',
162 top: '10px',
163 left: '',
164 right: '10px',
165 border: 'none',
166 padding: '5px',
167 opacity: 0.6,
168 cursor: 'default',
169 color: '#fff',
170 backgroundColor: '#000',
171 '-webkit-border-radius':'10px',
172 '-moz-border-radius': '10px',
173 'border-radius': '10px'
174 },
175
176 // IE issues: 'about:blank' fails on HTTPS and javascript:false is s-l-o-w
177 // (hat tip to Jorge H. N. de Vasconcelos)
178 /*jshint scripturl:true */
179 iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank',
180
181 // force usage of iframe in non-IE browsers (handy for blocking applets)
182 forceIframe: false,
183
184 // z-index for the blocking overlay
185 baseZ: 1000,
186
187 // set these to true to have the message automatically centered
188 centerX: true, // <-- only effects element blocking (page block controlled via css above)
189 centerY: true,
190
191 // allow body element to be stetched in ie6; this makes blocking look better
192 // on "short" pages. disable if you wish to prevent changes to the body height
193 allowBodyStretch: true,
194
195 // enable if you want key and mouse events to be disabled for content that is blocked
196 bindEvents: true,
197
198 // be default blockUI will suppress tab navigation from leaving blocking content
199 // (if bindEvents is true)
200 constrainTabKey: true,
201
202 // fadeIn time in millis; set to 0 to disable fadeIn on block
203 fadeIn: 200,
204
205 // fadeOut time in millis; set to 0 to disable fadeOut on unblock
206 fadeOut: 400,
207
208 // time in millis to wait before auto-unblocking; set to 0 to disable auto-unblock
209 timeout: 0,
210
211 // disable if you don't want to show the overlay
212 showOverlay: true,
213
214 // if true, focus will be placed in the first available input field when
215 // page blocking
216 focusInput: true,
217
218 // elements that can receive focus
219 focusableElements: ':input:enabled:visible',
220
221 // suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity)
222 // no longer needed in 2012
223 // applyPlatformOpacityRules: true,
224
225 // callback method invoked when fadeIn has completed and blocking message is visible
226 onBlock: null,
227
228 // callback method invoked when unblocking has completed; the callback is
229 // passed the element that has been unblocked (which is the window object for page
230 // blocks) and the options that were passed to the unblock call:
231 // onUnblock(element, options)
232 onUnblock: null,
233
234 // callback method invoked when the overlay area is clicked.
235 // setting this will turn the cursor to a pointer, otherwise cursor defined in overlayCss will be used.
236 onOverlayClick: null,
237
238 // don't ask; if you really must know: http://groups.google.com/group/jquery-en/browse_thread/thread/36640a8730503595/2f6a79a77a78e493#2f6a79a77a78e493
239 quirksmodeOffsetHack: 4,
240
241 // class name of the message block
242 blockMsgClass: 'blockMsg',
243
244 // if it is already blocked, then ignore it (don't unblock and reblock)
245 ignoreIfBlocked: false
246 };
247
248 // private data and functions follow...
249
250 var pageBlock = null;
251 var pageBlockEls = [];
252
253 function install(el, opts) {
254 var css, themedCSS;
255 var full = (el == window);
256 var msg = (opts && opts.message !== undefined ? opts.message : undefined);
257 opts = $.extend({}, $.blockUI.defaults, opts || {});
258
259 if (opts.ignoreIfBlocked && $(el).data('blockUI.isBlocked'))
260 return;
261
262 opts.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, opts.overlayCSS || {});
263 css = $.extend({}, $.blockUI.defaults.css, opts.css || {});
264 if (opts.onOverlayClick)
265 opts.overlayCSS.cursor = 'pointer';
266
267 themedCSS = $.extend({}, $.blockUI.defaults.themedCSS, opts.themedCSS || {});
268 msg = msg === undefined ? opts.message : msg;
269
270 // remove the current block (if there is one)
271 if (full && pageBlock)
272 remove(window, {fadeOut:0});
273
274 // if an existing element is being used as the blocking content then we capture
275 // its current place in the DOM (and current display style) so we can restore
276 // it when we unblock
277 if (msg && typeof msg != 'string' && (msg.parentNode || msg.jquery)) {
278 var node = msg.jquery ? msg[0] : msg;
279 var data = {};
280 $(el).data('blockUI.history', data);
281 data.el = node;
282 data.parent = node.parentNode;
283 data.display = node.style.display;
284 data.position = node.style.position;
285 if (data.parent)
286 data.parent.removeChild(node);
287 }
288
289 $(el).data('blockUI.onUnblock', opts.onUnblock);
290 var z = opts.baseZ;
291
292 // blockUI uses 3 layers for blocking, for simplicity they are all used on every platform;
293 // layer1 is the iframe layer which is used to suppress bleed through of underlying content
294 // layer2 is the overlay layer which has opacity and a wait cursor (by default)
295 // layer3 is the message content that is displayed while blocking
296 var lyr1, lyr2, lyr3, s;
297 if (msie || opts.forceIframe)
298 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>');
299 else
300 lyr1 = $('<div class="blockUI" style="display:none"></div>');
301
302 if (opts.theme)
303 lyr2 = $('<div class="blockUI blockOverlay ui-widget-overlay" style="z-index:'+ (z++) +';display:none"></div>');
304 else
305 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>');
306
307 if (opts.theme && full) {
308 s = '<div class="blockUI ' + opts.blockMsgClass + ' blockPage ui-dialog ui-widget ui-corner-all" style="z-index:'+(z+10)+';display:none;position:fixed">';
309 if ( opts.title ) {
310 s += '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || '&nbsp;')+'</div>';
311 }
312 s += '<div class="ui-widget-content ui-dialog-content"></div>';
313 s += '</div>';
314 }
315 else if (opts.theme) {
316 s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement ui-dialog ui-widget ui-corner-all" style="z-index:'+(z+10)+';display:none;position:absolute">';
317 if ( opts.title ) {
318 s += '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || '&nbsp;')+'</div>';
319 }
320 s += '<div class="ui-widget-content ui-dialog-content"></div>';
321 s += '</div>';
322 }
323 else if (full) {
324 s = '<div class="blockUI ' + opts.blockMsgClass + ' blockPage" style="z-index:'+(z+10)+';display:none;position:fixed"></div>';
325 }
326 else {
327 s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement" style="z-index:'+(z+10)+';display:none;position:absolute"></div>';
328 }
329 lyr3 = $(s);
330
331 // if we have a message, style it
332 if (msg) {
333 if (opts.theme) {
334 lyr3.css(themedCSS);
335 lyr3.addClass('ui-widget-content');
336 }
337 else
338 lyr3.css(css);
339 }
340
341 // style the overlay
342 if (!opts.theme /*&& (!opts.applyPlatformOpacityRules)*/)
343 lyr2.css(opts.overlayCSS);
344 lyr2.css('position', full ? 'fixed' : 'absolute');
345
346 // make iframe layer transparent in IE
347 if (msie || opts.forceIframe)
348 lyr1.css('opacity',0.0);
349
350 //$([lyr1[0],lyr2[0],lyr3[0]]).appendTo(full ? 'body' : el);
351 var layers = [lyr1,lyr2,lyr3], $par = full ? $('body') : $(el);
352 $.each(layers, function() {
353 this.appendTo($par);
354 });
355
356 if (opts.theme && opts.draggable && $.fn.draggable) {
357 lyr3.draggable({
358 handle: '.ui-dialog-titlebar',
359 cancel: 'li'
360 });
361 }
362
363 // ie7 must use absolute positioning in quirks mode and to account for activex issues (when scrolling)
364 var expr = setExpr && ( "CSS1Compat" !== document.compatMode || $('object,embed', full ? null : el).length > 0);
365 if (ie6 || expr) {
366 // give body 100% height
367 if (full && opts.allowBodyStretch && "CSS1Compat" === document.compatMode)
368 $('html,body').css('height','100%');
369
370 // fix ie6 issue when blocked element has a border width
371 if ((ie6 || "CSS1Compat" !== document.compatMode) && !full) {
372 var t = sz(el,'borderTopWidth'), l = sz(el,'borderLeftWidth');
373 var fixT = t ? '(0 - '+t+')' : 0;
374 var fixL = l ? '(0 - '+l+')' : 0;
375 }
376
377 // simulate fixed position
378 $.each(layers, function(i,o) {
379 var s = o[0].style;
380 s.position = 'absolute';
381 if (i < 2) {
382 if (full)
383 s.setExpression('height','Math.max(document.body.scrollHeight, document.body.offsetHeight) - ("CSS1Compat" === document.compatMode?0:'+opts.quirksmodeOffsetHack+') + "px"');
384 else
385 s.setExpression('height','this.parentNode.offsetHeight + "px"');
386 if (full)
387 s.setExpression('width','"CSS1Compat" === document.compatMode && document.documentElement.clientWidth || document.body.clientWidth + "px"');
388 else
389 s.setExpression('width','this.parentNode.offsetWidth + "px"');
390 if (fixL) s.setExpression('left', fixL);
391 if (fixT) s.setExpression('top', fixT);
392 }
393 else if (opts.centerY) {
394 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"');
395 s.marginTop = 0;
396 }
397 else if (!opts.centerY && full) {
398 var top = (opts.css && opts.css.top) ? parseInt(opts.css.top, 10) : 0;
399 var expression = '((document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + '+top+') + "px"';
400 s.setExpression('top',expression);
401 }
402 });
403 }
404
405 // show the message
406 if (msg) {
407 if (opts.theme)
408 lyr3.find('.ui-widget-content').append(msg);
409 else
410 lyr3.append(msg);
411 if (msg.jquery || msg.nodeType)
412 $(msg).show();
413 }
414
415 if ((msie || opts.forceIframe) && opts.showOverlay)
416 lyr1.show(); // opacity is zero
417 if (opts.fadeIn) {
418 var cb = opts.onBlock ? opts.onBlock : noOp;
419 var cb1 = (opts.showOverlay && !msg) ? cb : noOp;
420 var cb2 = msg ? cb : noOp;
421 if (opts.showOverlay)
422 lyr2._fadeIn(opts.fadeIn, cb1);
423 if (msg)
424 lyr3._fadeIn(opts.fadeIn, cb2);
425 }
426 else {
427 if (opts.showOverlay)
428 lyr2.show();
429 if (msg)
430 lyr3.show();
431 if (opts.onBlock)
432 opts.onBlock.bind(lyr3)();
433 }
434
435 // bind key and mouse events
436 bind(1, el, opts);
437
438 if (full) {
439 pageBlock = lyr3[0];
440 pageBlockEls = $(opts.focusableElements,pageBlock);
441 if (opts.focusInput)
442 setTimeout(focus, 20);
443 }
444 else
445 center(lyr3[0], opts.centerX, opts.centerY);
446
447 if (opts.timeout) {
448 // auto-unblock
449 var to = setTimeout(function() {
450 if (full)
451 $.unblockUI(opts);
452 else
453 $(el).unblock(opts);
454 }, opts.timeout);
455 $(el).data('blockUI.timeout', to);
456 }
457 }
458
459 // remove the block
460 function remove(el, opts) {
461 var count;
462 var full = (el == window);
463 var $el = $(el);
464 var data = $el.data('blockUI.history');
465 var to = $el.data('blockUI.timeout');
466 if (to) {
467 clearTimeout(to);
468 $el.removeData('blockUI.timeout');
469 }
470 opts = $.extend({}, $.blockUI.defaults, opts || {});
471 bind(0, el, opts); // unbind events
472
473 if (opts.onUnblock === null) {
474 opts.onUnblock = $el.data('blockUI.onUnblock');
475 $el.removeData('blockUI.onUnblock');
476 }
477
478 var els;
479 if (full) // crazy selector to handle odd field errors in ie6/7
480 els = $('body').children().filter('.blockUI').add('body > .blockUI');
481 else
482 els = $el.find('>.blockUI');
483
484 // fix cursor issue
485 if ( opts.cursorReset ) {
486 if ( els.length > 1 )
487 els[1].style.cursor = opts.cursorReset;
488 if ( els.length > 2 )
489 els[2].style.cursor = opts.cursorReset;
490 }
491
492 if (full)
493 pageBlock = pageBlockEls = null;
494
495 if (opts.fadeOut) {
496 count = els.length;
497 els.stop().fadeOut(opts.fadeOut, function() {
498 if ( --count === 0)
499 reset(els,data,opts,el);
500 });
501 }
502 else
503 reset(els, data, opts, el);
504 }
505
506 // move blocking element back into the DOM where it started
507 function reset(els,data,opts,el) {
508 var $el = $(el);
509 if ( $el.data('blockUI.isBlocked') )
510 return;
511
512 els.each(function(i,o) {
513 // remove via DOM calls so we don't lose event handlers
514 if (this.parentNode)
515 this.parentNode.removeChild(this);
516 });
517
518 if (data && data.el) {
519 data.el.style.display = data.display;
520 data.el.style.position = data.position;
521 data.el.style.cursor = 'default'; // #59
522 if (data.parent)
523 data.parent.appendChild(data.el);
524 $el.removeData('blockUI.history');
525 }
526
527 if ($el.data('blockUI.static')) {
528 $el.css('position', 'static'); // #22
529 }
530
531 if (typeof opts.onUnblock == 'function')
532 opts.onUnblock(el,opts);
533
534 // fix issue in Safari 6 where block artifacts remain until reflow
535 var body = $(document.body), w = body.width(), cssW = body[0].style.width;
536 body.width(w-1).width(w);
537 body[0].style.width = cssW;
538 }
539
540 // bind/unbind the handler
541 function bind(b, el, opts) {
542 var full = el == window, $el = $(el);
543
544 // don't bother unbinding if there is nothing to unbind
545 if (!b && (full && !pageBlock || !full && !$el.data('blockUI.isBlocked')))
546 return;
547
548 $el.data('blockUI.isBlocked', b);
549
550 // don't bind events when overlay is not in use or if bindEvents is false
551 if (!full || !opts.bindEvents || (b && !opts.showOverlay))
552 return;
553
554 // bind anchors and inputs for mouse and key events
555 var events = 'mousedown mouseup keydown keypress keyup touchstart touchend touchmove';
556 if (b)
557 $(document).on(events, opts, handler);
558 else
559 $(document).off(events, handler);
560
561 // former impl...
562 // var $e = $('a,:input');
563 // b ? $e.bind(events, opts, handler) : $e.unbind(events, handler);
564 }
565
566 // event handler to suppress keyboard/mouse events when blocking
567 function handler(e) {
568 // allow tab navigation (conditionally)
569 if (e.type === 'keydown' && e.keyCode && e.keyCode == 9) {
570 if (pageBlock && e.data.constrainTabKey) {
571 var els = pageBlockEls;
572 var fwd = !e.shiftKey && e.target === els[els.length-1];
573 var back = e.shiftKey && e.target === els[0];
574 if (fwd || back) {
575 setTimeout(function(){focus(back);},10);
576 return false;
577 }
578 }
579 }
580 var opts = e.data;
581 var target = $(e.target);
582 if (target.hasClass('blockOverlay') && opts.onOverlayClick)
583 opts.onOverlayClick(e);
584
585 // allow events within the message content
586 if (target.parents('div.' + opts.blockMsgClass).length > 0)
587 return true;
588
589 // allow events for content that is not being blocked
590 return target.parents().children().filter('div.blockUI').length === 0;
591 }
592
593 function focus(back) {
594 if (!pageBlockEls)
595 return;
596 var e = pageBlockEls[back===true ? pageBlockEls.length-1 : 0];
597 if (e)
598 e.focus();
599 }
600
601 function center(el, x, y) {
602 var p = el.parentNode, s = el.style;
603 var l = ((p.offsetWidth - el.offsetWidth)/2) - sz(p,'borderLeftWidth');
604 var t = ((p.offsetHeight - el.offsetHeight)/2) - sz(p,'borderTopWidth');
605 if (x) s.left = l > 0 ? (l+'px') : '0';
606 if (y) s.top = t > 0 ? (t+'px') : '0';
607 }
608
609 function sz(el, p) {
610 return parseInt($.css(el,p),10)||0;
611 }
612 jQuery.migrateDeduplicateWarnings = migrateDeduplicateWarnings;
613 }
614
615
616 /*global define:true */
617 if (typeof define === 'function' && define.amd && define.amd.jQuery) {
618 define(['jquery'], setup);
619 } else {
620 setup(jQuery);
621 }
622
623 })();
624