/* 蜗牛谷模态同步处理JS 需要使用woniugu_core.js文件 Table of Contents ----------------- Configuration Functions - getPageScroll() - getPageSize() - pause() - getKey() - listenKey() - showLightbox() - hideLightbox() - initLightbox() - addLoadEvent() Function Calls - addLoadEvent(initLightbox) */ function TmwLightBox(){ this.LoadingImage = 'loading.gif'; this.OverlayImage = 'overlay.png'; this.BasePath = ''; this.zIndex =999; this._objLightbox = null; this._objOverlay = null; this._objOverlayFrame = null; } TmwLightBox.prototype.Author = 'dypher@gmail.com'; // getPageScroll() // Returns array with x,y page scroll values. TmwLightBox.prototype.getPageScroll = function getPageScroll(){ var yScroll; if (self.pageYOffset) { yScroll = self.pageYOffset; } else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict yScroll = document.documentElement.scrollTop; } else if (document.body) {// all other Explorers yScroll = document.body.scrollTop; } arrayPageScroll = new Array('',yScroll) return arrayPageScroll; } // getPageSize() // Returns array with page width, height and window width, height TmwLightBox.prototype.getPageSize = function(){ var xScroll, yScroll; if (window.innerHeight && window.scrollMaxY) { xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; } var windowWidth, windowHeight; if (self.innerHeight) { // all except Explorer windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { // other Explorers windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; } // for small pages with total height less then height of the viewport if(yScroll < windowHeight){ pageHeight = windowHeight; } else { pageHeight = yScroll; } // for small pages with total width less then width of the viewport if(xScroll < windowWidth){ pageWidth = windowWidth; } else { pageWidth = xScroll; } arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) return arrayPageSize; } TmwLightBox.prototype.Create = function(){ if (!document.getElementsByTagName){ return; } // the rest of this code inserts html at the top of the page that looks like this: // //
//
// var objBody = document.getElementsByTagName("body").item(0); // create overlay div and hardcode some functional styles (aesthetic styles are in CSS file) this._objOverlay = document.createElement("div"); this._objOverlay.setAttribute('id','overlay'); this._objOverlay.style.display = 'none'; this._objOverlay.style.zIndex = this.zIndex + 1; this._objOverlay.style.position = 'absolute'; this._objOverlay.style.top = '0px'; this._objOverlay.style.left = '0px'; this._objOverlay.style.width = '100%'; this._objOverlay.style.height = '100%'; objBody.insertBefore(this._objOverlay, objBody.firstChild); // create overlay iframe and hardcode some functional styles (aesthetic styles are in CSS file) this._objOverlayFrame = document.createElement("iframe"); //this._objOverlayFrame.setAttribute('id','overlayframe'); this._objOverlayFrame.style.display = 'none'; this._objOverlayFrame.style.zIndex = this.zIndex ; if (navigator.appVersion.indexOf("MSIE")!=-1) { this._objOverlayFrame.style.filter = 'Alpha(Opacity=75,Finishopacity=75)'; } else { this._objOverlayFrame.style.backgroundColor = 'transparent'; } this._objOverlayFrame.style.position = 'absolute'; this._objOverlayFrame.style.top = '0px'; this._objOverlayFrame.style.left = '0px'; this._objOverlayFrame.style.width = '100%'; this._objOverlayFrame.style.height = '100%'; objBody.insertBefore(this._objOverlayFrame, objBody.firstChild); var arrayPageSize = this.getPageSize(); var arrayPageScroll = this.getPageScroll(); // create lightbox div, same note about styles as above this._objLightbox = document.createElement("div"); this._objLightbox.setAttribute('id','lightbox'); this._objLightbox.style.display = 'none'; this._objLightbox.style.position = 'absolute'; this._objLightbox.style.zIndex = this.zIndex + 2; objBody.insertBefore(this._objLightbox, this._objOverlay.nextSibling); } TmwLightBox.prototype.ShowLoadingBox = function(imgSrc){ var imgFile = imgSrc; if(imgSrc==undefined) imgFile = this.LoadingImage; var LoadingImageHtml = ''; var objLoadingImage = new Image(); objLoadingImage.src = imgFile; this.ShowLightboxContent(LoadingImageHtml, objLoadingImage.width, objLoadingImage.height ); } // pause(numberMillis) // Pauses code execution for specified time. Uses busy code, not good. TmwLightBox.prototype.pause = function(numberMillis) { var now = new Date(); var exitTime = now.getTime() + numberMillis; while (true) { now = new Date(); if (now.getTime() > exitTime) return; } } TmwLightBox.prototype.ShowDialog = function(title,content, width, height) { var _objContent = document.createElement("div"); var _divTop1 = document.createElement("div"); _divTop1.style.cssText = "height:1px;margin:0 2px;font-size:1px;line-height:1px;background:#888"; _objContent.appendChild(_divTop1); var _divTop2 = document.createElement("div"); _divTop2.style.cssText = "height:1px;font-size:1px;line-height:1px;background:#888;margin:0 1px;border-left:1px solid #888;border-right:1px solid #555"; _objContent.appendChild(_divTop2); var _divTitleBar = document.createElement("div"); _divTitleBar.style.cssText = "margin:0 0;border-left:1px solid #888;border-right:1px solid #555;background:#888;min-height:14px;padding:2px 6px 3px 6px;font-size:100%;color:#fff"; _divTitleBar.innerText = title; _objContent.appendChild(_divTitleBar); var _divContent = document.createElement("div"); _divContent.style.cssText = "margin:0 0;border-left:1px solid #888;border-right:1px solid #555;background:#eee;padding:5px 6px 3px 6px"; if (typeof(content)=="object") { _divContent.appendChild(content); } else { //_divContent.innerHTML = content; setInnerHTML(_divContent, content); } _objContent.appendChild(_divContent); var _divBot2 = document.createElement("div"); _divBot2.style.cssText = "height:1px;font-size:1px;line-height:1px;background:#eee;margin:0 1px;border-left:1px solid #888;border-right:1px solid #555"; _objContent.appendChild(_divBot2); var _divBot1 = document.createElement("div"); _divBot1.style.cssText = "height:1px;margin:0 2px;font-size:1px;line-height:1px;background:#555;"; _objContent.appendChild(_divBot1); this.ShowLightboxContent(_objContent, width, height ); } TmwLightBox.prototype.ShowDialogNew = function(content, width, height) { var _objContent = document.createElement("div"); if (typeof(content)=="object") { _objContent.appendChild(content); } else { //_divContent.innerHTML = content; setInnerHTML(_objContent, content); } this.ShowLightboxContent(_objContent, width, height ); } TmwLightBox.prototype.ShowLightboxContent = function(content, width, height) { var arrayPageSize = this.getPageSize(); var arrayPageScroll = this.getPageScroll(); // set height of Overlay to take up whole page and show this._objOverlay.style.height = (arrayPageSize[1] + 'px'); this._objOverlay.style.display = 'block'; this._objOverlayFrame.style.height = this._objOverlay.style.height; this._objOverlayFrame.style.display = 'block'; if (navigator.appVersion.indexOf("MSIE")!=-1) { //this._objOverlay.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader( src= "'+this.OverlayImage+'" , sizingMethod= "scale" )'; } else { this._objOverlay.style.backgroundImage = 'url('+this.OverlayImage+')'; this._objOverlay.style.backgroundRepeat = 'repeat'; this._objOverlay.style.backgroundAttachment = 'fixed'; } // center lightbox and make sure that the top and left values are not negative // and the image placed outside the viewport var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - height) / 2); var lightboxLeft = ((arrayPageSize[0] - 20 - width) / 2); this._objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px"; this._objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px"; this._objLightbox.style.width = width + 'px'; setInnerHTML(this._objLightbox, content); //使用woniugu_core.js中setInnerHTML函数 //this._objLightbox.innerHTML = content; // A small pause between the image loading and displaying is required with IE, // this prevents the previous image displaying for a short burst causing flicker. this._objLightbox.style.display = 'block'; } // hideLightbox() TmwLightBox.prototype.hideLightbox = function() { this._objOverlay.style.display = 'none'; this._objOverlayFrame.style.display = 'none'; this._objLightbox.style.display = 'none'; } TmwLightBox.prototype.showLightbox = function() { this._objOverlay.style.display = ''; this._objOverlayFrame.style.display = ''; this._objLightbox.style.display = ''; }