/* * jquery blockui plugin */ ; (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; //var noop = function() { }; // this bit is to ensure we don't call setexpression when we shouldn't (with extra muscle to handle // retarded useragent strings on vista) var mode = document.documentmode || 0; var setexpr = $.browser.msie && (($.browser.version < 8 && !mode) || mode < 8); var ie6 = $.browser.msie && /msie 6.0/.test(navigator.useragent) && !mode; // global $ methods for blocking/unblocking the entire page $.blockui = function(opts) { install(window, opts); }; $.unblockui = function(opts) { remove(window, opts); }; // 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.31; // 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: 'please wait...', // styles for the message when blocking; if you wish to disable // these and use an external stylesheet then do this in your code: // $.blockui.defaults.css = {}; css: { padding:0, margin:0, width:'300px', top:'30%', left:'50%', marginleft:'-150', textalign:'center', color:'#000', border:'1px solid #3b555c', backgroundcolor:'#cbddef', padding:'10px' //cursor:'wait' }, // styles for the overlay overlaycss: { backgroundcolor: '#000', opacity:'0.3' }, // 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 elementcghf 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, // fadeout time in millis; set to 0 to disable fadeout on unblock fadeout: 400, // 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 hascghf 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 }; // 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({}, $.blockui.defaults.css, opts.css || {}); msg = 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 ascghf 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; 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) ? $('') : $(''); var lyr2 = $('
'); var lyr3 = full ? $('
') : $(''); // if we have a message, style it if (msg){ lyr3.css(css); lyr3.css('left', $.browser.msie ? '50%' : (document.body.offsetwidth-parseint(css.width))/2 + "px"); lyr3.css('marginleft', $.browser.msie ? -parseint(css.width)/2 + "px" : ''); } // 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 = setexpr && (!$.boxmodel || $('object,embed', full ? null : el).length > 0); if (ie6 || expr) { // give body 100% height if (full && opts.allowbodystretch && $.boxmodel) $('html,body').css('height', '100%'); // 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','document.body.scrollheight > document.body.offsetheight ? document.body.scrollheight : document.body.offsetheight + "px"') : s.setexpression('height', 'this.parentnode.offsetheight + "px"'); full ? s.setexpression('width', 'jquery.boxmodel && document.documentelement.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.documentelement.clientheight || document.body.clientheight) / 2 - (this.offsetheight / 2) + (blah = document.documentelement.scrolltop ? document.documentelement.scrolltop : document.body.scrolltop) + "px"'); s.margintop = 0; } }); } // show the message lyr3.append(msg).show(); if (msg && (msg.jquery || msg.nodetype)) $(msg).show(); // bind key and mouse events bind(1, el, opts); if (full) { pageblock = lyr3[0]; pageblockels = $(':input:enabled:visible',pageblock); if (opts.focusinput) settimeout(focus, 20); } else center(lyr3[0], opts.centerx, opts.centery); }; // remove the block function remove(el, opts) { var full = el == window; var data = $(el).data('blockui.history'); 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 calls 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; 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); // bind anchors and inputs for mouse and key events var events = 'mousedown mouseup keydown keypress click'; 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.target == els[els.length - 1]; var back = e.shiftkey && e.target == els[0]; if (fwd || back) { settimeout(function() { focus(back) }, 10); return false; } } } // allow events within the message content if ($(e.target).parents('div.blockmsg').length > 0) return true; // allow events for content that is not being blocked return $(e.target).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); //仿alert (function($){ $.fn.alertwindow = function(ntc,url){ $('div#alert').remove(); $('html').append("
"); $('div#alert').append("
提示信息
"+ntc+"
"); $.blockui({message: $('div#alert'),css:{width:'300px'}}); $('#ok').click(function() { $.unblockui(); $("div#alert").fadeout("slow"); if(url!=""){ settimeout("self.location='"+url+"'",300); } }); $('.pwclose').click(function() { $.unblockui(); $("div#alert").fadeout("slow"); if(url!=""){ settimeout("self.location='"+url+"'",300); } }); }; })(jquery);