/**************************************************************************** * DHTML modal dialog box * Created: August, 26th, 2006 * @class Purpose of class: Display a modal dialog box on the screen. *****************************************************************************/ /** * @constructor */ ModalMessage = function() { this.url=''; // url of modal message this.htmlOfModalMessage=''; // html of modal message this.divs_transparentDiv; // Transparent div covering page content this.divs_content; // Modal message div. this.divs_shadow; this.iframe; // Iframe used in ie this.width=200; this.height=400; this.cssClassOfMessageBox=false; // Alternative css class of message box - in case you want a different appearance on one of them this.shadowVisible=true; this.shadowOffset=5; // X and Y offset of shadow(pixels from content box) this.popupMsg=false; // gets set to true if a pop-up message is shown. Is used to resize the dialog this.title=""; this.closeFunction=""; this.closeTitle=""; this.fast=false; this.draggable=true; this.resizable=false; this.noPopupMsg=false; this.completionCallback=null; } ModalMessage.prototype = { /** * Set source of the modal dialog box */ setSource : function(urlOfSource) { this.url = urlOfSource; } , /** * Setting static HTML content for the modal dialog box. * @param String newHtmlContent = Static HTML content of box */ setHtmlContent : function(newHtmlContent) { this.htmlOfModalMessage = newHtmlContent; if(this.divs_content) { this.__resizeDivs(true,0); } } , /** * Set the size of the modal dialog box * @param int width = width of box * @param int height = height of box */ setSize : function(width,height) { this.width = width; this.height = height; } , /** * Assign the message box to a new css class.(in case you wants a different appearance on one of them) * @param String newCssClass = Name of new css class (Pass false if you want to change back to default) */ setCssClassMessageBox : function(newCssClass) { this.cssClassOfMessageBox = newCssClass; if(this.divs_content) { if(this.cssClassOfMessageBox) this.divs_content.className=this.cssClassOfMessageBox; else this.divs_content.className='modalDialog_contentDiv'; } } , /** * Specify the size of shadow * @param Int newShadowOffset = Offset of shadow div(in pixels from message box - x and y) */ setShadowOffset : function(newShadowOffset) { this.shadowOffset = newShadowOffset } , /** * Display the modal dialog box */ display : function() { this.__createDivs(); // Redisplaying divs if(this.fast) { $("modalDialog_transparentDivs").display='block'; } else { fadeIn("modalDialog_transparentDivs",0,0.5); } if(this.shadowVisible) { this.divs_shadow.style.display='block'; } if(runningInIE()) { this.iframe.style.display='block'; } this.__resizeDivs(true,0); window.refToThisModalBoxObj = this; this.__insertContent(); // Calling method which inserts content into the message div. } , /** * Display the modal dialog box */ setShadowVisible : function(visible) { this.shadowVisible = visible; this.redrawShadow(); } , /** * Close the modal dialog box */ close : function() { //document.documentElement.style.overflow = ''; // Setting the CSS overflow attribute of the tag back to default. /* Hiding divs */ if(runningInIE() || this.fast) { secureRemove(this.divs_transparentDiv); } else { fadeOut("modalDialog_transparentDivs",0.5,0); setTimeout("secureRemove('modalDialog_transparentDivs')",600); } secureRemove(this.divs_content); secureRemove(this.divs_shadow); secureRemove(this.iframe); secureRemove("popup_msg_div"); secureRemove("dialogWrapperDiv"); Event.stopObserving(document,"keypress",keypressListener); } , /** * Create the divs for the modal dialog box * @private */ __createDivs : function() { // Creating transparent div this.divs_transparentDiv = Builder.node("div",{ className: 'modalDialog_transparentDivs', id : 'modalDialog_transparentDivs', style : "left:0px;top:0px" }); document.body.appendChild(this.divs_transparentDiv); // Creating content div this.divs_content = Builder.node("div",{ className: 'modalDialog_contentDiv', id : 'modalBox_contentDiv', style : 'zIndex:900;' }); if(runningInIE()) { this.iframe = Builder.node('iframe', { src : 'about:blank', frameborder: '0', style : 'zIndex:800;position:absolute' }); document.body.appendChild(this.iframe); } document.body.appendChild(this.divs_content); if(this.shadowVisible) { // Creating shadow div this.divs_shadow = Builder.node('div', { className: 'modalDialog_contentDiv_shadow', style : 'zIndex:850;' }); document.body.appendChild(this.divs_shadow); window.refToModMessage = this; Event.observe(window,'scroll',function(e){ window.refToModMessage.__repositionTransparentDiv() }); Event.observe(window,'resize',function(e){ window.refToModMessage.__repositionTransparentDiv() }); } } , /** * Redraws the shadow div, useful after the shape or position of the main div has changed. */ redrawShadow : function() { if(this.shadowVisible) { // Creating temporary width variables since the actual width of the content div could be larger than this.width and this.height(i.e. padding and border) var tmpWidth = this.divs_content.offsetWidth; var tmpHeight = this.divs_content.offsetHeight; this.divs_shadow.style.left = (this.divs_content.style.left.replace('px','')/1 + this.shadowOffset) + 'px'; this.divs_shadow.style.top = (this.divs_content.style.top.replace('px','')/1 + this.shadowOffset) + 'px'; this.divs_shadow.style.height = tmpHeight + 'px'; this.divs_shadow.style.width = tmpWidth + 'px'; if(runningInIE()){ this.iframe.style.left = this.divs_content.style.left; this.iframe.style.top = this.divs_content.style.top; this.iframe.style.width = this.divs_content.style.width; this.iframe.style.height = this.divs_content.style.height; } this.divs_shadow.style.display='block'; } else if(this.divs_shadow) { this.divs_shadow.style.display='none'; if(runningInIE()){ this.iframe.style.display='none'; } } } , /** * Resize the message divs * @private */ __resizeDivs : function(doCenter,widthOffset) { var topOffset = Math.max(document.body.scrollTop,document.documentElement.scrollTop); if(this.cssClassOfMessageBox) this.divs_content.className=this.cssClassOfMessageBox; else this.divs_content.className='modalDialog_contentDiv'; if(!this.divs_transparentDiv) { return; } // Preserve scroll position var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop); var sl = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft); window.scrollTo(sl,st); setTimeout('window.scrollTo(' + sl + ',' + st + ');',10); this.__repositionTransparentDiv(); // Setting width and height of content div this.divs_content.style.width = (this.width-widthOffset) + 'px'; this.divs_content.style.height= this.height + 'px'; // centering dialog if(doCenter) { var tmpWidth = this.divs_content.offsetWidth; var tmpHeight = this.divs_content.offsetHeight; var bodyWidth = document.viewport.getWidth(); var bodyHeight = document.viewport.getHeight(); this.divs_content.style.left = Math.ceil((bodyWidth - tmpWidth) / 2) + 'px'; this.divs_content.style.top = (Math.ceil((bodyHeight - tmpHeight) / 2) + topOffset) + 'px'; } this.redrawShadow(); } , /** * Insert content into the content div * @private */ __repositionTransparentDiv : function() { this.divs_transparentDiv.style.top = Math.max(document.body.scrollTop,document.documentElement.scrollTop) + 'px'; this.divs_transparentDiv.style.left = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft) + 'px'; this.divs_transparentDiv.style.width = document.viewport.getWidth() + 'px'; this.divs_transparentDiv.style.height = document.viewport.getHeight() + 'px'; } , /** * Insert content into the content div * @private */ __insertContent : function() { if(this.url){ // url specified - load content dynamically ajax_loadContent("modalBox_contentDiv",this.url); } else { // no url set, put static content inside the message box this.divs_content.innerHTML = this.wrapTitleAndContent(this.htmlOfModalMessage); setTimeout("modalDialog.checkWrapperSize()",50); } } , relativeResize : function(widthDelta,heightDelta,doCenter) { this.setSize($("modalBox_contentDiv").getWidth()+widthDelta,$("modalBox_contentDiv").getHeight()+heightDelta); if($("modalDialog_title")!=null) { $("dialogWrapperDiv").style.width=$("dialogWrapperDiv").getWidth()+widthDelta+"px"; $("dialogWrapperDiv").style.height=$("dialogWrapperDiv").getHeight()+heightDelta+"px"; } if($("modalDialog_title_content")!=null) { $("modalDialog_title_content").style.width=$("modalDialog_title_content").getWidth()+widthDelta+"px"; $("modalDialog_title_content").style.height=$("modalDialog_title_content").getHeight()+heightDelta+"px"; } if(typeof doCenter == "undefined") { doCenter=false; } modalDialog.__resizeDivs(doCenter,4); } , setTitle : function(newTitle) { this.title=newTitle; } , setCloseFunction : function(newCloseFunction) { this.closeFunction=newCloseFunction; } , setCloseTitle : function(newCloseTitle) { this.closeTitle=newCloseTitle; } , wrapTitleAndContent : function(dialogContent) { if(this.title!="") { if(this.closeFunction=="") { var theCloseFunction="modalDialog.close()"; } else { var theCloseFunction=this.closeFunction; } if(this.closeTitle=="") { var theCloseTitle="Cancel"; } else { var theCloseTitle=this.closeTitle; } var result="
"+ "
"+ ""+ "
"+ ""+this.title+""+ "
"+ "
"; if(!this.noPopupMsg) { result+=""; } result+=dialogContent+"
"; } result="
"+result; if(this.resizable) { result+=""; } result+="
"; if(this.draggable || this.resizable) { setTimeout("modalDialog.makeDraggOrResizable()",100); } if(this.completionCallback!=null) { setTimeout("modalDialog.callCompletionCallback()",50); } return result; } ,callCompletionCallback : function() { eval("modalDialog.completionCallback()"); } , makeDraggOrResizable : function() { if(this.draggable) { new Draggable("modalBox_contentDiv",{ revert:false, onStart:function() { modalDialog.setShadowVisible(false); }, onEnd: function() { modalDialog.setShadowVisible(true); }, handle: "modalDialog_title" }); } if(this.resizable) { new Resizeable("modalBox_contentDiv",{ onStart : function() { modalDialog.setShadowVisible(false); }, onEnd : function() { modalDialog.setShadowVisible(true); }, extraDiv : "dialogWrapperDiv", callback : function() { modalDialog.overflowResize(); } }); } } , checkWrapperSize : function() { if($("dialogWrapperDiv")!=null) { var wrapperWidth=$("dialogWrapperDiv").scrollWidth; var deltaWidth=0; var bodyWidth = document.viewport.getWidth()-20; if(wrapperWidth>this.width) { wrapperWidth+=20; if(wrapperWidth > bodyWidth) { deltaWidth=bodyWidth-this.width; } else { deltaWidth=wrapperWidth-this.width; } } var wrapperHeight=$("dialogWrapperDiv").scrollHeight; var deltaHeight=0; var bodyHeight = document.viewport.getHeight()-20; if(wrapperHeight>this.height) { wrapperHeight+=20; if(wrapperHeight>bodyHeight) { deltaHeight=bodyHeight-this.height; } else { deltaHeight=wrapperHeight-this.height; } } if(deltaWidth!=0 || deltaHeight!=0) { this.relativeResize(deltaWidth,deltaHeight,true); } } } , overflowResize : function() { var overflowDiv=$("dialog_overflow"); if(overflowDiv!=null) { overflowDiv.style.height=($("modalBox_contentDiv").getHeight()-$("modalDialog_title").getHeight()-30) +"px"; } } } function displayDialog(dialogContent,width,height,paramMap) { modalDialog = new ModalMessage(); modalDialog.setHtmlContent(dialogContent); modalDialog.setSource(false); _displayDialog(width,height,paramMap); } function displayDialogExt(sourceURL,width,height,paramMap) { modalDialog = new ModalMessage(); modalDialog.setSource(sourceURL); _displayDialog(width,height,paramMap); } function _displayDialog(width,height,paramMap) { modalDialog.setSize(width,height); if(typeof paramMap == "object") { if(typeof paramMap.cssClass == "string" && paramMap.cssClass!="") { modalDialog.setCssClassMessageBox(paramMap.cssClass); } if(typeof paramMap.title == "string" && paramMap.title!="") { modalDialog.setTitle(paramMap.title); modalDialog.setCssClassMessageBox("modalDialog_title_all"); } if(typeof paramMap.fast == "boolean" && paramMap.fast==true) { modalDialog.fast=paramMap.fast; } if(typeof paramMap.notDraggable == "boolean" && paramMap.notDraggable==true) { modalDialog.draggable=false; } if(typeof paramMap.resizable == "boolean" && paramMap.resizable==true) { modalDialog.resizable=true; } if(typeof paramMap.noPopupMsg == "boolean" && paramMap.noPopupMsg==true) { modalDialog.noPopupMsg=true; } if(typeof paramMap.closeFunction == "string" && paramMap.closeFunction!="") { modalDialog.setCloseFunction(paramMap.closeFunction); } if(typeof paramMap.closeTitle == "string" && paramMap.closeTitle!="") { modalDialog.setCloseTitle(paramMap.closeTitle); } if(typeof paramMap.completionCallback == "function") { modalDialog.completionCallback=paramMap.completionCallback; } } modalDialog.popMsg=false; modalDialog.display(); modalDialog.setShadowVisible(true); Event.observe(document,"keypress",keypressListener); } function checkDialogSize() { if(modalDialog!=null) { modalDialog.checkWrapperSize(); } } function keypressListener(event) { if(typeof modalDialog != "undefined") { if(!event && typeof event != "undefined") { event = event.keyCode; } if (event==Event.KEY_ESC || event.keyCode==Event.KEY_ESC) { if(modalDialog.closeFunction!="") { eval(modalDialog.closeFunction); } else { modalDialog.close(); } } if(typeof nd == "function") { nd(); } } } function ajax_loadContent(divId,url) { var innerHTML="   Loading content - Please wait."; if($(divId).getWidth()>140 && $(divId).getHeight()>150) { var offsetX=$(divId).getWidth() / 2 - 45; var offsetY=$(divId).getHeight() / 2 - 45; innerHTML+= "
"+ ""+ "
"; } $(divId).innerHTML = innerHTML; if(url.indexOf("?")==-1) { url+="?dialog_rnd_id="+Math.random(); } else { url+="&dialog_rnd_id="+Math.random(); } new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { var targetObj = $(divId); targetObj.innerHTML = modalDialog.wrapTitleAndContent(transport.responseText); setTimeout("modalDialog.checkWrapperSize()",50); ajax_parseJs(targetObj) }.bind(this) }); } function ajax_parseJs(obj) { var scriptTags = obj.getElementsByTagName('script'); var jsCode = ''; for(var no=0;no=0){ jsCode = jsCode + scriptTags[no].text + '\n'; } else { jsCode = jsCode + scriptTags[no].innerHTML; } } } if(jsCode)ajax_installScript(jsCode); } function ajax_installScript(script) { if (!script) return; if (window.execScript) { window.execScript(script) }else { window.setTimeout(script,0); } } function evaluateCss(obj) { var cssTags = obj.getElementsByTagName('style'); var head = document.getElementsByTagName('head')[0]; for(var no=0;no