📄 window.js
字号:
if (this.element.style.zIndex < Windows.maxZIndex)
this.setZIndex(Windows.maxZIndex + 1);
if (this.iefix)
this._fixIEOverlapping();
},
getBounds: function(insideOnly) {
if (! this.width || !this.height || !this.visible)
this.computeBounds();
var w = this.width;
var h = this.height;
if (!insideOnly) {
w += this.widthW + this.widthE;
h += this.heightN + this.heightS;
}
var bounds = Object.extend(this.getLocation(), {width: w + "px", height: h + "px"});
return bounds;
},
computeBounds: function() {
if (! this.width || !this.height) {
var size = WindowUtilities._computeSize(this.content.innerHTML, this.content.id, this.width, this.height, 0, this.options.className)
if (this.height)
this.width = size + 5
else
this.height = size + 5
}
this.setSize(this.width, this.height);
if (this.centered)
this._center(this.centerTop, this.centerLeft);
},
// Displays window modal state or not
show: function(modal) {
this.visible = true;
if (modal) {
// Hack for Safari !!
if (typeof this.overlayOpacity == "undefined") {
var that = this;
setTimeout(function() {that.show(modal)}, 10);
return;
}
Windows.addModalWindow(this);
this.modal = true;
this.setZIndex(Windows.maxZIndex + 1);
Windows.unsetOverflow(this);
}
else
if (!this.element.style.zIndex)
this.setZIndex(Windows.maxZIndex + 1);
// To restore overflow if need be
if (this.oldStyle)
this.getContent().setStyle({overflow: this.oldStyle});
this.computeBounds();
this._notify("onBeforeShow");
if (this.options.showEffect != Element.show && this.options.showEffectOptions)
this.options.showEffect(this.element, this.options.showEffectOptions);
else
this.options.showEffect(this.element);
this._checkIEOverlapping();
WindowUtilities.focusedWindow = this
this._notify("onShow");
},
// Displays window modal state or not at the center of the page
showCenter: function(modal, top, left) {
this.centered = true;
this.centerTop = top;
this.centerLeft = left;
this.show(modal);
},
isVisible: function() {
return this.visible;
},
_center: function(top, left) {
var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);
var pageSize = WindowUtilities.getPageSize(this.options.parent);
if (typeof top == "undefined")
top = (pageSize.windowHeight - (this.height + this.heightN + this.heightS))/2;
top += windowScroll.top
if (typeof left == "undefined")
left = (pageSize.windowWidth - (this.width + this.widthW + this.widthE))/2;
left += windowScroll.left
this.setLocation(top, left);
this.toFront();
},
_recenter: function(event) {
if (this.centered) {
var pageSize = WindowUtilities.getPageSize(this.options.parent);
var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);
// Check for this stupid IE that sends dumb events
if (this.pageSize && this.pageSize.windowWidth == pageSize.windowWidth && this.pageSize.windowHeight == pageSize.windowHeight &&
this.windowScroll.left == windowScroll.left && this.windowScroll.top == windowScroll.top)
return;
this.pageSize = pageSize;
this.windowScroll = windowScroll;
// set height of Overlay to take up whole page and show
if ($('overlay_modal'))
$('overlay_modal').setStyle({height: (pageSize.pageHeight + 'px')});
if (this.options.recenterAuto)
this._center(this.centerTop, this.centerLeft);
}
},
// Hides window
hide: function() {
this.visible = false;
if (this.modal) {
Windows.removeModalWindow(this);
Windows.resetOverflow();
}
// To avoid bug on scrolling bar
this.oldStyle = this.getContent().getStyle('overflow') || "auto"
this.getContent().setStyle({overflow: "hidden"});
this.options.hideEffect(this.element, this.options.hideEffectOptions);
if(this.iefix)
this.iefix.hide();
if (!this.doNotNotifyHide)
this._notify("onHide");
},
close: function() {
// Asks closeCallback if exists
if (this.visible) {
if (this.options.closeCallback && ! this.options.closeCallback(this))
return;
if (this.options.destroyOnClose) {
var destroyFunc = this.destroy.bind(this);
if (this.options.hideEffectOptions.afterFinish) {
var func = this.options.hideEffectOptions.afterFinish;
this.options.hideEffectOptions.afterFinish = function() {func();destroyFunc() }
}
else
this.options.hideEffectOptions.afterFinish = function() {destroyFunc() }
}
Windows.updateFocusedWindow();
this.doNotNotifyHide = true;
this.hide();
this.doNotNotifyHide = false;
this._notify("onClose");
}
},
minimize: function() {
if (this.resizing)
return;
var r2 = $(this.getId() + "_row2");
if (!this.minimized) {
this.minimized = true;
var dh = r2.getDimensions().height;
this.r2Height = dh;
var h = this.element.getHeight() - dh;
if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
new Effect.ResizeWindow(this, null, null, null, this.height -dh, {duration: Window.resizeEffectDuration});
} else {
this.height -= dh;
this.element.setStyle({height: h + "px"});
r2.hide();
}
if (! this.useTop) {
var bottom = parseFloat(this.element.getStyle('bottom'));
this.element.setStyle({bottom: (bottom + dh) + 'px'});
}
}
else {
this.minimized = false;
var dh = this.r2Height;
this.r2Height = null;
if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
new Effect.ResizeWindow(this, null, null, null, this.height + dh, {duration: Window.resizeEffectDuration});
}
else {
var h = this.element.getHeight() + dh;
this.height += dh;
this.element.setStyle({height: h + "px"})
r2.show();
}
if (! this.useTop) {
var bottom = parseFloat(this.element.getStyle('bottom'));
this.element.setStyle({bottom: (bottom - dh) + 'px'});
}
this.toFront();
}
this._notify("onMinimize");
// Store new location/size if need be
this._saveCookie()
},
maximize: function() {
if (this.isMinimized() || this.resizing)
return;
if (Prototype.Browser.IE && this.heightN == 0)
this._getWindowBorderSize();
if (this.storedLocation != null) {
this._restoreLocation();
if(this.iefix)
this.iefix.hide();
}
else {
this._storeLocation();
Windows.unsetOverflow(this);
var windowScroll = WindowUtilities.getWindowScroll(this.options.parent);
var pageSize = WindowUtilities.getPageSize(this.options.parent);
var left = windowScroll.left;
var top = windowScroll.top;
if (this.options.parent != document.body) {
windowScroll = {top:0, left:0, bottom:0, right:0};
var dim = this.options.parent.getDimensions();
pageSize.windowWidth = dim.width;
pageSize.windowHeight = dim.height;
top = 0;
left = 0;
}
if (this.constraint) {
pageSize.windowWidth -= Math.max(0, this.constraintPad.left) + Math.max(0, this.constraintPad.right);
pageSize.windowHeight -= Math.max(0, this.constraintPad.top) + Math.max(0, this.constraintPad.bottom);
left += Math.max(0, this.constraintPad.left);
top += Math.max(0, this.constraintPad.top);
}
var width = pageSize.windowWidth - this.widthW - this.widthE;
var height= pageSize.windowHeight - this.heightN - this.heightS;
if (this.useLeft && this.useTop && Window.hasEffectLib && Effect.ResizeWindow) {
new Effect.ResizeWindow(this, top, left, width, height, {duration: Window.resizeEffectDuration});
}
else {
this.setSize(width, height);
this.element.setStyle(this.useLeft ? {left: left} : {right: left});
this.element.setStyle(this.useTop ? {top: top} : {bottom: top});
}
this.toFront();
if (this.iefix)
this._fixIEOverlapping();
}
this._notify("onMaximize");
// Store new location/size if need be
this._saveCookie()
},
isMinimized: function() {
return this.minimized;
},
isMaximized: function() {
return (this.storedLocation != null);
},
setOpacity: function(opacity) {
if (Element.setOpacity)
Element.setOpacity(this.element, opacity);
},
setZIndex: function(zindex) {
this.element.setStyle({zIndex: zindex});
Windows.updateZindex(zindex, this);
},
setTitle: function(newTitle) {
if (!newTitle || newTitle == "")
newTitle = " ";
Element.update(this.element.id + '_top', newTitle);
},
getTitle: function() {
return $(this.element.id + '_top').innerHTML;
},
setStatusBar: function(element) {
var statusBar = $(this.getId() + "_bottom");
if (typeof(element) == "object") {
if (this.bottombar.firstChild)
this.bottombar.replaceChild(element, this.bottombar.firstChild);
else
this.bottombar.appendChild(element);
}
else
this.bottombar.innerHTML = element;
},
_checkIEOverlapping: function() {
if(!this.iefix && (navigator.appVersion.indexOf('MSIE')>0) && (navigator.userAgent.indexOf('Opera')<0) && (this.element.getStyle('position')=='absolute')) {
new Insertion.After(this.element.id, '<iframe id="' + this.element.id + '_iefix" '+ 'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' + 'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
this.iefix = $(this.element.id+'_iefix');
}
if(this.iefix)
setTimeout(this._fixIEOverlapping.bind(this), 50);
},
_fixIEOverlapping: function() {
Position.clone(this.element, this.iefix);
this.iefix.style.zIndex = this.element.style.zIndex - 1;
this.iefix.show();
},
_getWindowBorderSize: function(event) {
// Hack to get real window border size!!
var div = this._createHiddenDiv(this.options.className + "_n")
this.heightN = Element.getDimensions(div).height;
div.parentNode.removeChild(div)
var div = this._createHiddenDiv(this.options.className + "_s")
this.heightS = Element.getDimensions(div).height;
div.parentNode.removeChild(div)
var div = this._createHiddenDiv(this.options.className + "_e")
this.widthE = Element.getDimensions(div).width;
div.parentNode.removeChild(div)
var div = this._createHiddenDiv(this.options.className + "_w")
this.widthW = Element.getDimensions(div).width;
div.parentNode.removeChild(div);
var div = document.createElement("div");
div.className = "overlay_" + this.options.className ;
document.body.appendChild(div);
//alert("no timeout:\nopacity: " + div.getStyle("opacity") + "\nwidth: " + document.defaultView.getComputedStyle(div, null).width);
var that = this;
// Workaround for Safari!!
setTimeout(function() {that.overlayOpacity = ($(div).getStyle("opacity")); div.parentNode.removeChild(div);}, 10);
// Workaround for IE!!
if (Prototype.Browser.IE) {
this.heightS = $(this.getId() +"_row3").getDimensions().height;
this.heightN = $(this.getId() +"_row1").getDimensions().height;
}
// Safari size fix
if (Prototype.Browser.WebKit && Prototype.Browser.WebKitVersion < 420)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -