📄 container.js
字号:
}
} else { // Show
if (currentVis != "visible") {
this.beforeShowEvent.fire();
YAHOO.util.Dom.setStyle(this.element, "visibility", "visible");
this.cfg.refireEvent("iframe");
this.showEvent.fire();
}
}
} else { // Hide
if (isMacGecko) {
this.hideMacGeckoScrollbars();
}
if (effect) { // Animate out if showing
if (currentVis != "hidden") {
this.beforeHideEvent.fire();
for (var i=0;i<effectInstances.length;i++) {
var e = effectInstances[i];
if (i == 0 && ! YAHOO.util.Config.alreadySubscribed(e.animateOutCompleteEvent,this.hideEvent.fire,this.hideEvent)) {
e.animateOutCompleteEvent.subscribe(this.hideEvent.fire,this.hideEvent,true); // Delegate hideEvent until end of animateOutComplete
}
e.animateOut();
}
}
} else { // Simple hide
if (currentVis != "hidden") {
this.beforeHideEvent.fire();
YAHOO.util.Dom.setStyle(this.element, "visibility", "hidden");
this.cfg.refireEvent("iframe");
this.hideEvent.fire();
}
}
}
}
/**
* Center event handler used for centering on scroll/resize, but only if the Overlay is visible
*/
YAHOO.widget.Overlay.prototype.doCenterOnDOMEvent = function() {
if (this.cfg.getProperty("visible")) {
this.center();
}
}
/**
* The default event handler fired when the "fixedcenter" property is changed.
*/
YAHOO.widget.Overlay.prototype.configFixedCenter = function(type, args, obj) {
var val = args[0];
if (val) {
this.center();
if (! YAHOO.util.Config.alreadySubscribed(this.beforeShowEvent, this.center, this)) {
this.beforeShowEvent.subscribe(this.center, this, true);
}
if (! YAHOO.util.Config.alreadySubscribed(YAHOO.widget.Overlay.windowResizeEvent, this.doCenterOnDOMEvent, this)) {
YAHOO.widget.Overlay.windowResizeEvent.subscribe(this.doCenterOnDOMEvent, this, true);
}
if (! YAHOO.util.Config.alreadySubscribed(YAHOO.widget.Overlay.windowScrollEvent, this.doCenterOnDOMEvent, this)) {
YAHOO.widget.Overlay.windowScrollEvent.subscribe( this.doCenterOnDOMEvent, this, true);
}
} else {
YAHOO.widget.Overlay.windowResizeEvent.unsubscribe(this.doCenterOnDOMEvent, this);
YAHOO.widget.Overlay.windowScrollEvent.unsubscribe(this.doCenterOnDOMEvent, this);
}
}
/**
* The default event handler fired when the "height" property is changed.
*/
YAHOO.widget.Overlay.prototype.configHeight = function(type, args, obj) {
var height = args[0];
var el = this.element;
YAHOO.util.Dom.setStyle(el, "height", height);
this.cfg.refireEvent("iframe");
}
/**
* The default event handler fired when the "width" property is changed.
*/
YAHOO.widget.Overlay.prototype.configWidth = function(type, args, obj) {
var width = args[0];
var el = this.element;
YAHOO.util.Dom.setStyle(el, "width", width);
this.cfg.refireEvent("iframe");
}
/**
* The default event handler fired when the "zIndex" property is changed.
*/
YAHOO.widget.Overlay.prototype.configzIndex = function(type, args, obj) {
var zIndex = args[0];
var el = this.element;
if (! zIndex) {
zIndex = YAHOO.util.Dom.getStyle(el, "zIndex");
if (! zIndex || isNaN(zIndex)) {
zIndex = 0;
}
}
if (this.iframe) {
if (zIndex <= 0) {
zIndex = 1;
}
YAHOO.util.Dom.setStyle(this.iframe, "zIndex", (zIndex-1));
}
YAHOO.util.Dom.setStyle(el, "zIndex", zIndex);
this.cfg.setProperty("zIndex", zIndex, true);
}
/**
* The default event handler fired when the "xy" property is changed.
*/
YAHOO.widget.Overlay.prototype.configXY = function(type, args, obj) {
var pos = args[0];
var x = pos[0];
var y = pos[1];
this.cfg.setProperty("x", x);
this.cfg.setProperty("y", y);
this.beforeMoveEvent.fire([x,y]);
x = this.cfg.getProperty("x");
y = this.cfg.getProperty("y");
this.cfg.refireEvent("iframe");
this.moveEvent.fire([x,y]);
}
/**
* The default event handler fired when the "x" property is changed.
*/
YAHOO.widget.Overlay.prototype.configX = function(type, args, obj) {
var x = args[0];
var y = this.cfg.getProperty("y");
this.cfg.setProperty("x", x, true);
this.cfg.setProperty("y", y, true);
this.beforeMoveEvent.fire([x,y]);
x = this.cfg.getProperty("x");
y = this.cfg.getProperty("y");
YAHOO.util.Dom.setX(this.element, x, true);
this.cfg.setProperty("xy", [x, y], true);
this.cfg.refireEvent("iframe");
this.moveEvent.fire([x, y]);
}
/**
* The default event handler fired when the "y" property is changed.
*/
YAHOO.widget.Overlay.prototype.configY = function(type, args, obj) {
var x = this.cfg.getProperty("x");
var y = args[0];
this.cfg.setProperty("x", x, true);
this.cfg.setProperty("y", y, true);
this.beforeMoveEvent.fire([x,y]);
x = this.cfg.getProperty("x");
y = this.cfg.getProperty("y");
YAHOO.util.Dom.setY(this.element, y, true);
this.cfg.setProperty("xy", [x, y], true);
this.cfg.refireEvent("iframe");
this.moveEvent.fire([x, y]);
}
/**
* The default event handler fired when the "iframe" property is changed.
*/
YAHOO.widget.Overlay.prototype.configIframe = function(type, args, obj) {
var val = args[0];
var el = this.element;
if (val) {
var x = this.cfg.getProperty("x");
var y = this.cfg.getProperty("y");
if (! x || ! y) {
this.syncPosition();
x = this.cfg.getProperty("x");
y = this.cfg.getProperty("y");
}
if (! isNaN(x) && ! isNaN(y)) {
if (! this.iframe) {
this.iframe = document.createElement("iframe");
var parent = el.parentNode;
if (parent) {
parent.appendChild(this.iframe);
} else {
document.body.appendChild(this.iframe);
}
this.iframe.src = this.imageRoot + YAHOO.widget.Overlay.IFRAME_SRC;
YAHOO.util.Dom.setStyle(this.iframe, "position", "absolute");
YAHOO.util.Dom.setStyle(this.iframe, "border", "none");
YAHOO.util.Dom.setStyle(this.iframe, "margin", "0");
YAHOO.util.Dom.setStyle(this.iframe, "padding", "0");
YAHOO.util.Dom.setStyle(this.iframe, "opacity", "0");
}
YAHOO.util.Dom.setStyle(this.iframe, "left", x-2 + "px");
YAHOO.util.Dom.setStyle(this.iframe, "top", y-2 + "px");
var width = el.clientWidth;
var height = el.clientHeight;
YAHOO.util.Dom.setStyle(this.iframe, "width", (width+2) + "px");
YAHOO.util.Dom.setStyle(this.iframe, "height", (height+2) + "px");
if (! this.cfg.getProperty("visible")) {
this.iframe.style.display = "none";
} else {
this.iframe.style.display = "block";
}
}
} else {
if (this.iframe) {
this.iframe.style.display = "none";
}
}
}
/**
* The default event handler fired when the "constraintoviewport" property is changed.
*/
YAHOO.widget.Overlay.prototype.configConstrainToViewport = function(type, args, obj) {
var val = args[0];
if (val) {
if (! YAHOO.util.Config.alreadySubscribed(this.beforeMoveEvent, this.enforceConstraints, this)) {
this.beforeMoveEvent.subscribe(this.enforceConstraints, this, true);
}
} else {
this.beforeMoveEvent.unsubscribe(this.enforceConstraints, this);
}
}
/**
* The default event handler fired when the "context" property is changed.
*/
YAHOO.widget.Overlay.prototype.configContext = function(type, args, obj) {
var contextArgs = args[0];
if (contextArgs) {
var contextEl = contextArgs[0];
var elementMagnetCorner = contextArgs[1];
var contextMagnetCorner = contextArgs[2];
if (contextEl) {
if (typeof contextEl == "string") {
this.cfg.setProperty("context", [document.getElementById(contextEl),elementMagnetCorner,contextMagnetCorner], true);
}
if (elementMagnetCorner && contextMagnetCorner) {
this.align(elementMagnetCorner, contextMagnetCorner);
}
}
}
}
// END BUILT-IN PROPERTY EVENT HANDLERS //
/**
* Aligns the Overlay to its context element using the specified corner points (represented by the constants TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, and BOTTOM_RIGHT.
* @param {string} elementAlign The string representing the corner of the Overlay that should be aligned to the context element
* @param {string} contextAlign The corner of the context element that the elementAlign corner should stick to.
*/
YAHOO.widget.Overlay.prototype.align = function(elementAlign, contextAlign) {
var contextArgs = this.cfg.getProperty("context");
if (contextArgs) {
var context = contextArgs[0];
var element = this.element;
var me = this;
if (! elementAlign) {
elementAlign = contextArgs[1];
}
if (! contextAlign) {
contextAlign = contextArgs[2];
}
if (element && context) {
var elementRegion = YAHOO.util.Dom.getRegion(element);
var contextRegion = YAHOO.util.Dom.getRegion(context);
var doAlign = function(v,h) {
switch (elementAlign) {
case YAHOO.widget.Overlay.TOP_LEFT:
me.moveTo(h,v);
break;
case YAHOO.widget.Overlay.TOP_RIGHT:
me.moveTo(h-element.offsetWidth,v);
break;
case YAHOO.widget.Overlay.BOTTOM_LEFT:
me.moveTo(h,v-element.offsetHeight);
break;
case YAHOO.widget.Overlay.BOTTOM_RIGHT:
me.moveTo(h-element.offsetWidth,v-element.offsetHeight);
break;
}
}
switch (contextAlign) {
case YAHOO.widget.Overlay.TOP_LEFT:
doAlign(contextRegion.top, contextRegion.left);
break;
case YAHOO.widget.Overlay.TOP_RIGHT:
doAlign(contextRegion.top, contextRegion.right);
break;
case YAHOO.widget.Overlay.BOTTOM_LEFT:
doAlign(contextRegion.bottom, contextRegion.left);
break;
case YAHOO.widget.Overlay.BOTTOM_RIGHT:
doAlign(contextRegion.bottom, contextRegion.right);
break;
}
}
}
}
/**
* The default event handler executed when the moveEvent is fired, if the "constraintoviewport" is set to true.
*/
YAHOO.widget.Overlay.prototype.enforceConstraints = function(type, args, obj) {
var pos = args[0];
var x = pos[0];
var y = pos[1];
var width = parseInt(this.cfg.getProperty("width"));
if (isNaN(width)) {
width = 0;
}
var offsetHeight = this.element.offsetHeight;
var offsetWidth = (width>0?width:this.element.offsetWidth); //this.element.offsetWidth;
var viewPortWidth = YAHOO.util.Dom.getViewportWidth();
var viewPortHeight = YAHOO.util.Dom.getViewportHeight();
var scrollX = window.scrollX || document.documentElement.scrollLeft;
var scrollY = window.scrollY || document.documentElement.scrollTop;
var topConstraint = scrollY + 10;
var leftConstraint = scrollX + 10;
var bottomConstraint = scrollY + viewPortHeight - offsetHeight - 10;
var rightConstraint = scrollX + viewPortWidth - offsetWidth - 10;
if (x < leftConstraint) {
x = leftConstraint;
} else if (x > rightConstraint) {
x = rightConstraint;
}
if (y < topConstraint) {
y = topConstraint;
} else if (y > bottomConstraint) {
y = bottomConstraint;
}
this.cfg.setProperty("x", x, true);
this.cfg.setProperty("y", y, true);
this.cfg.setProperty("xy", [x,y], true);
}
/**
* Centers the container in the viewport.
*/
YAHOO.widget.Overlay.prototype.center = function() {
var scrollX = window.scrollX || document.documentElement.scrollLeft;
var scrollY = window.scrollY || document.documentElement.scrollTop;
var viewPortWidth = YAHOO.util.Dom.getClientWidth();
var viewPortHeight = YAHOO.util.Dom.getClientHeight();
var elementWidth = this.element.offsetWidth;
var elementHeight = this.element.offsetHeight;
var x = (viewPortWidth / 2) - (elementWidth / 2) + scrollX;
var y = (viewPortHeight / 2) - (elementHeight / 2) + scrollY;
this.element.style.left = parseInt(x) + "px";
this.element.style.top = parseInt(y) + "px";
this.syncPosition();
this.cfg.refireEvent("iframe");
}
/**
* Synchronizes the Panel's "xy", "x", and "y" properties with the Panel's position in the DOM. This is primarily used to update position information during drag & drop.
*/
YAHOO.widget.Overlay.prototype.syncPosition = function() {
var pos = YAHOO.util.Dom.getXY(this.element);
this.cfg.setProperty("x", pos[0], true);
this.cfg.setProperty("y", pos[1], true);
this.cfg.setProperty("xy", pos, true);
}
/**
* Event handler fired when the resize monitor element is resized.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -