📄 container.js
字号:
this.resizeMonitor = resizeMonitor;
YAHOO.util.Event.addListener(this.resizeMonitor.contentWindow, "resize", this.onDomResize, this, true);
}
}
},
/**
* Event handler fired when the resize monitor element is resized.
*/
onDomResize : function(e, obj) {
var nLeft = -1 * this.resizeMonitor.offsetWidth,
nTop = -1 * this.resizeMonitor.offsetHeight;
this.resizeMonitor.style.top = nTop + "px";
this.resizeMonitor.style.left = nLeft + "px";
},
/**
* Sets the Module's header content to the HTML specified, or appends the passed element to the header. If no header is present, one will be automatically created.
* @param {string} headerContent The HTML used to set the header <em>OR</em>
* @param {Element} headerContent The Element to append to the header
*/
setHeader : function(headerContent) {
if (! this.header) {
this.header = document.createElement("DIV");
this.header.className = YAHOO.widget.Module.CSS_HEADER;
}
if (typeof headerContent == "string") {
this.header.innerHTML = headerContent;
} else {
this.header.innerHTML = "";
this.header.appendChild(headerContent);
}
this.changeHeaderEvent.fire(headerContent);
this.changeContentEvent.fire();
},
/**
* Appends the passed element to the header. If no header is present, one will be automatically created.
* @param {Element} element The element to append to the header
*/
appendToHeader : function(element) {
if (! this.header) {
this.header = document.createElement("DIV");
this.header.className = YAHOO.widget.Module.CSS_HEADER;
}
this.header.appendChild(element);
this.changeHeaderEvent.fire(element);
this.changeContentEvent.fire();
},
/**
* Sets the Module's body content to the HTML specified, or appends the passed element to the body. If no body is present, one will be automatically created.
* @param {string} bodyContent The HTML used to set the body <em>OR</em>
* @param {Element} bodyContent The Element to append to the body
*/
setBody : function(bodyContent) {
if (! this.body) {
this.body = document.createElement("DIV");
this.body.className = YAHOO.widget.Module.CSS_BODY;
}
if (typeof bodyContent == "string")
{
this.body.innerHTML = bodyContent;
} else {
this.body.innerHTML = "";
this.body.appendChild(bodyContent);
}
this.changeBodyEvent.fire(bodyContent);
this.changeContentEvent.fire();
},
/**
* Appends the passed element to the body. If no body is present, one will be automatically created.
* @param {Element} element The element to append to the body
*/
appendToBody : function(element) {
if (! this.body) {
this.body = document.createElement("DIV");
this.body.className = YAHOO.widget.Module.CSS_BODY;
}
this.body.appendChild(element);
this.changeBodyEvent.fire(element);
this.changeContentEvent.fire();
},
/**
* Sets the Module's footer content to the HTML specified, or appends the passed element to the footer. If no footer is present, one will be automatically created.
* @param {string} footerContent The HTML used to set the footer <em>OR</em>
* @param {Element} footerContent The Element to append to the footer
*/
setFooter : function(footerContent) {
if (! this.footer) {
this.footer = document.createElement("DIV");
this.footer.className = YAHOO.widget.Module.CSS_FOOTER;
}
if (typeof footerContent == "string") {
this.footer.innerHTML = footerContent;
} else {
this.footer.innerHTML = "";
this.footer.appendChild(footerContent);
}
this.changeFooterEvent.fire(footerContent);
this.changeContentEvent.fire();
},
/**
* Appends the passed element to the footer. If no footer is present, one will be automatically created.
* @param {Element} element The element to append to the footer
*/
appendToFooter : function(element) {
if (! this.footer) {
this.footer = document.createElement("DIV");
this.footer.className = YAHOO.widget.Module.CSS_FOOTER;
}
this.footer.appendChild(element);
this.changeFooterEvent.fire(element);
this.changeContentEvent.fire();
},
/**
* Renders the Module by inserting the elements that are not already in the main Module into their correct places. Optionally appends the Module to the specified node prior to the render's execution. NOTE: For Modules without existing markup, the appendToNode argument is REQUIRED. If this argument is ommitted and the current element is not present in the document, the function will return false, indicating that the render was a failure.
* @param {string} appendToNode The element id to which the Module should be appended to prior to rendering <em>OR</em>
* @param {Element} appendToNode The element to which the Module should be appended to prior to rendering
* @param {Element} moduleElement OPTIONAL. The element that represents the actual Standard Module container.
* @return {boolean} Success or failure of the render
*/
render : function(appendToNode, moduleElement) {
this.beforeRenderEvent.fire();
if (! moduleElement) {
moduleElement = this.element;
}
var me = this;
var appendTo = function(element) {
if (typeof element == "string") {
element = document.getElementById(element);
}
if (element) {
element.appendChild(me.element);
me.appendEvent.fire();
}
};
if (appendToNode) {
appendTo(appendToNode);
} else { // No node was passed in. If the element is not pre-marked up, this fails
if (! YAHOO.util.Dom.inDocument(this.element)) {
return false;
}
}
// Need to get everything into the DOM if it isn't already
if (this.header && ! YAHOO.util.Dom.inDocument(this.header)) {
// There is a header, but it's not in the DOM yet... need to add it
var firstChild = moduleElement.firstChild;
if (firstChild) { // Insert before first child if exists
moduleElement.insertBefore(this.header, firstChild);
} else { // Append to empty body because there are no children
moduleElement.appendChild(this.header);
}
}
if (this.body && ! YAHOO.util.Dom.inDocument(this.body)) {
// There is a body, but it's not in the DOM yet... need to add it
if (this.footer && YAHOO.util.Dom.isAncestor(this.moduleElement, this.footer)) { // Insert before footer if exists in DOM
moduleElement.insertBefore(this.body, this.footer);
} else { // Append to element because there is no footer
moduleElement.appendChild(this.body);
}
}
if (this.footer && ! YAHOO.util.Dom.inDocument(this.footer)) {
// There is a footer, but it's not in the DOM yet... need to add it
moduleElement.appendChild(this.footer);
}
this.renderEvent.fire();
return true;
},
/**
* Removes the Module element from the DOM and sets all child elements to null.
*/
destroy : function() {
if (this.element) {
var parent = this.element.parentNode;
}
if (parent) {
parent.removeChild(this.element);
}
this.element = null;
this.header = null;
this.body = null;
this.footer = null;
this.destroyEvent.fire();
},
/**
* Shows the Module element by setting the visible configuration property to true. Also fires two events: beforeShowEvent prior to the visibility change, and showEvent after.
*/
show : function() {
this.cfg.setProperty("visible", true);
},
/**
* Hides the Module element by setting the visible configuration property to false. Also fires two events: beforeHideEvent prior to the visibility change, and hideEvent after.
*/
hide : function() {
this.cfg.setProperty("visible", false);
},
// BUILT-IN EVENT HANDLERS FOR MODULE //
/**
* Default event handler for changing the visibility property of a Module. By default, this is achieved by switching the "display" style between "block" and "none".
* This method is responsible for firing showEvent and hideEvent.
*/
configVisible : function(type, args, obj) {
var visible = args[0];
if (visible) {
this.beforeShowEvent.fire();
YAHOO.util.Dom.setStyle(this.element, "display", "block");
this.showEvent.fire();
} else {
this.beforeHideEvent.fire();
YAHOO.util.Dom.setStyle(this.element, "display", "none");
this.hideEvent.fire();
}
},
/**
* Default event handler for the "monitorresize" configuration property
*/
configMonitorResize : function(type, args, obj) {
var monitor = args[0];
if (monitor) {
this.initResizeMonitor();
} else {
YAHOO.util.Event.removeListener(this.resizeMonitor, "resize", this.onDomResize);
this.resizeMonitor = null;
}
}
};
/**
* Returns a string representation of the object.
* @type string
*/
YAHOO.widget.Module.prototype.toString = function() {
return "Module " + this.id;
};
/**
* Overlay is a Module that is absolutely positioned above the page flow. It has convenience methods for positioning and sizing, as well as options for controlling zIndex and constraining the Overlay's position to the current visible viewport. Overlay also contains a dynamicly generated IFRAME which is placed beneath it for Internet Explorer 6 and 5.x so that it will be properly rendered above SELECT elements.
* @extends YAHOO.widget.Module
* @param {string} el The element ID representing the Overlay <em>OR</em>
* @param {Element} el The element representing the Overlay
* @param {object} userConfig The configuration object literal containing the configuration that should be set for this Overlay. See configuration documentation for more details.
* @constructor
*/
YAHOO.widget.Overlay = function(el, userConfig) {
YAHOO.widget.Overlay.superclass.constructor.call(this, el, userConfig);
};
YAHOO.extend(YAHOO.widget.Overlay, YAHOO.widget.Module);
/**
* The URL of the blank image that will be placed in the iframe
* @type string
* @final
*/
YAHOO.widget.Overlay.IFRAME_SRC = "promo/m/irs/blank.gif";
/**
* Constant representing the top left corner of an element, used for configuring the context element alignment
* @type string
* @final
*/
YAHOO.widget.Overlay.TOP_LEFT = "tl";
/**
* Constant representing the top right corner of an element, used for configuring the context element alignment
* @type string
* @final
*/
YAHOO.widget.Overlay.TOP_RIGHT = "tr";
/**
* Constant representing the top bottom left corner of an element, used for configuring the context element alignment
* @type string
* @final
*/
YAHOO.widget.Overlay.BOTTOM_LEFT = "bl";
/**
* Constant representing the bottom right corner of an element, used for configuring the context element alignment
* @type string
* @final
*/
YAHOO.widget.Overlay.BOTTOM_RIGHT = "br";
/**
* Constant representing the default CSS class used for an Overlay
* @type string
* @final
*/
YAHOO.widget.Overlay.CSS_OVERLAY = "overlay";
/**
* CustomEvent fired before the Overlay is moved.
* args: x,y that the Overlay will be moved to
* @type YAHOO.util.CustomEvent
*/
YAHOO.widget.Overlay.prototype.beforeMoveEvent = null;
/**
* CustomEvent fired after the Overlay is moved.
* args: x,y that the Overlay was moved to
* @type YAHOO.util.CustomEvent
*/
YAHOO.widget.Overlay.prototype.moveEvent = null;
/**
* The Overlay initialization method, which is executed for Overlay and all of its subclasses. This method is automatically called by the constructor, and sets up all DOM references for pre-existing markup, and creates required markup if it is not already present.
* @param {string} el The element ID representing the Overlay <em>OR</em>
* @param {Element} el The element representing the Overlay
* @param {object} userConfig The configuration object literal containing the configuration that should be set for this Overlay. See configuration documentation for more details.
*/
YAHOO.widget.Overlay.prototype.init = function(el, userConfig) {
YAHOO.widget.Overlay.superclass.init.call(this, el/*, userConfig*/); // Note that we don't pass the user config in here yet because we only want it executed once, at the lowest subclass level
this.beforeInitEvent.fire(YAHOO.widget.Overlay);
YAHOO.util.Dom.addClass(this.element, YAHOO.widget.Overlay.CSS_OVERLAY);
if (userConfig) {
this.cfg.applyConfig(userConfig, true);
}
if (this.platform == "mac" && this.browser == "gecko") {
if (! YAHOO.util.Config.alreadySubscribed(this.showEvent,this.showMacGeckoScrollbars,this)) {
this.showEvent.subscribe(this.showMacGeckoScrollbars,this,true);
}
if (! YAHOO.util.Config.alreadySubscribed(this.hideEvent,this.hideMacGeckoScrollbars,this)) {
this.hideEvent.subscribe(this.hideMacGeckoScrollbars,this,true);
}
}
this.initEvent.fire(YAHOO.widget.Overlay);
};
/**
* Initializes the custom events for Overlay which are fired automatically at appropriate times by the Overlay class.
*/
YAHOO.widget.Overlay.prototype.initEvents = function() {
YAHOO.widget.Overlay.superclass.initEvents.call(this);
this.beforeMoveEvent = new YAHOO.util.CustomEvent("beforeMove", this);
this.moveEvent = new YAHOO.util.CustomEvent("move", this);
};
/**
* Initializes the class's configurable properties which can be changed using the Overlay's Config object (cfg).
*/
YAHOO.widget.Overlay.prototype.initDefaultConfig = function() {
YAHOO.widget.Overlay.superclass.initDefaultConfig.call(this);
// Add overlay config properties //
this.cfg.addProperty("x", { handler:this.configX, validator:this.cfg.checkNumber, suppressEvent:true, supercedes:["iframe"] } );
this.cfg.addProperty("y", { handler:this.configY, validator:this.cfg.checkNumber, suppressEvent:true, supercedes:["iframe"] } );
this.cfg.addProperty("xy",{ handler:this.configXY, suppressEvent:true, supercedes:["iframe"] } );
this.cfg.addProperty("context", { handler:this.configContext, suppressEvent:true, supercedes:["iframe"] } );
this.cfg.addProperty("fixedcenter", { value:false, handler:this.configFixedCenter, validator:this.cfg.checkBoolean, supercedes:["iframe","visible"] } );
this.cfg.addProperty("width", { handler:this.configWidth, suppressEvent:true, supercedes:["iframe"] } );
this.cfg.addProperty("height", { handler:this.configHeight, suppressEvent:true, supercedes:["iframe"] } );
this.cfg.addProperty("zIndex", { value:null, handler:this.configzIndex } );
this.cfg.addProperty("constraintoviewport", { value:false, handler:this.configConstrainToViewport, validator:this.cfg.checkBoolean, supercedes:["iframe","x","y","xy"] } );
this.cfg.addProperty("iframe", { value:(this.browser == "ie" ? true : false), handler:this.configIframe, validator:this.cfg.checkBoolean, supercedes:["zIndex"] } );
};
/**
* Moves the Overlay to the specified position. This function is identical to calling this.cfg.setProperty("xy", [x,y]);
* @param {int} x The Overlay's new x position
* @param {int} y The Overlay's new y position
*/
YAHOO.widget.Overlay.prototype.moveTo = function(x, y) {
this.cfg.setProperty("xy",[x,y]);
};
/**
* Adds a special CSS class to the Overlay when Mac/Gecko is in use, to work around a Gecko bug where
* scrollbars cannot be hidden. See https://bugzilla.mozilla.org/show_bug.cgi?id=187435
*/
YAHOO.widget.Overlay.prototype.hideMacGeckoScrollbars = function() {
YAHOO.util.Dom.removeClass(this.element, "show-scrollbars");
YAHOO.util.Dom.addClass(this.element, "hide-scrollbars");
};
/**
* Removes a special CSS class from the Overlay when Mac/Gecko is in use, to work around a Gecko bug where
* scrollbars cannot be hidden. See https://bugzilla.mozilla.org/show_bug.cgi?id=187435
*/
YAHOO.widget.Overlay.prototype.showMacGeckoScrollbars = function() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -