PageSourceSearch

https://coursesity.com/assets/js/jquery.blockUI.js

js coursesity.com collected 2026-10-02 04:09:36 UTC 23,927 bytes, 676 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.