📄 container.js
字号:
this.element = el; if (el.id) { this.id = el.id; } var childNodes = this.element.childNodes; if (childNodes) { for (var i=0;i<childNodes.length;i++) { var child = childNodes[i]; switch (child.className) { case YAHOO.widget.Module.CSS_HEADER: this.header = child; break; case YAHOO.widget.Module.CSS_BODY: this.body = child; break; case YAHOO.widget.Module.CSS_FOOTER: this.footer = child; break; } } } this.initDefaultConfig(); YAHOO.util.Dom.addClass(this.element, YAHOO.widget.Module.CSS_MODULE); if (userConfig) { this.cfg.applyConfig(userConfig, true); } // Subscribe to the fireQueue() method of Config so that any queued configuration changes are // excecuted upon render of the Module if (! YAHOO.util.Config.alreadySubscribed(this.renderEvent, this.cfg.fireQueue, this.cfg)) { this.renderEvent.subscribe(this.cfg.fireQueue, this.cfg, true); } this.initEvent.fire(YAHOO.widget.Module); }, /** * Initialized an empty IFRAME that is placed out of the visible area that can be used to detect text resize. * @method initResizeMonitor */ initResizeMonitor : function() { if(this.browser != "opera") { var resizeMonitor = document.getElementById("_yuiResizeMonitor"); if (! resizeMonitor) { resizeMonitor = document.createElement("iframe"); var bIE = (this.browser.indexOf("ie") === 0); if(this.isSecure && YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL && bIE) { resizeMonitor.src = YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL; } resizeMonitor.id = "_yuiResizeMonitor"; resizeMonitor.style.visibility = "hidden"; document.body.appendChild(resizeMonitor); resizeMonitor.style.width = "10em"; resizeMonitor.style.height = "10em"; resizeMonitor.style.position = "absolute"; var nLeft = -1 * resizeMonitor.offsetWidth, nTop = -1 * resizeMonitor.offsetHeight; resizeMonitor.style.top = nTop + "px"; resizeMonitor.style.left = nLeft + "px"; resizeMonitor.style.borderStyle = "none"; resizeMonitor.style.borderWidth = "0"; YAHOO.util.Dom.setStyle(resizeMonitor, "opacity", "0"); resizeMonitor.style.visibility = "visible"; if(!bIE) { var doc = resizeMonitor.contentWindow.document; doc.open(); doc.close(); } } var fireTextResize = function() { YAHOO.widget.Module.textResizeEvent.fire(); }; if(resizeMonitor && resizeMonitor.contentWindow) { this.resizeMonitor = resizeMonitor; YAHOO.widget.Module.textResizeEvent.subscribe(this.onDomResize, this, true); if (! YAHOO.widget.Module.textResizeInitialized) { if (! YAHOO.util.Event.addListener(this.resizeMonitor.contentWindow, "resize", fireTextResize)) { // This will fail in IE if document.domain has changed, so we must change the listener to // use the resizeMonitor element instead YAHOO.util.Event.addListener(this.resizeMonitor, "resize", fireTextResize); } YAHOO.widget.Module.textResizeInitialized = true; } } } }, /** * Event handler fired when the resize monitor element is resized. * @method onDomResize * @param {DOMEvent} e The DOM resize event * @param {Object} obj The scope object passed to the handler */ 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. * @method setHeader * @param {String} headerContent The HTML used to set the header <em>OR</em> * @param {HTMLElement} headerContent The HTMLElement 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. * @method appendToHeader * @param {HTMLElement} 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. * @method setBody * @param {String} bodyContent The HTML used to set the body <em>OR</em> * @param {HTMLElement} bodyContent The HTMLElement 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. * @method appendToBody * @param {HTMLElement} 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. * @method setFooter * @param {String} footerContent The HTML used to set the footer <em>OR</em> * @param {HTMLElement} footerContent The HTMLElement 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. * @method appendToFooter * @param {HTMLElement} 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. * @method render * @param {String} appendToNode The element id to which the Module should be appended to prior to rendering <em>OR</em> * @param {HTMLElement} appendToNode The element to which the Module should be appended to prior to rendering * @param {HTMLElement} 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. * @method destroy */ destroy : function() { var parent; if (this.element) { YAHOO.util.Event.purgeElement(this.element, true); parent = this.element.parentNode; } if (parent) { parent.removeChild(this.element); } this.element = null; this.header = null; this.body = null; this.footer = null; for (var e in this) { if (e instanceof YAHOO.util.CustomEvent) { e.unsubscribeAll(); } } YAHOO.widget.Module.textResizeEvent.unsubscribe(this.onDomResize, this); 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. * @method show */ 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. * @method hide */ 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. * @param {String} type The CustomEvent type (usually the property name) * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. * @method configVisible */ 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 * @param {String} type The CustomEvent type (usually the property name) * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. * @method configMonitorResize */ configMonitorResize : function(type, args, obj) { var monitor = args[0]; if (monitor) { this.initResizeMonitor(); } else { YAHOO.widget.Module.textResizeEvent.unsubscribe(this.onDomResize, this, true); this.resizeMonitor = null; } }};/*** Returns a String representation of the Object.* @method toString* @return {String} The string representation of the Module*/ YAHOO.widget.Module.prototype.toString = function() { return "Module " + this.id;};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -