/* * jQuery XYTipsWindow Plus @requires jQuery v1.3.2 * Dual licensed under the MIT and GPL licenses. * * Copyright (c) xinyour (http://www.xinyour.com/) * * Autor: Await * webSite: http://leotheme.cn/ * Date: 星期四 2011年05月15日 * Version: 2.8.0 ********************************************************************** * @example * $("#example").XYTipsWindow(); ********************************************************************** * XYTipsWindow 参数可配置项: * ___title : 窗口标题文字; * ___boxID : 弹出层ID(默认随机); * ___content : 内容(可选内容为){ text | id | img | swf | url | iframe}; * ___width : 窗口宽度(默认宽度为300px); * ___height : 窗口离度(默认高度为200px); * ___titleClass : 窗口标题样式名称; * ___closeID : 关闭窗口ID; * ___boxBdColor : 弹出层外层边框颜色(默认值:#E9F3FD); * ___boxBdOpacity : 弹出层外层边框透明度(默认值:1,不透明); * ___boxWrapBdColor : 弹出层内部边框颜色(默认值:#A6C9E1); * ___windowBgColor : 遮罩层背景颜色(默认值:#000000); *___windowBgOpacity : 遮罩层背景透明度(默认值:0.5); * ___time : 自动关闭等待时间;(单位毫秒); * ___drag : 拖动手柄ID[当指定___triggerID的时候禁止拖动]; * ___dragBoxOpacity : 设置窗口拖动时窗口透明度(默认值:1,不透明); * ___showTitle : 是否显示标题(布尔值 默认为true); * ___showBoxbg : 是否显示弹出层背景(布尔值 默认为true); * ___showbg : 是否显示遮罩层(布尔值 默认为false); * ___button : 数组,要显示按钮的文字; * ___callback : 回调函数,默认返回所选按钮显示的文 ; * ___offsets : 设定弹出层位置,默认居中;内置固定位置浮动:left-top(左上角);right-top(右上角);left-bottom(左下角);right-bottom(右下角);middle-top(居中置顶);middle-bottom(居中置低);left-middle(靠左居中);right-middle(靠右居中); * ___fns : 弹出窗口后执行的函数; **********************************************************************/ ;(function(){ $.XYTipsWindow=function(o){ defaults = $.extend({ ___title:"提示", ___boxID:boxID(10), ___content:"text:内容区域", ___width: "390", ___height: "210", ___titleClass: "boxTitle", ___closeID:"close", ___triggerID:"", ___boxBdColor:"none", ___boxBdOpacity:"0", ___boxWrapBdColor:"none", ___windowBgColor:"#000000", ___windowBgOpacity:"0.5", ___time:"", ___drag:"___boxTitle", ___dragBoxOpacity:"1", ___showTitle:true, ___showBoxbg:false, ___showbg:true, ___offsets:"", ___button:"", ___callback:function(){}, ___fns:function(){} },o); $.XYTipsWindow.init(defaults); }; var BOXID,isIE6 = !-[1,] && !window.XMLHttpRequest; var $XYTipsWindowarr = new Array(); var boxID = function (n){ var Str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0, r =""; i < n; i++){ r += Str.charAt(Math.floor(Math.random() * 62)); }; return r; }; $.extend($.XYTipsWindow,{ //初始化 init: function (o){ BOXID = o; if ($("#"+o.___boxID).length>0){ //alert("对不起,创建弹出层失败!窗口“"+o.___boxID+"”已存在!"); alert("请先完成当前操作!"); return false; }; var $box = $("#"+o.___boxID); $.XYTipsWindow.showBox(o); $(".___closeBox",$box).die().live("click",function(){ $.XYTipsWindow.removeBox(); }).css({zIndex:"891207"}); if(o.___closeID != ""){ $("#"+o.___closeID,$box).die().live("click",function(){ $.XYTipsWindow.removeBox(); }); }; if(o.___time != "") { setTimeout($.XYTipsWindow.removeBox,o.___time); }; if(o.___showbg != "" && o.___showbg == true){ var $boxBgDom = "
"; $($boxBgDom).appendTo("body").animate({opacity:o.___windowBgOpacity},200); }; if(o.___drag != "") { $.XYTipsWindow.dragBox(o); }; if(o.___fns != "" && $.isFunction(o.___fns)){ o.___fns.call(this); }; $.XYTipsWindow.contentBox(o); if (o.___button!=""){ $.XYTipsWindow.ask(o); }; $.XYTipsWindow.keyDown(o); $.XYTipsWindow.setBoxzIndex(o); if(o.___showbg != true){ $("#"+o.___boxID).addClass("shadow"); }; $("#"+o.___boxID).die().live("mouseenter",function(){ BOXID = o; }); }, getID: function(){ return thisID = BOXID.___boxID; }, //构造弹出层 showBox: function(o) { var $titleHeight = o.___showTitle!=true ? 1 : 33, $borderHeight = o.___showTitle!=true ? 0 : 10; $boxDialogHeight = o.___button!="" ? 45 : 0; $boxDialogBorder = $boxDialogHeight == "0" ? "0" : "1"; var $width = parseInt(o.___width) > 1000 ? 1000 : parseInt(o.___width), $height = parseInt(o.___height) > 550 ? 550 : parseInt(o.___height); var $boxDom = "loading...
"); }, error:function(){ $contentID.html("加载数据出错...
"); }, success:function(html){ $contentID.html("loading...
"); }, error:function(){ $contentID.html("加载数据出错...
"); }, success:function(html){ $contentID.html(""); $("#"+o.___boxID+"swf").css({ position:"absolute", left:"0", top:"0", textAlign:"center" }); } }); break; case "url": var contentDate=$content.split("?"); $.ajax({ beforeSend:function() { $contentID.html("loading...
"); }, type:contentDate[0], url:contentDate[1], data:contentDate[2], error:function(){ $contentID.html("加载数据出错...
"); }, success:function(html){ $contentID.html(html); } }); break; case "iframe": $contentID.css({overflowY:"hidden"}); $.ajax({ beforeSend:function() { $contentID.html("loading...
"); }, error:function(){ $contentID.html("加载数据出错...
"); }, success:function(html){ $contentID.html(""); } }); }; }, //对话模式 ask:function(o){ var $box = $("#"+o.___boxID); $boxDialog = $(".___boxDialog",$box); if (o.___button!=""){ var map = {}, answerStrings = []; if (o.___button instanceof Array) { for (var i = 0; i < o.___button.length; i++) { map[o.___button[i]] = o.___button[i]; answerStrings.push(o.___button[i]); }; } else { for (var k in o.___button) { map[o.___button[k]] = k; answerStrings.push(o.___button[k]); }; }; $boxDialog.html($.map(answerStrings, function(v) { return ""; }).join(' ')); $(".dialogBtn", $boxDialog).hover(function(){ $(this).addClass("hover"); },function(){ $(this).removeClass("hover"); }).click(function() { var $this = this; if(o.___callback != "" && $.isFunction(o.___callback)) { //设置回调函数返回值很简单,就是回调函数名后加括号括住的返回值就可以了。 o.___callback(map[$this.value]); }; $.XYTipsWindow.removeBox(o); }); }; }, //获取要吸附的ID的left和top值并重新计算弹出层left和top值 getDomPosition: function (o) { var $box = $("#"+o.___boxID); var cw=document.documentElement.clientWidth,ch=document.documentElement.clientHeight; var sw = $box.outerWidth(),sh = $box.outerHeight(); var $soffset = $box.offset(),sl = $soffset.left,st = $soffset.top; $getPageSize = new Array(); $getPageSize.push(cw,ch,sw,sh,sl,st); }, //设置窗口的zIndex setBoxzIndex: function (o) { $XYTipsWindowarr.push(document.getElementById(o.___boxID+"parent"));//存储窗口到数组 var ___event = "mousedown" || "click"; var $box = $("#"+o.___boxID+"parent"); $box.die().live("click",function(){ for(var i=0; i < $XYTipsWindowarr.length; i++){ $XYTipsWindowarr[i].style.zIndex = 891208+i*10; $(".XYTipsWindowBg").each(function() { var zx = $(this).prev("div").css("z-index"); $(this).css("z-index",zx-1); }); }; }); }, //写入CSS样式 addStyle : function(s) { var T = this.style; if(!T){ T = this.style = document.createElement('style'); T.setAttribute('type', 'text/css'); document.getElementsByTagName('head')[0].appendChild(T); }; T.styleSheet && (T.styleSheet.cssText += s) || T.appendChild(document.createTextNode(s)); }, //绑定拖拽 dragBox: function (o){ var $moveX = 0,$moveY = 0, drag = false; var $ID = $("#"+o.___boxID); $Handle = $("."+o.___drag,$ID); $Handle.mouseover(function() { if(o.___triggerID!=""){ $(this).css("cursor","default"); }else{ $(this).css("cursor","move"); }; }); $Handle.mousedown(function(e) { drag = o.___triggerID!="" ? false : true; if (o.___dragBoxOpacity) { if (o.___boxBdOpacity!="1") { $ID.children("div").css("opacity",o.___dragBoxOpacity); $ID.children("div.___boxBd").css("opacity",o.___boxBdOpacity); }else{ $ID.children("div").css("opacity",o.___dragBoxOpacity); }; }; e = window.event?window.event:e; var ___ID = document.getElementById(o.___boxID); $moveX = e.clientX - ___ID.offsetLeft; $moveY = e.clientY - ___ID.offsetTop; $(document).mousemove(function(e) { if (drag) { e = window.event?window.event:e; window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty(); var ___x = e.clientX - $moveX; var ___y = e.clientY - $moveY; $(___ID).css({ left : ___x, top : ___y }); }; }); $(document).mouseup(function(){ drag = false; if (o.___dragBoxOpacity) { if (o.___boxBdOpacity!="1") { $ID.children("div").css("opacity","1"); $ID.children("div.___boxBd").css("opacity",o.___boxBdOpacity); }else{ $ID.children("div").css("opacity","1"); }; }; }); }); }, //关闭弹出层 removeBox: function (){ var $box = $("#"+BOXID.___boxID); var $boxbg = $(".XYTipsWindowBg"); var len = $boxbg.length; if($box != null || $boxbg != null){ var $contentID = $(".___boxContent",$box); $contentType = BOXID.___content.substring(0,BOXID.___content.indexOf(":")); $content = BOXID.___content.substring(BOXID.___content.indexOf(":")+1,BOXID.___content.length); if ($contentType == "id") { $contentID.children().appendTo($("#"+$content)); $box.parent().removeAttr("style").remove(); $boxbg.eq(len-1).animate({opacity:"0"},200,function(){$(this).remove();}); }else{ $box.parent().removeAttr("style").remove(); $boxbg.eq(len-1).animate({opacity:"0"},200,function(){$(this).remove();}); }; }; }, //健盘事件,当按Esc的时候关闭弹出层 keyDown: function(o) { document.onkeydown = function(e) { e = e || event; if(e.keyCode == 27){ $(".audit-letter").hide(); $.XYTipsWindow.removeBox(); }; }; } }); })(jQuery);