/* Msgbox component * (c) 2009 PinLite.com * * msgbox is freely distributable under the terms of an MIT-style license. * *--------------------------------------------------------------------------*/ var NO_EFFECT= 'NO', HORIZONT_EFFECT = 'HORIZONT', VERTICAL_EFFECT = 'VERTICAL', BOTH_EFFECT = 'BOTH', POSITION_TOP = 'TOP', POSITION_CENTER = 'CENTER', POSITION_LEFT = 'LEFT', POSITION_RIGHT = 'RIGHT', POSITION_BOTTOM = 'BOTTOM', BOX_STATUS = 0; function iMaxH(){ return ((window.clientHeight || window.document.body.clientHeight) -30); } var MessageBoxParams={ //InitWidth : 350, //default width of message //InitHTMLWidth : 800, //default minimum width of HTML pupup //Opacity : 100, //opacity in % //ButtonOK : 'Закрыть', //text on button //ShowEffects : BOTH_EFFECT, // NO, HORIZONT, VERTICAL or BOTH slow appirance of message //PupUpPosition : [POSITION_CENTER,POSITION_CENTER], //position of messagebox, {x,y} coords. Your can set own coords like {500,400} in px Moveable : true, // moveable popup //SaveLastMovePosition : false, //save last x & y position if popup has been moved //Resize : false, // if popup resizeable or not StyleDir : '../css/', //path to style files ImgDir : '../img/msgbox/' //path to img files } var AlertBoxProps = { ShowEffectType : VERTICAL_EFFECT, ButtonOK : C_LRSCls, InitWidth : 380, PupUpPosition : [POSITION_CENTER,POSITION_CENTER], Moveable : true } var AlertHTMLBoxProps = { ShowEffectType : NO_EFFECT, ButtonOK : C_LRSCls, InitWidth : 800, PupUpPosition : [POSITION_CENTER,POSITION_CENTER], Moveable : true } var WinHTMLBoxProps= { ShowEffectType : NO_EFFECT, ButtonOK : C_LRSCls, InitWidth : 800, InitHeight : 'MAX', PupUpPosition : [POSITION_CENTER,POSITION_CENTER], Moveable : true } var PullDownProps = { ShowEffectType : VERTICAL_EFFECT, InitWidth : 300, PupUpPosition : [POSITION_RIGHT,POSITION_BOTTOM], ShowForTimer: 5 } var PullDownPropsInfo = { ShowEffectType : VERTICAL_EFFECT, InitWidth : 300, PupUpPosition : [POSITION_RIGHT,POSITION_BOTTOM], ShowForTimer: 60 } var PullDownAcyncProcessInfo = { ShowEffectType : VERTICAL_EFFECT, InitWidth : 450, PupUpPosition : ['250',POSITION_BOTTOM] // ShowForTimer: 60 } var ConfirmBoxProps = { ShowEffectType : VERTICAL_EFFECT, ButtonOK : 'OK', ButtonCancel : C_LRSCls, InitWidth : 380, PupUpPosition : [POSITION_CENTER,POSITION_CENTER], Moveable : true } var ConfirmHTMLBoxProps = { ShowEffectType : NO_EFFECT, ButtonOK : 'OK', ButtonCancel : C_LRSCls, InitWidth : 800, PupUpPosition : [POSITION_CENTER,POSITION_CENTER], Moveable : true } var MessageBoxObject = { alert : function(x,xHead,hideProc){ if(!MessageBoxObject.AlertBox) MessageBoxObject.AlertBox = new AlertBox(); MessageBoxObject.AlertBox.setName('MessageBoxObject.AlertBox'); MessageBoxObject.AlertBox.setProps(AlertBoxProps); MessageBoxObject.AlertBox.setTitle(xHead); MessageBoxObject.AlertBox.setBody(x,true); MessageBoxObject.AlertBox.setCloseMethod(hideProc); BOX_STATUS = BOX_STATUS + 1; MessageBoxObject.AlertBox.show(); }, alertHTML : function(x,xHead,newBoxProps){ if(!MessageBoxObject.AlertHTMLBox) MessageBoxObject.AlertHTMLBox = new AlertBox(); MessageBoxObject.AlertHTMLBox.setName('MessageBoxObject.AlertHTMLBox'); MessageBoxObject.AlertHTMLBox.setProps(newBoxProps||AlertHTMLBoxProps); MessageBoxObject.AlertHTMLBox.setTitle(xHead); MessageBoxObject.AlertHTMLBox.setBody(x); BOX_STATUS = BOX_STATUS + 1; MessageBoxObject.AlertHTMLBox.show(); }, pullDown : function(x){ if(!MessageBoxObject.PullDown)MessageBoxObject.PullDown = new PullDown(); MessageBoxObject.PullDown.setName('MessageBoxObject.PullDown'); MessageBoxObject.PullDown.setProps(PullDownProps); MessageBoxObject.PullDown.setBody(x); MessageBoxObject.PullDown.show(); }, pullInfo : function(x){ if(!MessageBoxObject.pullDownInfo)MessageBoxObject.pullDownInfo = new PullDown(); MessageBoxObject.pullDownInfo.setName('MessageBoxObject.pullDownInfo'); MessageBoxObject.pullDownInfo.setProps(PullDownPropsInfo); MessageBoxObject.pullDownInfo.setBody(x); MessageBoxObject.pullDownInfo.show(); }, pullDownAcyncInfo : function(x){ if(!MessageBoxObject.pullDownAcyncProcess)MessageBoxObject.pullDownAcyncProcess = new PullDown(); MessageBoxObject.pullDownAcyncProcess.setName('MessageBoxObject.pullDownAcyncProcess'); MessageBoxObject.pullDownAcyncProcess.setProps(PullDownAcyncProcessInfo); MessageBoxObject.pullDownAcyncProcess.setBody(x); MessageBoxObject.pullDownAcyncProcess.show(); }, confirm : function(x,xHead,hideProc){ if(!MessageBoxObject.ConfirmBox) MessageBoxObject.ConfirmBox = new ConfirmBox(); MessageBoxObject.ConfirmBox.setName('MessageBoxObject.ConfirmBox'); MessageBoxObject.ConfirmBox.setProps(ConfirmBoxProps); MessageBoxObject.ConfirmBox.setTitle(xHead); MessageBoxObject.ConfirmBox.setBody(x,true); MessageBoxObject.ConfirmBox.setCloseMethod(hideProc); BOX_STATUS = BOX_STATUS + 1; MessageBoxObject.ConfirmBox.show(); }, confirmHTML : function(x,xHead,newBoxProps){ if(!MessageBoxObject.ConfirmHTMLBox) MessageBoxObject.ConfirmHTMLBox = new ConfirmBox(); MessageBoxObject.ConfirmHTMLBox.setName('MessageBoxObject.ConfirmHTMLBox'); MessageBoxObject.ConfirmHTMLBox.setProps(newBoxProps||ConfirmHTMLBoxProps); MessageBoxObject.ConfirmHTMLBox.setTitle(xHead); MessageBoxObject.ConfirmHTMLBox.setBody(x); BOX_STATUS = BOX_STATUS + 1; MessageBoxObject.ConfirmHTMLBox.show(); } } //**************MsgBox - PullDown function PullDown(){ this.PullDownBox=getNewLayer('PullDown'); window.document.body.appendChild(this.PullDownBox); this.visualEffects = new VisualEffects(); this.visualEffects.setEffectObject(this.PullDownBox); this.setName=function(x){ this.objName=x; } this.getName=function(){ return this.objName; } this.setProps = function(Obj){ this.Props = Obj; this.visualEffects.setType(Obj.ShowEffectType); } this.setBody=function(x){ this.PullDownBox.innerHTML = '

'+x.replace(/\n/g,'

')+'

'; } this.close=function(){ this.PullDownBox.innerHTML = ''; this.PullDownBox.style.display='none'; } this.show=function(){ if(this.TimeOutID)window.clearTimeout(this.TimeOutID); this.PullDownBox.style.width = this.Props.InitWidth+'px'; this.visualEffects.start(this.objName+'.visualEffects',1); placeToCoords(this.PullDownBox,this.Props.PupUpPosition[0],this.Props.PupUpPosition[1]); if(this.Props.ShowForTimer)this.TimeOutID = window.setTimeout(this.getName()+'.close()',this.Props.ShowForTimer*1000); this.PullDownBox.style.zIndex = '10000'; } } //*************MsgBox - alert function AlertBox(){ this.alertBox=getNewLayer('MessageBox'); this.IsShow = false; with(this.alertBox.style){ display='none'; } this.headBlock = getNewLayer('MessageBoxHead'); this.headBlock.id = "HeadBlockID"; this.alertBox.appendChild(this.headBlock); this.textBlock = getNewLayer('MessageBoxText'); this.textBlock.id = 'MessageBoxText'; this.alertBox.appendChild(this.textBlock); this.buttonBlock = getNewLayer('MessageBoxButtons'); this.alertBox.appendChild(this.buttonBlock); window.document.body.appendChild(this.alertBox); this.visualEffects = new VisualEffects(); this.visualEffects.setEffectObject(this.alertBox); this.setName=function(x){ this.objName=x; } this.getName=function(x){ return this.objName; } this.setTitle=function(x){ this.headBlock.innerHTML = x ? x : ' '; placeToCoords(this.alertBox,this.Props.PupUpPosition[0],this.Props.PupUpPosition[1]); } this.setBody=function(x,doTransform){ try{if(!window.Disabled) DSBForm(w,true);}catch(e){} x = x.replace(/(\d{1}\|)(\D{1,})/g,'$2'); x = x.replace(/\[NL\]/g,'

'); x = x.replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"').replace(/'/g,"'"); this.textBlock.innerHTML = doTransform ? ('

'+x+'

'):x; } this.clearBody=function(x,doTransform){ this.textBlock.innerHTML = '..'; } this.setProps = function(Obj){ this.Props = Obj; this.visualEffects.setType(Obj.ShowEffectType); if(this.Props.Moveable){ attachMoveHandl('mousedown',this.getName(),'mousedown',this.headBlock); attachMoveHandl('mousemove',this.getName(),'mousemove',this.headBlock); attachMoveHandl('mouseup',this.getName(),'mouseup',this.headBlock); } } this.setCloseMethod = function(obj){ this.CloseMethod = obj ? obj : null; } this.show=function(x){ this.alertBox.style.width = this.Props.InitWidth.toString()+'px'; this.buttonBlock.innerHTML=''; if (this.alertBox.style.display=='block') BOX_STATUS = BOX_STATUS - 1; this.alertBox.style.display = 'block'; if (this.objName=='MessageBoxObject.AlertHTMLBox') this.alertBox.style.zIndex = '10000'; else this.alertBox.style.zIndex = '10005'; this.setPupUpHeight(); this.setPupUpWidth(); this.visualEffects.start(this.objName+'.visualEffects'); this.IsShow = true; this.setPosition(); _attachElmHndlrs(w,$(window,'MessageBoxText')); } this.setPosition=function(){ placeToCoords(this.alertBox,this.Props.PupUpPosition[0],this.Props.PupUpPosition[1]); } this.setPupUpHeight = function(){ var iHMax = iMaxH(); if(this.Props.InitHeight){ var iH = this.Props.InitHeight; if(this.Props.InitHeight=='MAX')iH=iHMax; this.textBlock.style.height =(iH-this.headBlock.offsetHeight - this.buttonBlock.offsetHeight).toString()+'px'; this.alertBox.style.height = iH + 'px'; return; } this.alertBox.style.height ='auto'; this.textBlock.scrollTop=0; if(this.alertBox.scrollHeight>iHMax){ this.textBlock.style.height =(iHMax-this.headBlock.offsetHeight - this.buttonBlock.offsetHeight).toString()+'px'; this.alertBox.style.height =iHMax.toString() + 'px'; } var iDif = this.alertBox.scrollHeight-this.textBlock.scrollHeight; if(iDif < 0){ this.textBlock.style.height = this.textBlock.scrollHeight+iDif-this.headBlock.offsetHeight-this.buttonBlock.offsetHeight; this.alertBox.style.height = (this.textBlock.offsetHeight + this.headBlock.offsetHeight +this.buttonBlock.offsetHeight).toString() + 'px'; }else{ this.textBlock.style.height = 'auto'; this.alertBox.style.height = 'auto'; } } this.setPupUpWidth = function(){ var iWRes = this.textBlock.scrollWidth+(this.textBlock.offsetWidth-this.textBlock.scrollWidth); if (this.headBlock.offsetWidth'); x = x.replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"').replace(/'/g,"'"); this.textBlock.innerHTML = doTransform ? ('

'+x+'

'):x; } this.clearBody=function(x,doTransform){ this.textBlock.innerHTML = '..'; } this.setProps = function(Obj){ this.Props = Obj; this.visualEffects.setType(Obj.ShowEffectType); if(this.Props.Moveable){ attachMoveHandl('mousedown',this.getName(),'mousedown',this.headBlock); attachMoveHandl('mousemove',this.getName(),'mousemove',this.headBlock); attachMoveHandl('mouseup',this.getName(),'mouseup',this.headBlock); } } this.setCloseMethod = function(obj){ this.CloseMethod = obj ? obj : null; } this.show=function(x){ this.confirmBox.style.width = this.Props.InitWidth.toString()+'px'; this.buttonBlockOK.innerHTML =''; this.buttonBlockCancel.innerHTML =''; if (this.confirmBox.style.display=='block') BOX_STATUS = BOX_STATUS - 1; this.confirmBox.style.display = 'block'; if (this.objName=='MessageBoxObject.ConfirmHTMLBox') this.confirmBox.style.zIndex = '10000'; else this.confirmBox.style.zIndex = '10005'; this.setPupUpHeight(); this.visualEffects.start(this.objName+'.visualEffects'); this.IsShow = true; this.setPosition(); _attachElmHndlrs(w,$(window,'MessageBoxText')); } this.setPosition=function(){ placeToCoords(this.confirmBox,this.Props.PupUpPosition[0],this.Props.PupUpPosition[1]); } this.setPupUpHeight = function(){ var iHMax = iMaxH(); if(this.Props.InitHeight){ var iH = this.Props.InitHeight; if(this.Props.InitHeight=='MAX')iH=iHMax; this.textBlock.style.height =(iH-this.headBlock.offsetHeight - this.buttonBlock.offsetHeight).toString()+'px'; this.confirmBox.style.height =iH + 'px'; return; } this.confirmBox.style.height ='auto'; this.textBlock.scrollTop=0; if(this.confirmBox.scrollHeight>iHMax){ this.textBlock.style.height =(iHMax-this.headBlock.offsetHeight - this.buttonBlock.offsetHeight).toString()+'px'; this.confirmBox.style.height =iHMax.toString() + 'px'; } var iDif = this.confirmBox.scrollHeight-this.textBlock.scrollHeight; if(iDif < 0){ this.textBlock.style.height = this.textBlock.scrollHeight+iDif-this.headBlock.offsetHeight-this.buttonBlock.offsetHeight; this.confirmBox.style.height = (this.textBlock.offsetHeight + this.headBlock.offsetHeight +this.buttonBlock.offsetHeight).toString() + 'px'; }else{ this.textBlock.style.height = 'auto'; this.confirmBox.style.height = 'auto'; } } this.close=function(){ try{wait_hide(w);}catch(e){} this.clearBody(); this.confirmBox.style.display='none'; BOX_STATUS = BOX_STATUS - 1; try{if(BOX_STATUS==0) {DSBForm(w,false); if(w.IsDict) w.IsDict=false;}}catch(e){} this.IsShow = false; if(!this.CloseMethod) return; try{ if(typeof(this.CloseMethod)=='object')this.CloseMethod.focus() else{ var bResult=true; try{eval.call(window, this.CloseMethod)}catch(e){bResult=false} try{if(!bResult)eval(this.CloseMethod)}catch(e){confirm(e || e.description)} } }catch(e){} var oHB=this.headBlock; if (isIE) oHB.releaseCapture(); else oHB.releaseCaptureNonIE(); } this.mousedown = function(e){ this.Props.isMoving = true; if(!e)e=window.event; try{ var oHB=this.headBlock; if (isIE) oHB.setCapture(); else oHB.setCaptureNonIE(); }catch(e){} e.cancelBubble=true; var el=e.target || e.srcElement; this.objX= e.layerX || e.offsetX; this.objY= e.layerY || e.offsetY; try{e.returnValue=false;}catch(e){} try{e.preventDefault();}catch(e){} } this.mousemove =function(e){ if(this.Props.isMoving){ if(!e)e=window.event; if(!this.objX || !this.objY)return; var iXX = (e.clientX -this.objX + document.body.scrollLeft); var iYY = (e.clientY -this.objY + document.body.scrollTop); this.confirmBox.style.left = iXX.toString() + 'px'; this.confirmBox.style.top = iYY.toString() + 'px'; try{e.returnValue=false;}catch(e){} try{e.preventDefault();}catch(e){} } } this.mouseup = function(){ this.Props.isMoving = false; try{ var oHB=this.headBlock; if (isIE) oHB.releaseCapture(); else oHB.releaseCaptureNonIE(); }catch(e){} this.objX=null; this.objY=null; } } //***************VisualEffects function VisualEffects(){ this.setType=function(x){ this.effectType=x; } this.setEffectObject=function(obj){ this.effectObject=obj; } this.start=function(xIntervalObj,iInt){ if(!iInt)iInt=10; switch(this.effectType){ case HORIZONT_EFFECT:; case VERTICAL_EFFECT:; case BOTH_EFFECT: var bBE = this.effectType==BOTH_EFFECT; this.heightClip = bBE ? 0:15; this.widthClip = bBE ? 0:15; //Opera 11.10 затирает эти параметры после установки clip var oldHeight = this.effectObject.offsetHeight, oldWidth = this.effectObject.offsetWidth; this.effectObject.style.clip='rect(0px,0px,0px,0px)'; //восстанавливаем параметры для Opera if (IsOpera) { this.effectObject.offsetHeight = oldHeight; this.effectObject.offsetWidth = oldWidth; } this.effectObject.style.display='block'; if(bBE){ this.iCntX=this.effectObject.offsetWidth/2; this.iCntY=this.effectObject.offsetHeight/2; } this.show(xIntervalObj,iInt); break; default: this.effectObject.style.display='block'; break; } } this.show = function(xIntervalObj,iInt){ var iTop=0,iBottom=0,iRight=0,iLeft=0; switch(this.effectType){ case HORIZONT_EFFECT: this.widthClip+=25; iRight=this.widthClip; iBottom=this.effectObject.offsetHeight; break; case VERTICAL_EFFECT: this.heightClip+=20; iRight=this.effectObject.offsetWidth; iBottom=this.heightClip; break; case BOTH_EFFECT: iRight=this.iCntX+this.widthClip; iBottom=this.effectObject.offsetHeight; iLeft=this.effectObject.offsetWidth/2-this.widthClip; this.iCntX+=1; this.heightClip=this.heightClip*2+1; this.iCntY-=this.effectObject.offsetHeight/10; this.widthClip=this.widthClip*2+1; break; default: this.effectObject.style.display='block'; break; } this.effectObject.style.clip='rect('+iTop.toString()+'px,'+iRight.toString()+'px,'+iBottom.toString()+'px,'+iLeft.toString()+'px)'; if(!(iBottom>=this.effectObject.offsetHeight && iRight>=this.effectObject.offsetWidth))setTimeout(xIntervalObj.toString()+'.show("'+xIntervalObj.toString()+'")',10);//iInt } } //****************VisualEffects function placeToCoords(obj,x,y){ var xScroll = window.document.body.scrollLeft, yScroll = window.document.body.scrollTop, xPos=3+xScroll, yPos=3+yScroll, xWidth = window.innerWidth || window.document.body.clientWidth, xHeight = window.innerHeight || window.document.body.clientHeight; if(IsOpera && obj.getBoundingClientRect && obj.style.display != 'none'){ var rect = obj.getBoundingClientRect(); obj.offsetWidth = rect.right - rect.left; obj.offsetHeight = rect.bottom - rect.top; } switch(x){ case POSITION_CENTER: xPos = xWidth/2 + xScroll -obj.offsetWidth/2; break; case POSITION_RIGHT: xPos = xWidth + xScroll-obj.offsetWidth-20; break; default: xPos = x; break; } switch(y){ case POSITION_CENTER: yPos = xHeight/2 + yPos-obj.offsetHeight/2 break; case POSITION_BOTTOM: yPos = xHeight + yScroll - obj.offsetHeight - 3 ; break; default: yPos = y; break; } if(yPos<0)yPos=10+yScroll; if(xPos<0)xPos=10+xScroll; obj.style.left=xPos + 'px'; obj.style.top=yPos + 'px'; } function getNewLayer(className){ var oL=window.document.createElement('DIV'); if(className)oL.className=className; return oL; } function attachMoveHandl(x,objName,func,obj){ if(obj.attachEvent)obj.attachEvent('on'+x,new Function(objName+'.'+func+'.apply('+objName+', arguments)')) else obj.addEventListener(x,new Function(objName+'.'+func+'.apply('+objName+', arguments)'),false); } //loading CSS //********************************************* function MessageBoxCSSLoad(){ try{ if(!window.document.body)return; window.clearInterval(window.MessageBoxInterval); var cssFileName=MessageBoxParams.StyleDir+'msgbox.css'; if(MessageBoxParams.StyleDir){ if(window.document.createStyleSheet)window.document.createStyleSheet(cssFileName) else{ var in_style = window.document.createElement('LINK'); in_style.setAttribute('REL','stylesheet'); in_style.setAttribute('HREF',cssFileName); window.document.getElementsByTagName('HEAD')[0].appendChild(in_style); } } }catch(e){} } if(MessageBoxParams.StyleDir) window.MessageBoxInterval=window.setInterval(MessageBoxCSSLoad,200); // Межевой 23.09.2010 // Эмуляция методов setCaption() и releaseCaption() для браузеров // отличных от IE if(window.HTMLElement) { var element = HTMLElement.prototype; var capture = ["mouseup","mousemove"]; function _capture(e){ var event = document.createEvent("MouseEvents"); event.initMouseEvent(e.type, false, true, window, 0, e.screenX, e.screenY, e.clientX, e.clientY, false, false, false, false, 0, null); $(w,'HeadBlockID').dispatchEvent(event); } element.setCaptureNonIE = function(){ for (var i=0; i