Jquery blockui. js

Source: Internet
Author: User

/*
* Jquery blockui plugin
* Version 2.16 (20-Mar-2009)
* @ Requires jquery v1.2.3 or later
*
* Examples at: http://malsup.com/jquery/block/
* Copyright (c) 2007-2008 M. alsup
* Dual licensed under the MIT and GPL licenses:
* Http://www.opensource.org/licenses/mit-license.php
* Http://www.gnu.org/licenses/gpl.html
*
* Thanks to Amir-Hossein Sobhi for some excellent contributions!
*/

; (Function ($ ){

If (/1 \. (0 | 1 | 2 )\. (0 | 1 | 2 )/. test ($. FN. jquery) |/^1.1 /. test ($. FN. jquery )){
Alert ('blockui requires jquery v1.2.3 or later! You are using V' + $. FN. jquery );
Return;
}

$. FN. _ fadein = $. FN. fadein;

// Global $ methods for blocking/unblocking the entire page
$. Blockui = function (OPTs) {install (window, opts );};
$. Unblockui = function (OPTs) {remove (window, opts );};

// Convenience method for quick growl-like notifications (http://www.google.com/search? Q = growl)
$. Growlui = function (title, message, timeout ){
VaR $ M = $ ('<Div class = "growlui"> </div> ');
If (title) $ M. append ('If (Message) $ M. append ('<H2>' + message + '</H2> ');
If (timeout = undefined) Timeout = 3000;
$. Blockui ({
Message: $ M, fadein: 700, fadeout: 1000, centery: false,
Timeout: timeout, showoverlay: false,
CSS: $. blockui. defaults. growlcss
});
};

// Plugin Method for blocking Element Content
$. FN. Block = function (OPTs ){
Return this. Each (function (){
If ().css (this, 'position') = 'static ')
This. style. Position = 'relative ';
If ($. browser. MSIE)
This. style. Zoom = 1; // force 'haslayout'
Install (this, opts );
});
};

// Plugin Method for unblocking Element Content
$. FN. Unblock = function (OPTs ){
Return this. Each (function (){
Remove (this, opts );
});
};

$. Blockui. Version = 2.16; // 2nd generation blocking at no extra cost!

// Override these in your code to change the default behavior and Style
$. Blockui. defaults = {
// Message displayed when blocking (use NULL for no message)
Message: '

// Styles for the message when blocking; if you wish to disable
// These and use an external stylesheet then do this in your code:
// Pai.blockui.defaults.css = {};
CSS :{
Padding: 0,
Margin: 0,
Width: '200 ',
Top: '123 ',
Left: '20140901 ',
Textalign: 'center ',
Color: '#000 ',
Border: '3px solid # aaa ',
Backgroundcolor: '# fff ',
Cursor: 'wait'
},

// Styles for the overlay
Overlaycss :{
Backgroundcolor: '#000 ',
Opacity: '0. 6'
},

// Styles applied when using $. growlui
Growlcss :{
Width: '350px ',
Top: '10px ',
Left :'',
Right: '10px ',
Border: 'none ',
Padding: '5px ',
Opacity: '0. 6 ',
Cursor: NULL,
Color: '# fff ',
Backgroundcolor: '#000 ',
'-WebKit-border-radius': '10px ',
'-Moz-border-radius': '10px'
},

// Z-index for the blocking overlay
Basez: 1000,

// Set these to true to have the message automatically centered
Centerx: True, // <-- only effects element blocking (page block controlled via CSS above)
Centery: True,

// Allow body element to be stetched in IE6; this makes blocking look better
// On "short" pages. Disable if you wish to prevent changes to the body height
Allowbodystretch: True,

// Be default blockui will supress tab navigation from leaving blocking content;
Constraintabkey: True,

// Fadein time in millis; set to 0 to disable fadein on Block
Fadein: 200,

// Fadeout time in millis; set to 0 to disable fadeout on unblock
Fadeout: 400,

// Time in millis to wait before auto-unblocking; set to 0 to disable auto-unblock
Timeout: 0,

// Disable if you don't want to show the overlay
Showoverlay: True,

// If true, focus will be placed in the first available input field when
// Page Blocking
Focusinput: True,

// Suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity)
Applyplatformopacityrules: True,

// Callback method invoked when unblocking has completed; the callback is
// Passed the element that has been unblocked (which is the window object for page
// Blocks) and the options that were passed to the Unblock call:
// Onunblock (element, options)
Onunblock: NULL,

// Don't ask; if you really must know: http://groups.google.com/group/jquery-en/browse_thread/thread/36640a8730503595/2f6a79a77a78e493#2f6a79a77a78e493
Quirksmodeoffsethack: 4
};

// Private data and functions follow...

VaR IE6 = $. browser. MSIE &/MSIE 6.0/. Test (navigator. useragent );
VaR pageblock = NULL;
VaR pageblockels = [];

Function install (El, opts ){
VaR full = (El = Window );
VaR MSG = opts & opts. message! = Undefined? Opts. Message: undefined;
Opts = $. Extend ({}, $. blockui. defaults, opts || {});
Opts. overlaycss =$. Extend ({}, $. blockui. defaults. overlaycss, opts. overlaycss || {});
VaR CSS = $. Extend ({}, developer.blockui.defaults.css, opts.css || {});
MSG = undefined? Opts. Message: MSG;

// Remove the current block (if there is one)
If (full & pageblock)
Remove (window, {fadeout: 0 });

// If an existing element is being used as the blocking content then we capture
// Its current place In the DOM (and current display style) so we can restore
// It When we unblock
If (MSG & typeof MSG! = 'String' & (msg. parentnode | msg. jquery )){
VaR node = msg. jquery? MSG [0]: MSG;
VaR data = {};
$ (EL). Data ('blockui. History ', data );
Data. El = node;
Data. Parent = node. parentnode;
Data. Display = node. style. display;
Data. Position = node. style. position;
If (data. Parent)
Data. Parent. removechild (node );
}

VaR z = opts. basez;

// Blockui uses 3 layers for blocking, for simplicity they are all used on every platform;
// Layer1 is the IFRAME layer which is used to supress bleed through of underlying content
// Layer2 is the overlay layer which has opacity and a wait cursor
// Layer3 is the message content that is displayed while blocking

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> ')
: $ ('<Div class = "blockui" style = "display: none"> </div> ');
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> ');
VaR lyr3 = full? $ ('<Div class = "blockui blockmsg blockpage" style = "Z-index:' + Z + '; display: none; position: fixed"> </div> ')
: $ ('<Div class = "blockui blockmsg blockelement" style = "Z-index:' + Z + '; display: none; position: absolute "> </div> ');

// If we have a message, style it
If (MSG)
Lyr3.css (CSS );

// Style the overlay
If (! Opts. applyplatformopacityrules |! ($. Browser. Mozilla &/Linux/. Test (navigator. Platform )))
Lyr2.css (OPTs. overlaycss );
Lyr2.css ('position', full? 'Fixed': 'absolute ');

// Make IFRAME layer transparent in IE
If ($. browser. MSIE)
Lyr1.css ('opacity ', '0. 0 ');

$([Lyr1 [0], lyr2 [0], lyr3 [0]). appendto (full? 'Body': El );

// IE7 must use absolute positioning in quirks mode and to account for ActiveX issues (when scrolling)
VaR expr = $. browser. MSIE & ($. browser. version <8 |! $. Boxmodel )&&(! $. Boxmodel | $ ('object, embed ', full? Null: El). length> 0 );
If (IE6 | (expr & lyr3 [0]. style. setexpression )){
// The give body 100% height
If (full & opts. allowbodystretch & $. boxmodel)
Watermark ('html,body'0000.css ('height', '20140901 ');

// Fix IE6 issue when blocked element has a Border Width
If (IE6 |! $. Boxmodel )&&! Full ){
VaR T = SZ (El, 'bordertopwidth '), L = SZ (El, 'borderleftwidth ');
VaR fixt = t? '(0-' + T + ')': 0;
VaR fixl = L? '(0-' + L + ')': 0;
}

// Simulate fixed position
$. Each ([lyr1, lyr2, lyr3], function (I, O ){
VaR S = O [0]. style;
S. Position = 'absolute ';
If (I <2 ){
Full? S. setexpression ('height', 'math. Max (document. Body. scrollheight, document. Body. offsetheight)-(jquery. boxmodel? 0: '+ opts. quirksmodeoffsethack +') + "PX "')
: S. setexpression ('height', 'this. parentnode. offsetheight + "PX "');
Full? S. setexpression ('width', 'jquery. boxmodel & document.doc umentelement. clientwidth | document. Body. clientwidth + "PX "')
: S. setexpression ('width', 'this. parentnode. offsetwidth + "PX "');
If (fixl) S. setexpression ('left', fixl );
If (fixt) S. setexpression ('top', fixt );
}
Else if (OPTs. centery ){
If (full) s.setexpression('top', '(document.doc umentelement. clientheight | document. Body. clientheight)/2-(this. offsetheight/2) + (blah = document.doc umentelement. scrolltop? Document.doc umentelement. scrolltop: Document. Body. scrolltop)
+ "PX "');
S. margintop = 0;
}
Else if (! Opts. centery & Full ){
VaR Top = (opts.css & opts.css. Top )? Parseint(opts.css. Top): 0;
VaR expression = '(document.doc umentelement. scrolltop? Document.doc umentelement. scrolltop: Document. Body. scrolltop) + '+ TOP +') + "PX "';
S. setexpression ('top', expression );
}
});
}

// Show the message
If (MSG ){
Lyr3.append (MSG );
If (msg. jquery | msg. nodetype)
$ (MSG). Show ();
}

If ($. browser. MSIE & opts. showoverlay)
Lyr1.show (); // Opacity is zero
If (OPTs. fadein ){
If (OPTs. showoverlay)
Lyr2. _ fadein (OPTs. fadein );
If (MSG)
Lyr3.fadein (OPTs. fadein );
}
Else {
If (OPTs. showoverlay)
Lyr2.show ();
If (MSG)
Lyr3.show ();
}

// Bind key and mouse events
BIND (1, El, opts );

If (full ){
Pageblock = lyr3 [0];
Pageblockels = $ (': input: enabled: visable', pageblock );
If (OPTs. focusinput)
SetTimeout (Focus, 20 );
}
Else
Center (lyr3 [0], opts. centerx, opts. centery );

If (OPTs. Timeout ){
// Auto-unblock
VaR to = setTimeout (function (){
Full? $. Unblockui (OPTs): $ (EL). Unblock (OPTs );
}, Opts. Timeout );
$ (EL). Data ('blockui. timeout', );
}
};

// Remove the block
Function remove (El, opts ){
VaR full = El = window;
VaR $ El = $ (EL );
VaR DATA = $ El. Data ('blockui. History ');
VaR to = $ El. Data ('blockui. timeout ');
If (){
Cleartimeout ();
$ El. removedata ('blockui. timeout ');
}
Opts = $. Extend ({}, $. blockui. defaults, opts || {});
BIND (0, El, opts); // unbind events
VaR els = full? $ ('Body'). Children (). Filter ('. blockui'): $ ('. blockui', El );

If (full)
Pageblock = pageblockels = NULL;

If (OPTs. fadeout ){
Els. fadeout (OPTs. fadeout );
SetTimeout (function () {reset (ELS, Data, opts, El) ;}, opts. fadeout );
}
Else
Reset (ELS, Data, opts, El );
};

// Move blocking element back into the DOM where it started
Function reset (ELS, Data, opts, El ){
Els. Each (function (I, O ){
// Remove via Dom CILS so we don't lose event handlers
If (this. parentnode)
This. parentnode. removechild (this );
});

If (Data & Data. El ){
Data. El. style. Display = data. display;
Data. El. style. Position = data. position;
If (data. Parent)
Data. Parent. appendchild (data. El );
$ (Data. El). removedata ('blockui. History ');
}

If (typeof opts. onunblock = 'function ')
Opts. onunblock (El, opts );
};

// Bind/unbind the Handler
Function BIND (B, El, opts ){
VaR full = El = Window, $ El = $ (EL );

// Don't bother unbinding if there is nothing to unbind
If (! B & (full &&! Pageblock |! Full &&! $ El. Data ('blockui. isblocked ')))
Return;
If (! Full)
$ El. Data ('blockui. isblocked', B );

If (B &&! Opts. showoverlay) // don't prevent events when overlay not in use
Return;

// Bind anchors and inputs for mouse and key events
VaR events = 'mousedown mouseup keydown keypress ';
B? $ (Document). BIND (events, opts, Handler): $ (document). Unbind (events, Handler );

// Former impl...
// Var $ e = $ ('a,: input ');
// B? $ E. BIND (events, opts, Handler): $ E. Unbind (events, Handler );
};

// Event handler to suppress keyboard/mouse events when blocking
Function handler (e ){
// Allow tab navigation (conditionally)
If (E. keycode & E. keycode = 9 ){
If (pageblock & E. Data. constraintabkey ){
VaR els = pageblockels;
VaR FWD =! E. shiftkey & e.tar get = els [els. Length-1];
VaR back = E. shiftkey & e.tar get = els [0];
If (FWD | back ){
SetTimeout (function () {focus (back)}, 10 );
Return false;
}
}
}
// Allow events within the message content
If (objects (e.tar get). Parents ('div. blockmsg '). length> 0)
Return true;

// Allow events for content that is not being blocked
Return parameters (e.tar get). Parents (). Children (). Filter ('div. blockui '). Length = 0;
};

Function focus (back ){
If (! Pageblockels)
Return;
VaR E = pageblockels [back === true? Pageblockels. Length-1: 0];
If (E)
E. Focus ();
};

Function center (El, x, y ){
VaR P = El. parentnode, S = El. style;
VaR L = (P. offsetwidth-El. offsetwidth)/2)-SZ (p, 'borderleftwidth ');
VaR t = (P. offsetheight-El. offsetheight)/2)-SZ (p, 'bordertopwidth ');
If (x) S. Left = L> 0? (L + 'px '): '0 ';
If (y) S. Top = T> 0? (T + 'px '): '0 ';
};

Function SZ (El, p ){
Return parseint().css (El, p) | 0;
};

}) (Jquery );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.