📄 bbsxp_modal.js
字号:
BBSXP_Modal = new Object();
BBSXP_Modal._variableName = 'BBSXP_Modal';
BBSXP_Modal.LoadingHtmlUrl = null;
BBSXP_Modal.WindowCssClasses = new Array();
BBSXP_Modal.WindowTitleCssClasses = new Array();
BBSXP_Modal.WindowCloseCssClasses = new Array();
BBSXP_Modal.WindowContentCssClasses = new Array();
BBSXP_Modal.WindowMaskCssClasses = new Array();
BBSXP_Modal.WindowFooterCssClasses = new Array();
BBSXP_Modal.WindowResizeCssClasses = new Array();
BBSXP_Modal.ZIndex = 100;
BBSXP_Modal._isShown = false;
BBSXP_Modal._initialized = false;
BBSXP_Modal._modal = null;
BBSXP_Modal._modalTitle = null;
BBSXP_Modal._modalClose = null;
BBSXP_Modal._modalAnimationMask = null;
BBSXP_Modal._modalMask = null;
BBSXP_Modal._modalIframe = null;
BBSXP_Modal._modalResize = null;
BBSXP_Modal._modalFooter = null;
BBSXP_Modal._modalContent = null;
BBSXP_Modal._animationHandle = null;
BBSXP_Modal._isOpening = false;
BBSXP_Modal._hiddenSelects = null;
BBSXP_Modal._checkForScrollResizeHandle = null;
BBSXP_Modal._lastModalInfo = null;
BBSXP_Modal._lastWindowInfo = null;
BBSXP_Modal._isDragging = false;
BBSXP_Modal._moveModalInfo = null;
BBSXP_Modal._resizeModalInfo = null;
BBSXP_Modal._isResizing = false;
BBSXP_Modal.Configure = function(loadingHtmlUrl, windowCssClasses, windowTitleCssClasses, windowCloseCssClasses, windowContentCssClasses, windowFooterCssClasses, windowResizeCssClasses, windowMaskCssClasses, zIndex)
{
this.LoadingHtmlUrl = loadingHtmlUrl;
this.WindowCssClasses = windowCssClasses;
this.WindowTitleCssClasses = windowTitleCssClasses;
this.WindowCloseCssClasses = windowCloseCssClasses;
this.WindowContentCssClasses = windowContentCssClasses;
this.WindowMaskCssClasses = windowMaskCssClasses;
this.WindowFooterCssClasses = windowFooterCssClasses;
this.WindowResizeCssClasses = windowResizeCssClasses;
this.ZIndex = zIndex;
}
BBSXP_Modal.IsShown = function()
{
return this._isShown;
}
BBSXP_Modal._getWindowInfo = function()
{
var scrollX = 0, scrollY = 0, width = 0, height = 0, contentWidth = 0, contentHeight = 0;
if (typeof(window.pageXOffset) == 'number')
{
//Netscape compliant
scrollX = window.pageXOffset;
scrollY = window.pageYOffset;
}
else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
{
//DOM compliant
scrollX = document.body.scrollLeft;
scrollY = document.body.scrollTop;
}
else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
{
//IE6 standards compliant mode
scrollX = document.documentElement.scrollLeft;
scrollY = document.documentElement.scrollTop;
}
if (typeof(window.innerWidth) == 'number')
{
//Non-IE
width = window.innerWidth;
height = window.innerHeight;
}
else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
{
//IE 6+ in 'standards compliant mode'
width = document.documentElement.clientWidth;
height = document.documentElement.clientHeight;
}
else if (document.body && (document.body.clientWidth || document.body.clientHeight))
{
//IE 4 compatible
width = document.body.clientWidth;
height = document.body.clientHeight;
}
if (document.documentElement && (document.documentElement.scrollHeight || document.documentElement.offsetHeight))
{
if (document.documentElement.scrollHeight > document.documentElement.offsetHeight)
{
contentWidth = document.documentElement.scrollWidth;
contentHeight = document.documentElement.scrollHeight;
}
else
{
contentWidth = document.documentElement.offsetWidth;
contentHeight = document.documentElement.offsetHeight;
}
}
else if (document.body && (document.body.scrollHeight || document.body.offsetHeight))
{
if (document.body.scrollHeight > document.body.offsetHeight)
{
contentWidth = document.body.scrollWidth;
contentHeight = document.body.scrollHeight;
}
else
{
contentWidth = document.body.offsetWidth;
contentHeight = document.body.offsetHeight;
}
}
else
{
contentWidth = width;
contentHeight = height;
}
if (height > contentHeight)
height = contentHeight;
if (width > contentWidth)
width = contentWidth;
var rect = new Object();
rect.ScrollX = scrollX;
rect.ScrollY = scrollY;
rect.Width = width;
rect.Height = height;
rect.ContentWidth = contentWidth;
rect.ContentHeight = contentHeight;
return rect;
}
BBSXP_Modal._getCurrentStyleValue = function(element, styleRule, jsStyleRule)
{
var value = 0;
if(document.defaultView && document.defaultView.getComputedStyle)
value = parseInt(document.defaultView.getComputedStyle(element, "").getPropertyValue(styleRule), 0);
else if(element.currentStyle)
value = parseInt(element.currentStyle[jsStyleRule], 0);
if (!isNaN(value))
return value;
else
return 0;
}
BBSXP_Modal._calculateStyleOffset = function(element)
{
var result = new Object();
result.Height = this._getCurrentStyleValue(element, 'border-top-width', 'borderTopWidth') +
this._getCurrentStyleValue(element, 'border-bottom-width', 'borderBottomWidth') +
this._getCurrentStyleValue(element, 'padding-top', 'paddingTop') +
this._getCurrentStyleValue(element, 'padding-bottom', 'paddingBottom');
result.Width = this._getCurrentStyleValue(element, 'border-left-width', 'borderLeftWidth') +
this._getCurrentStyleValue(element, 'border-right-width', 'borderRightWidth') +
this._getCurrentStyleValue(element, 'padding-left', 'paddingLeft') +
this._getCurrentStyleValue(element, 'padding-right', 'paddingRight');
return result;
}
BBSXP_Modal.Open = function (url, width, height, onCloseFunction, x, y, ignoreCloseAndAnimation)
{
if (!ignoreCloseAndAnimation && this._isShown)
this.Close();
else if (this._hiddenSelects)
{
for (var i = 0; i < this._hiddenSelects.length; i++)
{
if (this._hiddenSelects[i].Element.style.visibility == 'hidden')
this._hiddenSelects[i].Element.style.visibility = this._hiddenSelects[i].Visibility;
}
this._hiddenSelects = null;
}
if (!this._initialized)
this._initialize();
try
{
this._modalTitle.childNodes[1].innerHTML = this._modalIframe.contentWindow.document.title;
}
catch (err)
{
}
if (!ignoreCloseAndAnimation)
this._modalIframe.src = url;
try
{
this._modalIframe.contentWindow.opener = window;
}
catch (err)
{
}
this._modalAnimationMask.style.display = 'none';
this._modalMask.style.display = 'none';
// retrieve the window info
this._lastWindowInfo = this._getWindowInfo();
this._modalAnimationMask.style.display = 'block';
// width/height of panel
if (width > this._lastWindowInfo.Width)
width = this._lastWindowInfo.Width;
this._modalAnimationMask.style.position = 'absolute';
this._modalAnimationMask.style.zIndex = this.ZIndex;
this._modalAnimationMask.style.display = 'block';
this._modalAnimationMask.style.visibility = 'hidden';
this._modalAnimationMask.style.overflow = 'hidden';
this._modalAnimationMask.style.width = width + 'px';
this._modalContent.style.width = width + 'px';
this._modal.style.position = 'absolute';
this._modal.style.display = 'block';
this._modal.style.visibility = 'hidden';
this._modal.style.left = '0px';
this._modal.style.top = '0px';
this._modalMask.style.position = 'absolute';
this._modalMask.style.display = 'block';
this._modalMask.style.zIndex = this.ZIndex;
this._modalMask.style.visibility = 'visible';
var modalContentOffset = this._calculateStyleOffset(this._modalContent);
var offset = (this._modal.offsetHeight - this._modalContent.offsetHeight) - modalContentOffset.Height;
if (height + offset > this._lastWindowInfo.Height)
height = this._lastWindowInfo.Height - offset;
if (width < this._modalResize.offsetWidth * 2)
width = this._modalResize.offsetWidth * 2;
if (width < this._modalClose.offsetWidth * 2)
width = this._modalClose.offsetWidth * 2;
if (height < this._modalTitle.offsetHeight + this._modalFooter.offsetHeight)
height = this._modalTitle.offsetHeight + this._modalFooter.offsetHeight;
this._modalIframe.style.height = height + 'px';
this._modalContent.style.height = height + 'px';
this._modalContent.style.width = (width - (this._modal.offsetWidth - this._modalContent.offsetWidth) - modalContentOffset.Width) + 'px';
this._modalAnimationMask.style.width = width + 'px';
this._modalAnimationMask.style.height = this._modal.offsetHeight + 'px';
this._modalMask.style.left = '0px';
this._modalMask.style.top = '0px';
this._modalMask.style.width = this._lastWindowInfo.ContentWidth + 'px';
this._modalMask.style.height = this._lastWindowInfo.ContentHeight + 'px';
this._lastWindowInfo = this._getWindowInfo();
var panelWidth = this._modal.offsetWidth;
var panelHeight = this._modal.offsetHeight;
var animatePropertyName, animateTargetValue, animateNextValue;
if (typeof(x) == 'undefined' || isNaN(parseInt(x, 10)))
x = ((this._lastWindowInfo.Width - panelWidth) / 2) + this._lastWindowInfo.ScrollX;
if (x + panelWidth > this._lastWindowInfo.Width + this._lastWindowInfo.ScrollX)
x = this._lastWindowInfo.Width + this._lastWindowInfo.ScrollX - panelWidth;
if (x < this._lastWindowInfo.ScrollX)
x = this._lastWindowInfo.ScrollX;
if (typeof(y) == 'undefined' || isNaN(parseInt(y, 10)))
y = ((this._lastWindowInfo.Height - panelHeight) / 2) + this._lastWindowInfo.ScrollY;
if (y + panelHeight > this._lastWindowInfo.Height + this._lastWindowInfo.ScrollY)
y = this._lastWindowInfo.Height + this._lastWindowInfo.ScrollY - panelHeight;
if (y < this._lastWindowInfo.ScrollY)
y = this._lastWindowInfo.ScrollY;
this._modalAnimationMask.style.left = x + 'px';
this._modalAnimationMask.style.top = y + 'px';
animateTargetValue = 0;
animateNextValue = -panelHeight;
this._modal.style.visibility = 'visible';
this._modalAnimationMask.style.visibility = 'visible';
this._modalAnimationMask.style.overflow = 'hidden';
// detect and hide select boxes
if (this._modalAnimationMask.getClientRects)
{
var selectBoxes = document.getElementsByTagName('select');
this._hiddenSelects = new Array();
for (var i = 0; i < selectBoxes.length; i++)
{
this._hiddenSelects[this._hiddenSelects.length] = { Element: selectBoxes[i], Visibility: selectBoxes[i].style.visibility };
selectBoxes[i].style.visibility = 'hidden';
}
}
this._isOpening = true;
if (ignoreCloseAndAnimation)
this._animationHandle = window.setTimeout(new Function(this._variableName + '._animate(0,0,0,0);'), 9);
else
{
this._modalIframe.style.display = 'none';
this._animate(0, -panelHeight, panelHeight / 3, .67);
}
this._lastModalInfo = { Url : this._modalIframe.src, OnCloseFunction : onCloseFunction, X : x, Y : y, Width : parseInt(width, 10), Height: parseInt(height, 10) };
this._isShown = true;
}
BBSXP_Modal._checkForScrollResize = function()
{
if (this._checkForScrollResizeHandle)
window.clearTimeout(this._checkForScrollResizeHandle);
if (this._isShown && !this._isOpening && this._lastWindowInfo)
{
try
{
this._modalTitle.childNodes[1].innerHTML = this._modalIframe.contentWindow.document.title;
}
catch (err)
{
}
var windowInfo = this._getWindowInfo();
if (windowInfo.ScrollX != this._lastWindowInfo.ScrollX || windowInfo.ScrollY != this._lastWindowInfo.ScrollY || windowInfo.Width != this._lastWindowInfo.Width || windowInfo.Height != this._lastWindowInfo.Height)
this.Open(null, this._lastModalInfo.Width, this._lastModalInfo.Height, this._lastModalInfo.OnCloseFunction, this._lastModalInfo.X, this._lastModalInfo.Y, true);
else
this._checkForScrollResizeHandle = window.setTimeout(new Function('window.' + this._variableName + '._checkForScrollResize();'), 999);
}
}
BBSXP_Modal.Close = function(returnValue)
{
if (this._isShown)
{
if (!this._initialized)
this._initialize();
this._modal.style.position = 'absolute';
this._modal.style.display = 'none';
this._modalAnimationMask.style.position = 'absolute';
this._modalAnimationMask.style.display = 'none';
this._modalMask.style.position = 'absolute';
this._modalMask.style.display = 'none';
this._modalIframe.src = this.LoadingHtmlUrl;
var onCloseFunction = this._lastModalInfo.OnCloseFunction;
this._isShown = false;
this._lastModalInfo = null;
this._windowInfo = null;
if (this._hiddenSelects)
{
for (var i = 0; i < this._hiddenSelects.length; i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -