[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/jquery/multiplefileupload/ -> jquery.blockUI.js (source)

   1  /*

   2   * jQuery blockUI plugin

   3   * Version 2.16 (20-MAR-2009)

   4   * @requires jQuery v1.2.3 or later

   5   *

   6   * Examples at: http://malsup.com/jquery/block/

   7   * Copyright (c) 2007-2008 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  
  17  if (/1\.(0|1|2)\.(0|1|2)/.test($.fn.jquery) || /^1.1/.test($.fn.jquery)) {
  18      alert('blockUI requires jQuery v1.2.3 or later!  You are using v' + $.fn.jquery);
  19      return;
  20  }
  21  
  22  $.fn._fadeIn = $.fn.fadeIn;
  23  
  24  // global $ methods for blocking/unblocking the entire page

  25  $.blockUI   = function(opts) { install(window, opts); };
  26  $.unblockUI = function(opts) { remove(window, opts); };
  27  
  28  // convenience method for quick growl-like notifications  (http://www.google.com/search?q=growl)

  29  $.growlUI = function(title, message, timeout) {
  30      var $m = $('<div class="growlUI"></div>');
  31      if (title) $m.append('<h1>'+title+'</h1>');
  32      if (message) $m.append('<h2>'+message+'</h2>');
  33      if (timeout == undefined) timeout = 3000;
  34      $.blockUI({
  35          message: $m, fadeIn: 700, fadeOut: 1000, centerY: false,
  36          timeout: timeout, showOverlay: false,
  37          css: $.blockUI.defaults.growlCSS
  38      });
  39  };
  40  
  41  // plugin method for blocking element content

  42  $.fn.block = function(opts) {
  43      return this.each(function() {
  44          if ($.css(this,'position') == 'static')
  45              this.style.position = 'relative';
  46          if ($.browser.msie)
  47              this.style.zoom = 1; // force 'hasLayout'

  48          install(this, opts);
  49      });
  50  };
  51  
  52  // plugin method for unblocking element content

  53  $.fn.unblock = function(opts) {
  54      return this.each(function() {
  55          remove(this, opts);
  56      });
  57  };
  58  
  59  $.blockUI.version = 2.16; // 2nd generation blocking at no extra cost!

  60  
  61  // override these in your code to change the default behavior and style

  62  $.blockUI.defaults = {
  63      // message displayed when blocking (use null for no message)

  64      message:  '<h1>Please wait...</h1>',
  65  
  66      // styles for the message when blocking; if you wish to disable

  67      // these and use an external stylesheet then do this in your code:

  68      // $.blockUI.defaults.css = {};

  69      css: {
  70          padding:        0,
  71          margin:         0,
  72          width:          '30%',
  73          top:            '40%',
  74          left:           '35%',
  75          textAlign:      'center',
  76          color:          '#000',
  77          border:         '3px solid #aaa',
  78          backgroundColor:'#fff',
  79          cursor:         'wait'
  80      },
  81  
  82      // styles for the overlay

  83      overlayCSS:  {
  84          backgroundColor: '#000',
  85          opacity:         '0.6'
  86      },
  87  
  88      // styles applied when using $.growlUI

  89      growlCSS: {
  90          width:    '350px',
  91          top:      '10px',
  92          left:     '',
  93          right:    '10px',
  94          border:   'none',
  95          padding:  '5px',
  96          opacity:  '0.6',
  97          cursor:    null,
  98          color:    '#fff',
  99          backgroundColor: '#000',
 100          '-webkit-border-radius': '10px',
 101          '-moz-border-radius':    '10px'
 102      },
 103  
 104      // z-index for the blocking overlay

 105      baseZ: 1000,
 106  
 107      // set these to true to have the message automatically centered

 108      centerX: true, // <-- only effects element blocking (page block controlled via css above)
 109      centerY: true,
 110  
 111      // allow body element to be stetched in ie6; this makes blocking look better

 112      // on "short" pages.  disable if you wish to prevent changes to the body height

 113      allowBodyStretch: true,
 114  
 115      // be default blockUI will supress tab navigation from leaving blocking content;

 116      constrainTabKey: true,
 117  
 118      // fadeIn time in millis; set to 0 to disable fadeIn on block

 119      fadeIn:  200,
 120  
 121      // fadeOut time in millis; set to 0 to disable fadeOut on unblock

 122      fadeOut:  400,
 123  
 124      // time in millis to wait before auto-unblocking; set to 0 to disable auto-unblock

 125      timeout: 0,
 126  
 127      // disable if you don't want to show the overlay

 128      showOverlay: true,
 129  
 130      // if true, focus will be placed in the first available input field when

 131      // page blocking

 132      focusInput: true,
 133  
 134      // suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity)

 135      applyPlatformOpacityRules: true,
 136  
 137      // callback method invoked when unblocking has completed; the callback is

 138      // passed the element that has been unblocked (which is the window object for page

 139      // blocks) and the options that were passed to the unblock call:

 140      //     onUnblock(element, options)

 141      onUnblock: null,
 142  
 143      // don't ask; if you really must know: http://groups.google.com/group/jquery-en/browse_thread/thread/36640a8730503595/2f6a79a77a78e493#2f6a79a77a78e493

 144      quirksmodeOffsetHack: 4
 145  };
 146  
 147  // private data and functions follow...

 148  
 149  var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent);
 150  var pageBlock = null;
 151  var pageBlockEls = [];
 152  
 153  function install(el, opts) {
 154      var full = (el == window);
 155      var msg = opts && opts.message !== undefined ? opts.message : undefined;
 156      opts = $.extend({}, $.blockUI.defaults, opts || {});
 157      opts.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, opts.overlayCSS || {});
 158      var css = $.extend({}, $.blockUI.defaults.css, opts.css || {});
 159      msg = msg === undefined ? opts.message : msg;
 160  
 161      // remove the current block (if there is one)

 162      if (full && pageBlock)
 163          remove(window, {fadeOut:0});
 164  
 165      // if an existing element is being used as the blocking content then we capture

 166      // its current place in the DOM (and current display style) so we can restore

 167      // it when we unblock

 168      if (msg && typeof msg != 'string' && (msg.parentNode || msg.jquery)) {
 169          var node = msg.jquery ? msg[0] : msg;
 170          var data = {};
 171          $(el).data('blockUI.history', data);
 172          data.el = node;
 173          data.parent = node.parentNode;
 174          data.display = node.style.display;
 175          data.position = node.style.position;
 176          if (data.parent)
 177              data.parent.removeChild(node);
 178      }
 179  
 180      var z = opts.baseZ;
 181  
 182      // blockUI uses 3 layers for blocking, for simplicity they are all used on every platform;

 183      // layer1 is the iframe layer which is used to supress bleed through of underlying content

 184      // layer2 is the overlay layer which has opacity and a wait cursor

 185      // layer3 is the message content that is displayed while blocking

 186  
 187      var lyr1 = ($.browser.msie) ? $('<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="about:blank"></iframe>')
 188                                  : $('<div class="blockUI" style="display:none"></div>');
 189      var lyr2 = $('<div class="blockUI blockOverlay" style="z-index:'+ (z++) +';display:none;cursor:wait;border:none;margin:0;padding:0;width:100%;height:100%;top:0;left:0"></div>');
 190      var lyr3 = full ? $('<div class="blockUI blockMsg blockPage" style="z-index:'+z+';display:none;position:fixed"></div>')
 191                      : $('<div class="blockUI blockMsg blockElement" style="z-index:'+z+';display:none;position:absolute"></div>');
 192  
 193      // if we have a message, style it

 194      if (msg)
 195          lyr3.css(css);
 196  
 197      // style the overlay

 198      if (!opts.applyPlatformOpacityRules || !($.browser.mozilla && /Linux/.test(navigator.platform)))
 199          lyr2.css(opts.overlayCSS);
 200      lyr2.css('position', full ? 'fixed' : 'absolute');
 201  
 202      // make iframe layer transparent in IE

 203      if ($.browser.msie)
 204          lyr1.css('opacity','0.0');
 205  
 206      $([lyr1[0],lyr2[0],lyr3[0]]).appendTo(full ? 'body' : el);
 207  
 208      // ie7 must use absolute positioning in quirks mode and to account for activex issues (when scrolling)

 209      var expr = $.browser.msie && ($.browser.version < 8 || !$.boxModel) && (!$.boxModel || $('object,embed', full ? null : el).length > 0);
 210      if (ie6 || (expr && lyr3[0].style.setExpression)) {
 211          // give body 100% height

 212          if (full && opts.allowBodyStretch && $.boxModel)
 213              $('html,body').css('height','100%');
 214  
 215          // fix ie6 issue when blocked element has a border width

 216          if ((ie6 || !$.boxModel) && !full) {
 217              var t = sz(el,'borderTopWidth'), l = sz(el,'borderLeftWidth');
 218              var fixT = t ? '(0 - '+t+')' : 0;
 219              var fixL = l ? '(0 - '+l+')' : 0;
 220          }
 221  
 222          // simulate fixed position

 223          $.each([lyr1,lyr2,lyr3], function(i,o) {
 224              var s = o[0].style;
 225              s.position = 'absolute';
 226              if (i < 2) {
 227                  full ? s.setExpression('height','Math.max(document.body.scrollHeight, document.body.offsetHeight) - (jQuery.boxModel?0:'+opts.quirksmodeOffsetHack+') + "px"')
 228                       : s.setExpression('height','this.parentNode.offsetHeight + "px"');
 229                  full ? s.setExpression('width','jQuery.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"')
 230                       : s.setExpression('width','this.parentNode.offsetWidth + "px"');
 231                  if (fixL) s.setExpression('left', fixL);
 232                  if (fixT) s.setExpression('top', fixT);
 233              }
 234              else if (opts.centerY) {
 235                  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"');
 236                  s.marginTop = 0;
 237              }
 238              else if (!opts.centerY && full) {
 239                  var top = (opts.css && opts.css.top) ? parseInt(opts.css.top) : 0;
 240                  var expression = '((document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + '+top+') + "px"';
 241                  s.setExpression('top',expression);
 242              }
 243          });
 244      }
 245  
 246      // show the message

 247      if (msg) {
 248          lyr3.append(msg);
 249          if (msg.jquery || msg.nodeType)
 250              $(msg).show();
 251      }
 252  
 253      if ($.browser.msie && opts.showOverlay)
 254          lyr1.show(); // opacity is zero

 255      if (opts.fadeIn) {
 256          if (opts.showOverlay)
 257              lyr2._fadeIn(opts.fadeIn);
 258          if (msg)
 259              lyr3.fadeIn(opts.fadeIn);
 260      }
 261      else {
 262          if (opts.showOverlay)
 263              lyr2.show();
 264          if (msg)
 265              lyr3.show();
 266      }
 267  
 268      // bind key and mouse events

 269      bind(1, el, opts);
 270  
 271      if (full) {
 272          pageBlock = lyr3[0];
 273          pageBlockEls = $(':input:enabled:visible',pageBlock);
 274          if (opts.focusInput)
 275              setTimeout(focus, 20);
 276      }
 277      else
 278          center(lyr3[0], opts.centerX, opts.centerY);
 279  
 280      if (opts.timeout) {
 281          // auto-unblock

 282          var to = setTimeout(function() {
 283              full ? $.unblockUI(opts) : $(el).unblock(opts);
 284          }, opts.timeout);
 285          $(el).data('blockUI.timeout', to);
 286      }
 287  };
 288  
 289  // remove the block

 290  function remove(el, opts) {
 291      var full = el == window;
 292      var $el = $(el);
 293      var data = $el.data('blockUI.history');
 294      var to = $el.data('blockUI.timeout');
 295      if (to) {
 296          clearTimeout(to);
 297          $el.removeData('blockUI.timeout');
 298      }
 299      opts = $.extend({}, $.blockUI.defaults, opts || {});
 300      bind(0, el, opts); // unbind events

 301      var els = full ? $('body').children().filter('.blockUI') : $('.blockUI', el);
 302  
 303      if (full)
 304          pageBlock = pageBlockEls = null;
 305  
 306      if (opts.fadeOut) {
 307          els.fadeOut(opts.fadeOut);
 308          setTimeout(function() { reset(els,data,opts,el); }, opts.fadeOut);
 309      }
 310      else
 311          reset(els, data, opts, el);
 312  };
 313  
 314  // move blocking element back into the DOM where it started

 315  function reset(els,data,opts,el) {
 316      els.each(function(i,o) {
 317          // remove via DOM calls so we don't lose event handlers

 318          if (this.parentNode)
 319              this.parentNode.removeChild(this);
 320      });
 321  
 322      if (data && data.el) {
 323          data.el.style.display = data.display;
 324          data.el.style.position = data.position;
 325          if (data.parent)
 326              data.parent.appendChild(data.el);
 327          $(data.el).removeData('blockUI.history');
 328      }
 329  
 330      if (typeof opts.onUnblock == 'function')
 331          opts.onUnblock(el,opts);
 332  };
 333  
 334  // bind/unbind the handler

 335  function bind(b, el, opts) {
 336      var full = el == window, $el = $(el);
 337  
 338      // don't bother unbinding if there is nothing to unbind

 339      if (!b && (full && !pageBlock || !full && !$el.data('blockUI.isBlocked')))
 340          return;
 341      if (!full)
 342          $el.data('blockUI.isBlocked', b);
 343  
 344      if (b && !opts.showOverlay) // don't prevent events when overlay not in use
 345          return;
 346  
 347      // bind anchors and inputs for mouse and key events

 348      var events = 'mousedown mouseup keydown keypress';
 349      b ? $(document).bind(events, opts, handler) : $(document).unbind(events, handler);
 350  
 351  // former impl...

 352  //    var $e = $('a,:input');

 353  //    b ? $e.bind(events, opts, handler) : $e.unbind(events, handler);

 354  };
 355  
 356  // event handler to suppress keyboard/mouse events when blocking

 357  function handler(e) {
 358      // allow tab navigation (conditionally)

 359      if (e.keyCode && e.keyCode == 9) {
 360          if (pageBlock && e.data.constrainTabKey) {
 361              var els = pageBlockEls;
 362              var fwd = !e.shiftKey && e.target == els[els.length-1];
 363              var back = e.shiftKey && e.target == els[0];
 364              if (fwd || back) {
 365                  setTimeout(function(){focus(back)},10);
 366                  return false;
 367              }
 368          }
 369      }
 370      // allow events within the message content

 371      if ($(e.target).parents('div.blockMsg').length > 0)
 372          return true;
 373  
 374      // allow events for content that is not being blocked

 375      return $(e.target).parents().children().filter('div.blockUI').length == 0;
 376  };
 377  
 378  function focus(back) {
 379      if (!pageBlockEls)
 380          return;
 381      var e = pageBlockEls[back===true ? pageBlockEls.length-1 : 0];
 382      if (e)
 383          e.focus();
 384  };
 385  
 386  function center(el, x, y) {
 387      var p = el.parentNode, s = el.style;
 388      var l = ((p.offsetWidth - el.offsetWidth)/2) - sz(p,'borderLeftWidth');
 389      var t = ((p.offsetHeight - el.offsetHeight)/2) - sz(p,'borderTopWidth');
 390      if (x) s.left = l > 0 ? (l+'px') : '0';
 391      if (y) s.top  = t > 0 ? (t+'px') : '0';
 392  };
 393  
 394  function sz(el, p) {
 395      return parseInt($.css(el,p))||0;
 396  };
 397  
 398  })(jQuery);


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1