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