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