//---------------------------------------------------------------- /** * Description class to load and manage the multiple div elements * @author christoph.ruggenthaler@andritz.com * @createdate 20.09.2007 christoph.ruggenthaler@andritz.com * @change */ function Overlay() { //Private members var pos_top = 100; var pos_left = 200; var curr_id = 'new'; var curr_index = 0; var boolWorking = false; var element_move_enable = false; var element_move = ''; //---------------------------------------------------------------- /** * Ajax function to fetch the content from the given url */ function getOverlayElement(link) { link = "ajax_render-overlay?loadDoc=" + link; new Ajax.Request(link, {onSuccess:succOverlayElement, onFailure:failedOverlayElement}); } function succOverlayElement(t) { Element.hide('overlayError'); updateOverlay(t.responseText); } function failedOverlayElement(t) { Element.update('overlayError', 'Error communicating with the server: ' + t.responseText.stripTags()); Element.show('overlayError'); boolWorking = false; } //---------------------------------------------------------------- /** * Get the corresponding div element and update its content */ function updateOverlay(content) { var currContainer = document.getElementById(curr_id); var newContent = content.replace(/CURR_ID/g, curr_id); Element.update(curr_id, newContent); Element.show(curr_id); boolWorking = false; } //---------------------------------------------------------------- /** * Function which decides whether the object is already loaded -> show * otherwise fetch the object and prepare a new div container for the content */ this.loadOverlay = function(completeLink) { var anchor = completeLink.split('#'); anchor = anchor[anchor.length-1]; if(document.getElementById(completeLink)) { var currContainer = document.getElementById(completeLink); if(currContainer) { currContainer.style.left = parseInt(pos_left - 10)+ 'px'; currContainer.style.top = parseInt(pos_top - 10) + 'px'; } Element.show(completeLink); } else if(completeLink && !boolWorking) { boolWorking = true; curr_id = completeLink; if(!document.getElementById('overlayContainer_' + curr_index)) { document.getElementById('footer').innerHTML += ''; } var currContainer = document.getElementById("overlayContainer_" + curr_index); if(currContainer) { currContainer.style.left = parseInt(pos_left - 10)+ 'px'; currContainer.style.top = parseInt(pos_top - 10) + 'px'; currContainer.id = curr_id; curr_index = curr_index + 1; getOverlayElement(anchor); } } } //---------------------------------------------------------------- /** * Handle the move operation of any div element */ this.moveElement = function(div, enable) { if(element_move_enable) { var currContainer = document.getElementById(element_move); if(currContainer) { currContainer.style.left = parseInt(pos_left- 30)+ 'px'; currContainer.style.top = parseInt(pos_top - 12) + 'px'; } } if(div) { element_move_enable = enable; element_move = div; } } //---------------------------------------------------------------- /** * Update the position if the mouse moves */ this.updatePosition = function(event) { // IE if(window.event && window.event.clientX && window.event.clientY) { pos_top = parseInt(window.event.clientY + document.body.scrollTop); pos_left = parseInt(window.event.clientX + document.body.scrollLeft); } // Firefox else if(event && event.clientX && event.clientY) { pos_top = parseInt(event.clientY + document.body.scrollTop); pos_left = parseInt(event.clientX + document.body.scrollLeft); } this.moveElement(); } //---------------------------------------------------------------- /** * Init function: write error div all overlayContainers */ this.init = function() { if(!document.getElementById('overlayError')) { document.write(''); } for(var ii=0; ii < 99; ii++) { if(!document.getElementById('overlayContainer_' + ii)) document.write(''); } } } var overlay = new Overlay(); overlay.init(); //---------------------------------------------------------------- /** * function for loading elements from the overlay class */ function overlayLoadElement(curr) { if(!overlay) overlay = new Overlay(); overlay.loadOverlay(curr.href); } //---------------------------------------------------------------- /** * function for moving elements from the overlay class */ function overlayMoveElement(currId) { if(!overlay) overlay = new Overlay(); overlay.moveElement(currId, true); } //---------------------------------------------------------------- /** * MouseMove event handler for the correct position */ document.onmousemove = function(event) { if(!overlay) overlay = new Overlay(); overlay.updatePosition(event); } //---------------------------------------------------------------- document.onmouseup = function() { if(!overlay) overlay = new Overlay(); overlay.moveElement('none', false); }