function createPopup(url, width, height) { document.popup = new Popup(url, width, height); document.popup.show(); } function destroyPopup() { document.popup.hide(); } function Popup(newURL, newWidth, newHeight) { document.PopperdePopup = this; this.id = 'popupeddiv'; this.overlayId = 'overlayeddiv'; this.url = newURL; this.width = newWidth; this.height = newHeight; this.windowWidth = -1; this.windowHeight = -1; this.scrollLeft = 0; this.scrollTop = 0; this.body = null; this.iframe = ''; this.iframeid = 'popupediframe'; if (typeof(_Popup_prototype_called) == 'undefined') { _Popup_prototype_called = true; Popup.prototype.show = show; Popup.prototype.hide = hide; Popup.prototype.repaint = repaint; Popup.prototype.showOverlay = showOverlay; Popup.prototype.hideOverlay = hideOverlay; Popup.prototype.getPageSize = getPageSize; Popup.prototype.getScrollPosition = getScrollPosition; if (window.addEventListener) { // Standard window.addEventListener('resize', repaint, false); window.addEventListener('scroll', repaint, false); } else if (window.attachEvent) { // IE window.attachEvent('onresize', repaint); window.attachEvent('onscroll', repaint); } } function getPageSize() { if (self.innerHeight) { // Standard this.windowWidth = self.innerWidth; this.windowHeight = self.innerHeight; // BUG: in firefox the width and height are a bit too big when scrollbars are visible. } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode this.windowWidth = document.documentElement.clientWidth; this.windowHeight = document.documentElement.clientHeight; } else if (document.body) { // other Explorers this.windowWidth = document.body.clientWidth; this.windowHeight = document.body.clientHeight; } } function getScrollPosition() { this.scrollTop = typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement.scrollTop; this.scrollLeft = typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement.scrollLeft; this.scrollTop = document.body.scrollTop > 0 ? document.body.scrollTop : this.scrollTop; this.scrollLeft = document.body.scrollLeft > 0 ? document.body.scrollLeft : this.scrollLeft; } function getMaxZIndex() { var maxZIndex = 0; var elements = document.getElementsByTagName('*'); for (i = 0; i < elements.length; i++) { var element = elements[i]; var zindex; if (element.currentStyle) zindex = element.currentStyle.zIndex; else if (document.defaultView) zindex = document.defaultView.getComputedStyle(element, null).getPropertyValue('z-index'); if (!isNaN(zindex)) { if (zindex > maxZIndex) maxZIndex = zindex; } } return ++maxZIndex; } function setOpacity(obj, opacity) { opacity = (opacity == 100) ? 99.999 : opacity; // IE/Win obj.style.filter = 'alpha(opacity:' + opacity + ')'; // Safari<1.2, Konqueror obj.style.KHTMLopacity = opacity/100; // Older Mozilla and Firefox obj.style.Mozopacity = opacity/100; // Safari 1.2, newer Firefox and Mozilla, CSS3 obj.style.opacity = opacity/100; } function showOverlay() { // Create div. var newDiv = document.createElement('div'); newDiv.setAttribute('id', this.overlayId); // Style new div. newDiv.style.position = 'absolute'; newDiv.style.left = this.scrollLeft + 'px'; newDiv.style.top = this.scrollTop + 'px'; newDiv.style.width = this.windowWidth + 'px'; newDiv.style.height = this.windowHeight + 'px'; newDiv.style.zIndex = getMaxZIndex(); newDiv.style.backgroundColor = '#CCCCCC'; newDiv.style.visibility = 'visible'; setOpacity(newDiv, 50); document.body.appendChild(newDiv); } function hideOverlay() { // Remove div. var overlayDiv = document.getElementById(this.overlayId); document.body.removeChild(overlayDiv); } function show() { var popupDiv = document.getElementById(this.id); if (popupDiv != null) return; this.getPageSize(); this.getScrollPosition(); this.showOverlay(); var separator = (this.url.indexOf('?') == -1 ? '?' : '&'); var url = this.url + separator + 'nocache=' + new Date().getTime(); // Get content. ajaxConnection = new AJAXConnection(url); ajaxConnection.get(); this.body = this.iframe + ajaxConnection.getResponseText(); // Create div. var newDiv = document.createElement('div'); document.body.appendChild(newDiv); newDiv.setAttribute('id', this.id); newDiv.innerHTML = this.body; // Style new div. newDiv.style.display = 'block'; newDiv.style.visibility = 'visible'; newDiv.style.position = 'absolute'; if (this.width == null || this.height == null) { // Get size of popup content. this.width = newDiv.offsetWidth; this.height = newDiv.offsetHeight; } newDiv.style.left = ((this.windowWidth / 2) - (this.width / 2)) + this.scrollLeft + 'px'; newDiv.style.top = ((this.windowHeight / 2) - (this.height / 2)) + this.scrollTop + 'px'; newDiv.style.zIndex = getMaxZIndex(); // Set size to helper iframe. document.getElementById(this.iframeid).style.width = this.width + 'px'; document.getElementById(this.iframeid).style.height = this.height + 'px'; } function hide() { this.hideOverlay(); // Remove div. var popupDiv = document.getElementById(this.id); document.body.removeChild(popupDiv); } function repaint() { // BUG: in firefox it's possible to keep scrolling. var p = document.PopperdePopup; p.getPageSize(); p.getScrollPosition(); // Resize and relocate overlay div. var overlayDiv = document.getElementById(p.overlayId); if (overlayDiv != null) { overlayDiv.style.left = p.scrollLeft + 'px'; overlayDiv.style.top = p.scrollTop + 'px'; overlayDiv.style.width = p.windowWidth + 'px'; overlayDiv.style.height = p.windowHeight + 'px'; } // Relocate popup div. var popupDiv = document.getElementById(p.id); if (popupDiv != null) { if (p.width == null || p.height == null) { // Get width of popup content. p.width = popupDiv.offsetWidth; p.height = popupDiv.offsetHeight; } popupDiv.style.left = ((p.windowWidth / 2) - (p.width / 2)) + 'px'; popupDiv.style.top = ((p.windowHeight / 2) - (p.height / 2)) + 'px'; } } }