| 1 | /*
|
|---|
| 2 | * jQuery blockUI plugin
|
|---|
| 3 | * Version 2.14 (18-JAN-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 | // global $ methods for blocking/unblocking the entire page
|
|---|
| 23 | $.blockUI = function(opts) { install(window, opts); };
|
|---|
| 24 | $.unblockUI = function(opts) { remove(window, opts); };
|
|---|
| 25 |
|
|---|
| 26 | // convenience method for quick growl-like notifications (http://www.google.com/search?q=growl)
|
|---|
| 27 | $.growlUI = function(title, message, timeout) {
|
|---|
| 28 | var $m = $('<div class="growlUI"></div>');
|
|---|
| 29 | if (title) $m.append('<h1>'+title+'</h1>');
|
|---|
| 30 | if (message) $m.append('<h2>'+message+'</h2>');
|
|---|
| 31 | if (timeout == undefined) timeout = 3000;
|
|---|
| 32 | $.blockUI({
|
|---|
| 33 | message: $m, fadeIn: 700, fadeOut: 1000, centerY: false,
|
|---|
| 34 | timeout: timeout, showOverlay: false,
|
|---|
| 35 | css: $.blockUI.defaults.growlCSS
|
|---|
| 36 | });
|
|---|
| 37 | };
|
|---|
| 38 |
|
|---|
| 39 | // plugin method for blocking element content
|
|---|
| 40 | $.fn.block = function(opts) {
|
|---|
| 41 | return this.each(function() {
|
|---|
| 42 | if ($.css(this,'position') == 'static')
|
|---|
| 43 | this.style.position = 'relative';
|
|---|
| 44 | if ($.browser.msie)
|
|---|
| 45 | this.style.zoom = 1; // force 'hasLayout'
|
|---|
| 46 | install(this, opts);
|
|---|
| 47 | });
|
|---|
| 48 | };
|
|---|
| 49 |
|
|---|
| 50 | // plugin method for unblocking element content
|
|---|
| 51 | $.fn.unblock = function(opts) {
|
|---|
| 52 | return this.each(function() {
|
|---|
| 53 | remove(this, opts);
|
|---|
| 54 | });
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | $.blockUI.version = 2.14; // 2nd generation blocking at no extra cost!
|
|---|
| 58 |
|
|---|
| 59 | // override these in your code to change the default behavior and style
|
|---|
| 60 | $.blockUI.defaults = {
|
|---|
| 61 | // message displayed when blocking (use null for no message)
|
|---|
| 62 | message: '<h1>Please wait...</h1>',
|
|---|
| 63 |
|
|---|
| 64 | // styles for the message when blocking; if you wish to disable
|
|---|
| 65 | // these and use an external stylesheet then do this in your code:
|
|---|
| 66 | // $.blockUI.defaults.css = {};
|
|---|
| 67 | css: {
|
|---|
| 68 | padding: 0,
|
|---|
| 69 | margin: 0,
|
|---|
| 70 | width: '30%',
|
|---|
| 71 | top: '40%',
|
|---|
| 72 | left: '35%',
|
|---|
| 73 | textAlign: 'center',
|
|---|
| 74 | color: '#000',
|
|---|
| 75 | border: '3px solid #aaa',
|
|---|
| 76 | backgroundColor:'#fff',
|
|---|
| 77 | cursor: 'wait'
|
|---|
| 78 | },
|
|---|
| 79 |
|
|---|
| 80 | // styles for the overlay
|
|---|
| 81 | overlayCSS: {
|
|---|
| 82 | backgroundColor: '#000',
|
|---|
| 83 | opacity: '0.6'
|
|---|
| 84 | },
|
|---|
| 85 |
|
|---|
| 86 | // styles applied when using $.growlUI
|
|---|
| 87 | growlCSS: {
|
|---|
| 88 | width: '350px',
|
|---|
| 89 | top: '10px',
|
|---|
| 90 | left: '',
|
|---|
| 91 | right: '10px',
|
|---|
| 92 | border: 'none',
|
|---|
| 93 | padding: '5px',
|
|---|
| 94 | opacity: '0.6',
|
|---|
| 95 | cursor: null,
|
|---|
| 96 | color: '#fff',
|
|---|
| 97 | backgroundColor: '#000',
|
|---|
| 98 | '-webkit-border-radius': '10px',
|
|---|
| 99 | '-moz-border-radius': '10px'
|
|---|
| 100 | },
|
|---|
| 101 |
|
|---|
| 102 | // z-index for the blocking overlay
|
|---|
| 103 | baseZ: 1000,
|
|---|
| 104 |
|
|---|
| 105 | // set these to true to have the message automatically centered
|
|---|
| 106 | centerX: true, // <-- only effects element blocking (page block controlled via css above)
|
|---|
| 107 | centerY: true,
|
|---|
| 108 |
|
|---|
| 109 | // allow body element to be stetched in ie6; this makes blocking look better
|
|---|
| 110 | // on "short" pages. disable if you wish to prevent changes to the body height
|
|---|
| 111 | allowBodyStretch: true,
|
|---|
| 112 |
|
|---|
| 113 | // be default blockUI will supress tab navigation from leaving blocking content;
|
|---|
| 114 | constrainTabKey: true,
|
|---|
| 115 |
|
|---|
| 116 | // fadeIn time in millis; set to 0 to disable fadeIn on block
|
|---|
| 117 | fadeIn: 200,
|
|---|
| 118 |
|
|---|
| 119 | // fadeOut time in millis; set to 0 to disable fadeOut on unblock
|
|---|
| 120 | fadeOut: 400,
|
|---|
| 121 |
|
|---|
| 122 | // time in millis to wait before auto-unblocking; set to 0 to disable auto-unblock
|
|---|
| 123 | timeout: 0,
|
|---|
| 124 |
|
|---|
| 125 | // disable if you don't want to show the overlay
|
|---|
| 126 | showOverlay: true,
|
|---|
| 127 |
|
|---|
| 128 | // if true, focus will be placed in the first available input field when
|
|---|
| 129 | // page blocking
|
|---|
| 130 | focusInput: true,
|
|---|
| 131 |
|
|---|
| 132 | // suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity)
|
|---|
| 133 | applyPlatformOpacityRules: true,
|
|---|
| 134 |
|
|---|
| 135 | // callback method invoked when unblocking has completed; the callback is
|
|---|
| 136 | // passed the element that has been unblocked (which is the window object for page
|
|---|
| 137 | // blocks) and the options that were passed to the unblock call:
|
|---|
| 138 | // onUnblock(element, options)
|
|---|
| 139 | onUnblock: null,
|
|---|
| 140 |
|
|---|
| 141 | // don't ask; if you really must know: http://groups.google.com/group/jquery-en/browse_thread/thread/36640a8730503595/2f6a79a77a78e493#2f6a79a77a78e493
|
|---|
| 142 | quirksmodeOffsetHack: 4
|
|---|
| 143 | };
|
|---|
| 144 |
|
|---|
| 145 | // private data and functions follow...
|
|---|
| 146 |
|
|---|
| 147 | var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent);
|
|---|
| 148 | var pageBlock = null;
|
|---|
| 149 | var pageBlockEls = [];
|
|---|
| 150 |
|
|---|
| 151 | function install(el, opts) {
|
|---|
| 152 | var full = (el == window);
|
|---|
| 153 | var msg = opts && opts.message !== undefined ? opts.message : undefined;
|
|---|
| 154 | opts = $.extend({}, $.blockUI.defaults, opts || {});
|
|---|
| 155 | opts.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, opts.overlayCSS || {});
|
|---|
| 156 | var css = $.extend({}, $.blockUI.defaults.css, opts.css || {});
|
|---|
| 157 | msg = msg === undefined ? opts.message : msg;
|
|---|
| 158 |
|
|---|
| 159 | // remove the current block (if there is one)
|
|---|
| 160 | if (full && pageBlock)
|
|---|
| 161 | remove(window, {fadeOut:0});
|
|---|
| 162 |
|
|---|
| 163 | // if an existing element is being used as the blocking content then we capture
|
|---|
| 164 | // its current place in the DOM (and current display style) so we can restore
|
|---|
| 165 | // it when we unblock
|
|---|
| 166 | if (msg && typeof msg != 'string' && (msg.parentNode || msg.jquery)) {
|
|---|
| 167 | var node = msg.jquery ? msg[0] : msg;
|
|---|
| 168 | var data = {};
|
|---|
| 169 | $(el).data('blockUI.history', data);
|
|---|
| 170 | data.el = node;
|
|---|
| 171 | data.parent = node.parentNode;
|
|---|
| 172 | data.display = node.style.display;
|
|---|
| 173 | data.position = node.style.position;
|
|---|
| 174 | if (data.parent)
|
|---|
| 175 | data.parent.removeChild(node);
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | var z = opts.baseZ;
|
|---|
| 179 |
|
|---|
| 180 | // blockUI uses 3 layers for blocking, for simplicity they are all used on every platform;
|
|---|
| 181 | // layer1 is the iframe layer which is used to supress bleed through of underlying content
|
|---|
| 182 | // layer2 is the overlay layer which has opacity and a wait cursor
|
|---|
| 183 | // layer3 is the message content that is displayed while blocking
|
|---|
| 184 |
|
|---|
| 185 | 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="javascript:false;"></iframe>')
|
|---|
| 186 | : $('<div class="blockUI" style="display:none"></div>');
|
|---|
| 187 | 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>');
|
|---|
| 188 | var lyr3 = full ? $('<div class="blockUI blockMsg blockPage" style="z-index:'+z+';display:none;position:fixed"></div>')
|
|---|
| 189 | : $('<div class="blockUI blockMsg blockElement" style="z-index:'+z+';display:none;position:absolute"></div>');
|
|---|
| 190 |
|
|---|
| 191 | // if we have a message, style it
|
|---|
| 192 | if (msg)
|
|---|
| 193 | lyr3.css(css);
|
|---|
| 194 |
|
|---|
| 195 | // style the overlay
|
|---|
| 196 | if (!opts.applyPlatformOpacityRules || !($.browser.mozilla && /Linux/.test(navigator.platform)))
|
|---|
| 197 | lyr2.css(opts.overlayCSS);
|
|---|
| 198 | lyr2.css('position', full ? 'fixed' : 'absolute');
|
|---|
| 199 |
|
|---|
| 200 | // make iframe layer transparent in IE
|
|---|
| 201 | if ($.browser.msie)
|
|---|
| 202 | lyr1.css('opacity','0.0');
|
|---|
| 203 |
|
|---|
| 204 | $([lyr1[0],lyr2[0],lyr3[0]]).appendTo(full ? 'body' : el);
|
|---|
| 205 |
|
|---|
| 206 | // ie7 must use absolute positioning in quirks mode and to account for activex issues (when scrolling)
|
|---|
| 207 | var expr = $.browser.msie && (!$.boxModel || $('object,embed', full ? null : el).length > 0);
|
|---|
| 208 | if (ie6 || expr) {
|
|---|
| 209 | // give body 100% height
|
|---|
| 210 | if (full && opts.allowBodyStretch && $.boxModel)
|
|---|
| 211 | $('html,body').css('height','100%');
|
|---|
| 212 |
|
|---|
| 213 | // fix ie6 issue when blocked element has a border width
|
|---|
| 214 | if ((ie6 || !$.boxModel) && !full) {
|
|---|
| 215 | var t = sz(el,'borderTopWidth'), l = sz(el,'borderLeftWidth');
|
|---|
| 216 | var fixT = t ? '(0 - '+t+')' : 0;
|
|---|
| 217 | var fixL = l ? '(0 - '+l+')' : 0;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | // simulate fixed position
|
|---|
| 221 | $.each([lyr1,lyr2,lyr3], function(i,o) {
|
|---|
| 222 | var s = o[0].style;
|
|---|
| 223 | s.position = 'absolute';
|
|---|
| 224 | if (i < 2) {
|
|---|
| 225 | full ? s.setExpression('height','Math.max(document.body.scrollHeight, document.body.offsetHeight) - (jQuery.boxModel?0:'+opts.quirksmodeOffsetHack+') + "px"')
|
|---|
| 226 | : s.setExpression('height','this.parentNode.offsetHeight + "px"');
|
|---|
| 227 | full ? s.setExpression('width','jQuery.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"')
|
|---|
| 228 | : s.setExpression('width','this.parentNode.offsetWidth + "px"');
|
|---|
| 229 | if (fixL) s.setExpression('left', fixL);
|
|---|
| 230 | if (fixT) s.setExpression('top', fixT);
|
|---|
| 231 | }
|
|---|
| 232 | else if (opts.centerY) {
|
|---|
| 233 | 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"');
|
|---|
| 234 | s.marginTop = 0;
|
|---|
| 235 | }
|
|---|
| 236 | else if (!opts.centerY && full) {
|
|---|
| 237 | var top = (opts.css && opts.css.top) ? parseInt(opts.css.top) : 0;
|
|---|
| 238 | var expression = '((document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + '+top+') + "px"';
|
|---|
| 239 | s.setExpression('top',expression);
|
|---|
| 240 | }
|
|---|
| 241 | });
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | // show the message
|
|---|
| 245 | lyr3.append(msg);//.show();
|
|---|
| 246 | if (msg && (msg.jquery || msg.nodeType))
|
|---|
| 247 | $(msg).show();
|
|---|
| 248 |
|
|---|
| 249 | if (opts.fadeIn) {
|
|---|
| 250 | if ($.browser.msie && opts.showOverlay)
|
|---|
| 251 | lyr1.fadeIn(opts.fadeIn);
|
|---|
| 252 | if (opts.showOverlay)
|
|---|
| 253 | lyr2.fadeIn(opts.fadeIn);
|
|---|
| 254 | lyr3.fadeIn(opts.fadeIn);
|
|---|
| 255 | }
|
|---|
| 256 | else {
|
|---|
| 257 | if ($.browser.msie && opts.showOverlay)
|
|---|
| 258 | lyr1.show();
|
|---|
| 259 | if (opts.showOverlay)
|
|---|
| 260 | lyr2.show();
|
|---|
| 261 | lyr3.show();
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | // bind key and mouse events
|
|---|
| 265 | bind(1, el, opts);
|
|---|
| 266 |
|
|---|
| 267 | if (full) {
|
|---|
| 268 | pageBlock = lyr3[0];
|
|---|
| 269 | pageBlockEls = $(':input:enabled:visible',pageBlock);
|
|---|
| 270 | if (opts.focusInput)
|
|---|
| 271 | setTimeout(focus, 20);
|
|---|
| 272 | }
|
|---|
| 273 | else
|
|---|
| 274 | center(lyr3[0], opts.centerX, opts.centerY);
|
|---|
| 275 |
|
|---|
| 276 | if (opts.timeout) {
|
|---|
| 277 | // auto-unblock
|
|---|
| 278 | setTimeout(function() {
|
|---|
| 279 | full ? $.unblockUI(opts) : $(el).unblock(opts);
|
|---|
| 280 | }, opts.timeout);
|
|---|
| 281 | }
|
|---|
| 282 | };
|
|---|
| 283 |
|
|---|
| 284 | // remove the block
|
|---|
| 285 | function remove(el, opts) {
|
|---|
| 286 | var full = el == window;
|
|---|
| 287 | var data = $(el).data('blockUI.history');
|
|---|
| 288 | opts = $.extend({}, $.blockUI.defaults, opts || {});
|
|---|
| 289 | bind(0, el, opts); // unbind events
|
|---|
| 290 | var els = full ? $('body').children().filter('.blockUI') : $('.blockUI', el);
|
|---|
| 291 |
|
|---|
| 292 | if (full)
|
|---|
| 293 | pageBlock = pageBlockEls = null;
|
|---|
| 294 |
|
|---|
| 295 | if (opts.fadeOut) {
|
|---|
| 296 | els.fadeOut(opts.fadeOut);
|
|---|
| 297 | setTimeout(function() { reset(els,data,opts,el); }, opts.fadeOut);
|
|---|
| 298 | }
|
|---|
| 299 | else
|
|---|
| 300 | reset(els, data, opts, el);
|
|---|
| 301 | };
|
|---|
| 302 |
|
|---|
| 303 | // move blocking element back into the DOM where it started
|
|---|
| 304 | function reset(els,data,opts,el) {
|
|---|
| 305 | els.each(function(i,o) {
|
|---|
| 306 | // remove via DOM calls so we don't lose event handlers
|
|---|
| 307 | if (this.parentNode)
|
|---|
| 308 | this.parentNode.removeChild(this);
|
|---|
| 309 | });
|
|---|
| 310 |
|
|---|
| 311 | if (data && data.el) {
|
|---|
| 312 | data.el.style.display = data.display;
|
|---|
| 313 | data.el.style.position = data.position;
|
|---|
| 314 | if (data.parent)
|
|---|
| 315 | data.parent.appendChild(data.el);
|
|---|
| 316 | $(data.el).removeData('blockUI.history');
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | if (typeof opts.onUnblock == 'function')
|
|---|
| 320 | opts.onUnblock(el,opts);
|
|---|
| 321 | };
|
|---|
| 322 |
|
|---|
| 323 | // bind/unbind the handler
|
|---|
| 324 | function bind(b, el, opts) {
|
|---|
| 325 | var full = el == window, $el = $(el);
|
|---|
| 326 |
|
|---|
| 327 | // don't bother unbinding if there is nothing to unbind
|
|---|
| 328 | if (!b && (full && !pageBlock || !full && !$el.data('blockUI.isBlocked')))
|
|---|
| 329 | return;
|
|---|
| 330 | if (!full)
|
|---|
| 331 | $el.data('blockUI.isBlocked', b);
|
|---|
| 332 |
|
|---|
| 333 | if (b && !opts.showOverlay) // don't prevent events when overlay not in use
|
|---|
| 334 | return;
|
|---|
| 335 |
|
|---|
| 336 | // bind anchors and inputs for mouse and key events
|
|---|
| 337 | var events = 'mousedown mouseup keydown keypress';
|
|---|
| 338 | b ? $(document).bind(events, opts, handler) : $(document).unbind(events, handler);
|
|---|
| 339 |
|
|---|
| 340 | // former impl...
|
|---|
| 341 | // var $e = $('a,:input');
|
|---|
| 342 | // b ? $e.bind(events, opts, handler) : $e.unbind(events, handler);
|
|---|
| 343 | };
|
|---|
| 344 |
|
|---|
| 345 | // event handler to suppress keyboard/mouse events when blocking
|
|---|
| 346 | function handler(e) {
|
|---|
| 347 | // allow tab navigation (conditionally)
|
|---|
| 348 | if (e.keyCode && e.keyCode == 9) {
|
|---|
| 349 | if (pageBlock && e.data.constrainTabKey) {
|
|---|
| 350 | var els = pageBlockEls;
|
|---|
| 351 | var fwd = !e.shiftKey && e.target == els[els.length-1];
|
|---|
| 352 | var back = e.shiftKey && e.target == els[0];
|
|---|
| 353 | if (fwd || back) {
|
|---|
| 354 | setTimeout(function(){focus(back)},10);
|
|---|
| 355 | return false;
|
|---|
| 356 | }
|
|---|
| 357 | }
|
|---|
| 358 | }
|
|---|
| 359 | // allow events within the message content
|
|---|
| 360 | if ($(e.target).parents('div.blockMsg').length > 0)
|
|---|
| 361 | return true;
|
|---|
| 362 |
|
|---|
| 363 | // allow events for content that is not being blocked
|
|---|
| 364 | return $(e.target).parents().children().filter('div.blockUI').length == 0;
|
|---|
| 365 | };
|
|---|
| 366 |
|
|---|
| 367 | function focus(back) {
|
|---|
| 368 | if (!pageBlockEls)
|
|---|
| 369 | return;
|
|---|
| 370 | var e = pageBlockEls[back===true ? pageBlockEls.length-1 : 0];
|
|---|
| 371 | if (e)
|
|---|
| 372 | e.focus();
|
|---|
| 373 | };
|
|---|
| 374 |
|
|---|
| 375 | function center(el, x, y) {
|
|---|
| 376 | var p = el.parentNode, s = el.style;
|
|---|
| 377 | var l = ((p.offsetWidth - el.offsetWidth)/2) - sz(p,'borderLeftWidth');
|
|---|
| 378 | var t = ((p.offsetHeight - el.offsetHeight)/2) - sz(p,'borderTopWidth');
|
|---|
| 379 | if (x) s.left = l > 0 ? (l+'px') : '0';
|
|---|
| 380 | if (y) s.top = t > 0 ? (t+'px') : '0';
|
|---|
| 381 | };
|
|---|
| 382 |
|
|---|
| 383 | function sz(el, p) {
|
|---|
| 384 | return parseInt($.css(el,p))||0;
|
|---|
| 385 | };
|
|---|
| 386 |
|
|---|
| 387 | })(jQuery);
|
|---|