1 |
- (function($){var p=null;$.fn.openDialog=function(options){if(this.size()==0){return null}var settings={dymamic:false,dymamicOff:false,opacity:.7,backgroundColor:"#000",positionTo:"",speed:240,clickOtherClose:true,border:false,width:"",height:"",draw:undefined,position:"absolute",closedFunc:function(){}};if(options){settings=$.extend(settings,options)}if(settings.dialogType!="ui"){p=settings}$(this).css("width",settings.width);$(this).css("height",settings.height);var width=$(document).width();var height=$(document).height();var thisObj=this;var bl=!!settings.zIndex;settings.zIndex=settings.zIndex||2e3;if(settings.border){var pwidth=thisObj.show().width();thisObj=thisObj.wrap('<div style="position: relative;width:'+pwidth+'px" class="popwrap"><div class="popcon faceImg_pop"></div></div>').parent().after('<b class="bg_mask" style="width:'+(pwidth+20)+'px"></b>').parent()}$(this).data("p",p);var allOpenDialog=$(thisObj[0].tagName+".open_dialog_jquery");if(allOpenDialog.size()>0){var arr=allOpenDialog.toArray().sort(function(a,b){return $(a).css("zIndex")<$(b).css("zIndex")});if(!bl){var index=$(arr[0]).css("zIndex");index=index=="auto"?settings.zIndex:index;settings.zIndex=parseInt(index)+2}}$(this).addClass("open_dialog_jquery");var bgZIndex=settings.zIndex-1;var bgId=$(this).attr("bgid");if(!bgId){bgId="#bg_x_"+bgZIndex;$(this).attr("bgid",bgId)}if(settings.backgroundColor){if($(bgId).size()==0){$("body").append('<div style="position:absolute;left:0px;top:0px;width:100%;height:'+height+"px;background-color:"+settings.backgroundColor+";z-index:"+(bgZIndex-1)+";display:none;\" id='"+bgId.substring(1)+"'></div>")}else{$(bgId).css("height",$(document).height())}}thisObj.hide();if(settings.backgroundColor){if(settings.dymamic){$(bgId).fadeTo(0,0).show().fadeTo(settings.speed,settings.opacity);positionInit(thisObj,settings,width,height)}else{var b=$(bgId);if(!b.attr("isOpacity")){b.fadeTo(0,settings.opacity);b.attr("isOpacity",true)}b.css("display","block");positionInit(thisObj,settings,width,height)}}else{positionInit(thisObj,settings,width,height)}if(p&&p.clickOtherClose){$(bgId).one("click",function(){$(thisObj).closeDialog();if(typeof p.onclose=="function"){p.onclose()}})}if(p&&p.close){thisObj.find(p.close).one("click",function(){$(thisObj).closeDialog();return false})}if(p&&p.draw){var obj=$(this).find(p.draw);if(!obj.attr("draw")){obj.attr("draw",true);var ps={};var moveObj=obj.parent();obj.mousedown(function(e){obj.css("cursor","move");obj.isDraw=true;ps.left=e.clientX-moveObj.offset().left;ps.top=e.clientY+$(window).scrollTop()-moveObj.offset().top});$(document).mouseup(function(){obj.css("cursor","");obj.isDraw=false}).mousemove(function(e){if(obj.isDraw){moveObj.css({left:e.clientX-ps.left,top:e.clientY+$(window).scrollTop()-ps.top})}})}}};$.fn.closeDialog=function(call){var p=$(this).data("p");if(p.dymamic){this.fadeOut(p.speed)}else{this.hide()}this.removeClass("open_dialog_jquery");var bgId=$(this).attr("bgid");if(p&&$(bgId).length>0){if(p.dymamic){$(bgId).fadeOut(p.speed,function(){typeof call=="function"&&call()})}else{$(bgId).hide();typeof call=="function"&&call()}if(typeof p.onclose=="function"){p.onclose()}}return this};function positionInit(thisObj,settings,width){var positionTo=settings.positionTo;var tmpHeight=0;var tmpScrollTop=$(window).scrollTop();var top=0;var left=0;if(positionTo){var p=null,addLeft=0,addTop=0;if(typeof positionTo=="string"){p=$(positionTo)}else if(typeof positionTo=="object"){p=$(positionTo.slt);addLeft=positionTo.left||0;addTop=positionTo.top||0}tmpHeight=p.height();width=p.width();top=p.offset().top+addTop;left=p.offset().left+addLeft}else{tmpHeight=$(window).height();top=(tmpHeight-thisObj.height())/2+tmpScrollTop;left=(width-thisObj.width())/2}if(top<0){top=0}if(left<0){left=0}if(settings.position=="fixed"){top-=tmpScrollTop;thisObj.css({position:"fixed",margin:"0 0 0 0",zIndex:settings.zIndex+1,top:top,left:left,display:"block"})}else{thisObj.css({position:"absolute",margin:"0 0 0 0",zIndex:settings.zIndex+1,top:top,left:left,display:"block"})}if(settings.dymamic){thisObj.hide().fadeIn(settings.speed)}if(settings.dymamicOff){settings.dymamic=true}}})(jQuery);
|