Path: blob/master/core/main/client/lib/jquery.blockUI.js
1154 views
/*!1* jQuery blockUI plugin2* Version 2.70.0-2014.11.233* Requires jQuery v1.7 or later4*5* Examples at: http://malsup.com/jquery/block/6* Copyright (c) 2007-2013 M. Alsup7* Dual licensed under the MIT and GPL licenses:8* http://www.opensource.org/licenses/mit-license.php9* http://www.gnu.org/licenses/gpl.html10*11* Thanks to Amir-Hossein Sobhi for some excellent contributions!12*/1314;(function() {15/*jshint eqeqeq:false curly:false latedef:false */16"use strict";1718function setup($) {19$.fn._fadeIn = $.fn.fadeIn;2021var noOp = $.noop || function() {};2223// this bit is to ensure we don't call setExpression when we shouldn't (with extra muscle to handle24// confusing userAgent strings on Vista)25var msie = /MSIE/.test(navigator.userAgent);26var ie6 = /MSIE 6.0/.test(navigator.userAgent) && ! /MSIE 8.0/.test(navigator.userAgent);27var mode = document.documentMode || 0;28var setExpr = $.isFunction( document.createElement('div').style.setExpression );2930// global $ methods for blocking/unblocking the entire page31$.blockUI = function(opts) { install(window, opts); };32$.unblockUI = function(opts) { remove(window, opts); };3334// convenience method for quick growl-like notifications (http://www.google.com/search?q=growl)35$.growlUI = function(title, message, timeout, onClose) {36var $m = $('<div class="growlUI"></div>');37if (title) $m.append('<h1>'+title+'</h1>');38if (message) $m.append('<h2>'+message+'</h2>');39if (timeout === undefined) timeout = 3000;4041// Added by konapun: Set timeout to 30 seconds if this growl is moused over, like normal toast notifications42var callBlock = function(opts) {43opts = opts || {};4445$.blockUI({46message: $m,47fadeIn : typeof opts.fadeIn !== 'undefined' ? opts.fadeIn : 700,48fadeOut: typeof opts.fadeOut !== 'undefined' ? opts.fadeOut : 1000,49timeout: typeof opts.timeout !== 'undefined' ? opts.timeout : timeout,50centerY: false,51showOverlay: false,52onUnblock: onClose,53css: $.blockUI.defaults.growlCSS54});55};5657callBlock();58var nonmousedOpacity = $m.css('opacity');59$m.mouseover(function() {60callBlock({61fadeIn: 0,62timeout: 3000063});6465var displayBlock = $('.blockMsg');66displayBlock.stop(); // cancel fadeout if it has started67displayBlock.fadeTo(300, 1); // make it easier to read the message by removing transparency68}).mouseout(function() {69$('.blockMsg').fadeOut(1000);70});71// End konapun additions72};7374// plugin method for blocking element content75$.fn.block = function(opts) {76if ( this[0] === window ) {77$.blockUI( opts );78return this;79}80var fullOpts = $.extend({}, $.blockUI.defaults, opts || {});81this.each(function() {82var $el = $(this);83if (fullOpts.ignoreIfBlocked && $el.data('blockUI.isBlocked'))84return;85$el.unblock({ fadeOut: 0 });86});8788return this.each(function() {89if ($.css(this,'position') == 'static') {90this.style.position = 'relative';91$(this).data('blockUI.static', true);92}93this.style.zoom = 1; // force 'hasLayout' in ie94install(this, opts);95});96};9798// plugin method for unblocking element content99$.fn.unblock = function(opts) {100if ( this[0] === window ) {101$.unblockUI( opts );102return this;103}104return this.each(function() {105remove(this, opts);106});107};108109$.blockUI.version = 2.70; // 2nd generation blocking at no extra cost!110111// override these in your code to change the default behavior and style112$.blockUI.defaults = {113// message displayed when blocking (use null for no message)114message: '<h1>Please wait...</h1>',115116title: null, // title string; only used when theme == true117draggable: true, // only used when theme == true (requires jquery-ui.js to be loaded)118119theme: false, // set to true to use with jQuery UI themes120121// styles for the message when blocking; if you wish to disable122// these and use an external stylesheet then do this in your code:123// $.blockUI.defaults.css = {};124css: {125padding: 0,126margin: 0,127width: '30%',128top: '40%',129left: '35%',130textAlign: 'center',131color: '#000',132border: '3px solid #aaa',133backgroundColor:'#fff',134cursor: 'wait'135},136137// minimal style set used when themes are used138themedCSS: {139width: '30%',140top: '40%',141left: '35%'142},143144// styles for the overlay145overlayCSS: {146backgroundColor: '#000',147opacity: 0.6,148cursor: 'wait'149},150151// style to replace wait cursor before unblocking to correct issue152// of lingering wait cursor153cursorReset: 'default',154155// styles applied when using $.growlUI156growlCSS: {157width: '350px',158top: '10px',159left: '',160right: '10px',161border: 'none',162padding: '5px',163opacity: 0.6,164cursor: 'default',165color: '#fff',166backgroundColor: '#000',167'-webkit-border-radius':'10px',168'-moz-border-radius': '10px',169'border-radius': '10px'170},171172// IE issues: 'about:blank' fails on HTTPS and javascript:false is s-l-o-w173// (hat tip to Jorge H. N. de Vasconcelos)174/*jshint scripturl:true */175iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank',176177// force usage of iframe in non-IE browsers (handy for blocking applets)178forceIframe: false,179180// z-index for the blocking overlay181baseZ: 1000,182183// set these to true to have the message automatically centered184centerX: true, // <-- only effects element blocking (page block controlled via css above)185centerY: true,186187// allow body element to be stetched in ie6; this makes blocking look better188// on "short" pages. disable if you wish to prevent changes to the body height189allowBodyStretch: true,190191// enable if you want key and mouse events to be disabled for content that is blocked192bindEvents: true,193194// be default blockUI will supress tab navigation from leaving blocking content195// (if bindEvents is true)196constrainTabKey: true,197198// fadeIn time in millis; set to 0 to disable fadeIn on block199fadeIn: 200,200201// fadeOut time in millis; set to 0 to disable fadeOut on unblock202fadeOut: 400,203204// time in millis to wait before auto-unblocking; set to 0 to disable auto-unblock205timeout: 0,206207// disable if you don't want to show the overlay208showOverlay: true,209210// if true, focus will be placed in the first available input field when211// page blocking212focusInput: true,213214// elements that can receive focus215focusableElements: ':input:enabled:visible',216217// suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity)218// no longer needed in 2012219// applyPlatformOpacityRules: true,220221// callback method invoked when fadeIn has completed and blocking message is visible222onBlock: null,223224// callback method invoked when unblocking has completed; the callback is225// passed the element that has been unblocked (which is the window object for page226// blocks) and the options that were passed to the unblock call:227// onUnblock(element, options)228onUnblock: null,229230// callback method invoked when the overlay area is clicked.231// setting this will turn the cursor to a pointer, otherwise cursor defined in overlayCss will be used.232onOverlayClick: null,233234// don't ask; if you really must know: http://groups.google.com/group/jquery-en/browse_thread/thread/36640a8730503595/2f6a79a77a78e493#2f6a79a77a78e493235quirksmodeOffsetHack: 4,236237// class name of the message block238blockMsgClass: 'blockMsg',239240// if it is already blocked, then ignore it (don't unblock and reblock)241ignoreIfBlocked: false242};243244// private data and functions follow...245246var pageBlock = null;247var pageBlockEls = [];248249function install(el, opts) {250var css, themedCSS;251var full = (el == window);252var msg = (opts && opts.message !== undefined ? opts.message : undefined);253opts = $.extend({}, $.blockUI.defaults, opts || {});254255if (opts.ignoreIfBlocked && $(el).data('blockUI.isBlocked'))256return;257258opts.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, opts.overlayCSS || {});259css = $.extend({}, $.blockUI.defaults.css, opts.css || {});260if (opts.onOverlayClick)261opts.overlayCSS.cursor = 'pointer';262263themedCSS = $.extend({}, $.blockUI.defaults.themedCSS, opts.themedCSS || {});264msg = msg === undefined ? opts.message : msg;265266// remove the current block (if there is one)267if (full && pageBlock)268remove(window, {fadeOut:0});269270// if an existing element is being used as the blocking content then we capture271// its current place in the DOM (and current display style) so we can restore272// it when we unblock273if (msg && typeof msg != 'string' && (msg.parentNode || msg.jquery)) {274var node = msg.jquery ? msg[0] : msg;275var data = {};276$(el).data('blockUI.history', data);277data.el = node;278data.parent = node.parentNode;279data.display = node.style.display;280data.position = node.style.position;281if (data.parent)282data.parent.removeChild(node);283}284285$(el).data('blockUI.onUnblock', opts.onUnblock);286var z = opts.baseZ;287288// blockUI uses 3 layers for blocking, for simplicity they are all used on every platform;289// layer1 is the iframe layer which is used to supress bleed through of underlying content290// layer2 is the overlay layer which has opacity and a wait cursor (by default)291// layer3 is the message content that is displayed while blocking292var lyr1, lyr2, lyr3, s;293if (msie || opts.forceIframe)294lyr1 = $('<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>');295else296lyr1 = $('<div class="blockUI" style="display:none"></div>');297298if (opts.theme)299lyr2 = $('<div class="blockUI blockOverlay ui-widget-overlay" style="z-index:'+ (z++) +';display:none"></div>');300else301lyr2 = $('<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>');302303if (opts.theme && full) {304s = '<div class="blockUI ' + opts.blockMsgClass + ' blockPage ui-dialog ui-widget ui-corner-all" style="z-index:'+(z+10)+';display:none;position:fixed">';305if ( opts.title ) {306s += '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || ' ')+'</div>';307}308s += '<div class="ui-widget-content ui-dialog-content"></div>';309s += '</div>';310}311else if (opts.theme) {312s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement ui-dialog ui-widget ui-corner-all" style="z-index:'+(z+10)+';display:none;position:absolute">';313if ( opts.title ) {314s += '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || ' ')+'</div>';315}316s += '<div class="ui-widget-content ui-dialog-content"></div>';317s += '</div>';318}319else if (full) {320s = '<div class="blockUI ' + opts.blockMsgClass + ' blockPage" style="z-index:'+(z+10)+';display:none;position:fixed"></div>';321}322else {323s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement" style="z-index:'+(z+10)+';display:none;position:absolute"></div>';324}325lyr3 = $(s);326327// if we have a message, style it328if (msg) {329if (opts.theme) {330lyr3.css(themedCSS);331lyr3.addClass('ui-widget-content');332}333else334lyr3.css(css);335}336337// style the overlay338if (!opts.theme /*&& (!opts.applyPlatformOpacityRules)*/)339lyr2.css(opts.overlayCSS);340lyr2.css('position', full ? 'fixed' : 'absolute');341342// make iframe layer transparent in IE343if (msie || opts.forceIframe)344lyr1.css('opacity',0.0);345346//$([lyr1[0],lyr2[0],lyr3[0]]).appendTo(full ? 'body' : el);347var layers = [lyr1,lyr2,lyr3], $par = full ? $('body') : $(el);348$.each(layers, function() {349this.appendTo($par);350});351352if (opts.theme && opts.draggable && $.fn.draggable) {353lyr3.draggable({354handle: '.ui-dialog-titlebar',355cancel: 'li'356});357}358359// ie7 must use absolute positioning in quirks mode and to account for activex issues (when scrolling)360var expr = setExpr && (!$.support.boxModel || $('object,embed', full ? null : el).length > 0);361if (ie6 || expr) {362// give body 100% height363if (full && opts.allowBodyStretch && $.support.boxModel)364$('html,body').css('height','100%');365366// fix ie6 issue when blocked element has a border width367if ((ie6 || !$.support.boxModel) && !full) {368var t = sz(el,'borderTopWidth'), l = sz(el,'borderLeftWidth');369var fixT = t ? '(0 - '+t+')' : 0;370var fixL = l ? '(0 - '+l+')' : 0;371}372373// simulate fixed position374$.each(layers, function(i,o) {375var s = o[0].style;376s.position = 'absolute';377if (i < 2) {378if (full)379s.setExpression('height','Math.max(document.body.scrollHeight, document.body.offsetHeight) - (jQuery.support.boxModel?0:'+opts.quirksmodeOffsetHack+') + "px"');380else381s.setExpression('height','this.parentNode.offsetHeight + "px"');382if (full)383s.setExpression('width','jQuery.support.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"');384else385s.setExpression('width','this.parentNode.offsetWidth + "px"');386if (fixL) s.setExpression('left', fixL);387if (fixT) s.setExpression('top', fixT);388}389else if (opts.centerY) {390if (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"');391s.marginTop = 0;392}393else if (!opts.centerY && full) {394var top = (opts.css && opts.css.top) ? parseInt(opts.css.top, 10) : 0;395var expression = '((document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + '+top+') + "px"';396s.setExpression('top',expression);397}398});399}400401// show the message402if (msg) {403if (opts.theme)404lyr3.find('.ui-widget-content').append(msg);405else406lyr3.append(msg);407if (msg.jquery || msg.nodeType)408$(msg).show();409}410411if ((msie || opts.forceIframe) && opts.showOverlay)412lyr1.show(); // opacity is zero413if (opts.fadeIn) {414var cb = opts.onBlock ? opts.onBlock : noOp;415var cb1 = (opts.showOverlay && !msg) ? cb : noOp;416var cb2 = msg ? cb : noOp;417if (opts.showOverlay)418lyr2._fadeIn(opts.fadeIn, cb1);419if (msg)420lyr3._fadeIn(opts.fadeIn, cb2);421}422else {423if (opts.showOverlay)424lyr2.show();425if (msg)426lyr3.show();427if (opts.onBlock)428opts.onBlock.bind(lyr3)();429}430431// bind key and mouse events432bind(1, el, opts);433434if (full) {435pageBlock = lyr3[0];436pageBlockEls = $(opts.focusableElements,pageBlock);437if (opts.focusInput)438setTimeout(focus, 20);439}440else441center(lyr3[0], opts.centerX, opts.centerY);442443if (opts.timeout) {444// auto-unblock445var to = setTimeout(function() {446if (full)447$.unblockUI(opts);448else449$(el).unblock(opts);450}, opts.timeout);451$(el).data('blockUI.timeout', to);452}453}454455// remove the block456function remove(el, opts) {457var count;458var full = (el == window);459var $el = $(el);460var data = $el.data('blockUI.history');461var to = $el.data('blockUI.timeout');462if (to) {463clearTimeout(to);464$el.removeData('blockUI.timeout');465}466opts = $.extend({}, $.blockUI.defaults, opts || {});467bind(0, el, opts); // unbind events468469if (opts.onUnblock === null) {470opts.onUnblock = $el.data('blockUI.onUnblock');471$el.removeData('blockUI.onUnblock');472}473474var els;475if (full) // crazy selector to handle odd field errors in ie6/7476els = $('body').children().filter('.blockUI').add('body > .blockUI');477else478els = $el.find('>.blockUI');479480// fix cursor issue481if ( opts.cursorReset ) {482if ( els.length > 1 )483els[1].style.cursor = opts.cursorReset;484if ( els.length > 2 )485els[2].style.cursor = opts.cursorReset;486}487488if (full)489pageBlock = pageBlockEls = null;490491if (opts.fadeOut) {492count = els.length;493els.stop().fadeOut(opts.fadeOut, function() {494if ( --count === 0)495reset(els,data,opts,el);496});497}498else499reset(els, data, opts, el);500}501502// move blocking element back into the DOM where it started503function reset(els,data,opts,el) {504var $el = $(el);505if ( $el.data('blockUI.isBlocked') )506return;507508els.each(function(i,o) {509// remove via DOM calls so we don't lose event handlers510if (this.parentNode)511this.parentNode.removeChild(this);512});513514if (data && data.el) {515data.el.style.display = data.display;516data.el.style.position = data.position;517data.el.style.cursor = 'default'; // #59518if (data.parent)519data.parent.appendChild(data.el);520$el.removeData('blockUI.history');521}522523if ($el.data('blockUI.static')) {524$el.css('position', 'static'); // #22525}526527if (typeof opts.onUnblock == 'function')528opts.onUnblock(el,opts);529530// fix issue in Safari 6 where block artifacts remain until reflow531var body = $(document.body), w = body.width(), cssW = body[0].style.width;532body.width(w-1).width(w);533body[0].style.width = cssW;534}535536// bind/unbind the handler537function bind(b, el, opts) {538var full = el == window, $el = $(el);539540// don't bother unbinding if there is nothing to unbind541if (!b && (full && !pageBlock || !full && !$el.data('blockUI.isBlocked')))542return;543544$el.data('blockUI.isBlocked', b);545546// don't bind events when overlay is not in use or if bindEvents is false547if (!full || !opts.bindEvents || (b && !opts.showOverlay))548return;549550// bind anchors and inputs for mouse and key events551var events = 'mousedown mouseup keydown keypress keyup touchstart touchend touchmove';552if (b)553$(document).bind(events, opts, handler);554else555$(document).unbind(events, handler);556557// former impl...558// var $e = $('a,:input');559// b ? $e.bind(events, opts, handler) : $e.unbind(events, handler);560}561562// event handler to suppress keyboard/mouse events when blocking563function handler(e) {564// allow tab navigation (conditionally)565if (e.type === 'keydown' && e.keyCode && e.keyCode == 9) {566if (pageBlock && e.data.constrainTabKey) {567var els = pageBlockEls;568var fwd = !e.shiftKey && e.target === els[els.length-1];569var back = e.shiftKey && e.target === els[0];570if (fwd || back) {571setTimeout(function(){focus(back);},10);572return false;573}574}575}576var opts = e.data;577var target = $(e.target);578if (target.hasClass('blockOverlay') && opts.onOverlayClick)579opts.onOverlayClick(e);580581// allow events within the message content582if (target.parents('div.' + opts.blockMsgClass).length > 0)583return true;584585// allow events for content that is not being blocked586return target.parents().children().filter('div.blockUI').length === 0;587}588589function focus(back) {590if (!pageBlockEls)591return;592var e = pageBlockEls[back===true ? pageBlockEls.length-1 : 0];593if (e)594e.focus();595}596597function center(el, x, y) {598var p = el.parentNode, s = el.style;599var l = ((p.offsetWidth - el.offsetWidth)/2) - sz(p,'borderLeftWidth');600var t = ((p.offsetHeight - el.offsetHeight)/2) - sz(p,'borderTopWidth');601if (x) s.left = l > 0 ? (l+'px') : '0';602if (y) s.top = t > 0 ? (t+'px') : '0';603}604605function sz(el, p) {606return parseInt($.css(el,p),10)||0;607}608609}610611612/*global define:true */613if (typeof define === 'function' && define.amd && define.amd.jQuery) {614define(['jquery'], setup);615} else {616setup(jQuery);617}618619})();620621622