📄 container.js
字号:
*/
YAHOO.util.Config.alreadySubscribed = function(evt, fn, obj) {
for (var e=0;e<evt.subscribers.length;e++) {
var subsc = evt.subscribers[e];
if (subsc && subsc.obj == obj && subsc.fn == fn) {
return true;
}
}
return false;
};
/**
* Module is a JavaScript representation of the Standard Module Format. Standard Module Format is a simple standard for markup containers where child nodes representing the header, body, and footer of the content are denoted using the CSS classes "hd", "bd", and "ft" respectively. Module is the base class for all other classes in the YUI Container package.
* @param {string} el The element ID representing the Module <em>OR</em>
* @param {Element} el The element representing the Module
* @param {object} userConfig The configuration object literal containing the configuration that should be set for this module. See configuration documentation for more details.
* @constructor
*/
YAHOO.widget.Module = function(el, userConfig) {
if (el) {
this.init(el, userConfig);
}
};
/**
* Constant representing the prefix path to use for non-secure images
* @type string
*/
YAHOO.widget.Module.IMG_ROOT = "http://us.i1.yimg.com/us.yimg.com/i/";
/**
* Constant representing the prefix path to use for securely served images
* @type string
*/
YAHOO.widget.Module.IMG_ROOT_SSL = "https://a248.e.akamai.net/sec.yimg.com/i/";
/**
* Constant for the default CSS class name that represents a Module
* @type string
* @final
*/
YAHOO.widget.Module.CSS_MODULE = "module";
/**
* Constant representing the module header
* @type string
* @final
*/
YAHOO.widget.Module.CSS_HEADER = "hd";
/**
* Constant representing the module body
* @type string
* @final
*/
YAHOO.widget.Module.CSS_BODY = "bd";
/**
* Constant representing the module footer
* @type string
* @final
*/
YAHOO.widget.Module.CSS_FOOTER = "ft";
/**
* Constant representing the url for the "src" attribute of the iframe used to monitor changes to the browser's base font size
* @type string
* @final
*/
YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL = "javascript:false";
YAHOO.widget.Module.prototype = {
/**
* The class's constructor function
* @type function
*/
constructor : YAHOO.widget.Module,
/**
* The main module element that contains the header, body, and footer
* @type Element
*/
element : null,
/**
* The header element, denoted with CSS class "hd"
* @type Element
*/
header : null,
/**
* The body element, denoted with CSS class "bd"
* @type Element
*/
body : null,
/**
* The footer element, denoted with CSS class "ft"
* @type Element
*/
footer : null,
/**
* The id of the element
* @type string
*/
id : null,
/**
* Array of elements
* @type Element[]
*/
childNodesInDOM : null,
/**
* The string representing the image root
* @type string
*/
imageRoot : YAHOO.widget.Module.IMG_ROOT,
/**
* CustomEvent fired prior to class initalization.
* args: class reference of the initializing class, such as this.beforeInitEvent.fire(YAHOO.widget.Module)
* @type YAHOO.util.CustomEvent
*/
beforeInitEvent : null,
/**
* CustomEvent fired after class initalization.
* args: class reference of the initializing class, such as this.initEvent.fire(YAHOO.widget.Module)
* @type YAHOO.util.CustomEvent
*/
initEvent : null,
/**
* CustomEvent fired when the Module is appended to the DOM
* args: none
* @type YAHOO.util.CustomEvent
*/
appendEvent : null,
/**
* CustomEvent fired before the Module is rendered
* args: none
* @type YAHOO.util.CustomEvent
*/
beforeRenderEvent : null,
/**
* CustomEvent fired after the Module is rendered
* args: none
* @type YAHOO.util.CustomEvent
*/
renderEvent : null,
/**
* CustomEvent fired when the header content of the Module is modified
* args: string/element representing the new header content
* @type YAHOO.util.CustomEvent
*/
changeHeaderEvent : null,
/**
* CustomEvent fired when the body content of the Module is modified
* args: string/element representing the new body content
* @type YAHOO.util.CustomEvent
*/
changeBodyEvent : null,
/**
* CustomEvent fired when the footer content of the Module is modified
* args: string/element representing the new footer content
* @type YAHOO.util.CustomEvent
*/
changeFooterEvent : null,
/**
* CustomEvent fired when the content of the Module is modified
* args: none
* @type YAHOO.util.CustomEvent
*/
changeContentEvent : null,
/**
* CustomEvent fired when the Module is destroyed
* args: none
* @type YAHOO.util.CustomEvent
*/
destroyEvent : null,
/**
* CustomEvent fired before the Module is shown
* args: none
* @type YAHOO.util.CustomEvent
*/
beforeShowEvent : null,
/**
* CustomEvent fired after the Module is shown
* args: none
* @type YAHOO.util.CustomEvent
*/
showEvent : null,
/**
* CustomEvent fired before the Module is hidden
* args: none
* @type YAHOO.util.CustomEvent
*/
beforeHideEvent : null,
/**
* CustomEvent fired after the Module is hidden
* args: none
* @type YAHOO.util.CustomEvent
*/
hideEvent : null,
/**
* Initializes the custom events for Module which are fired automatically at appropriate times by the Module class.
*/
initEvents : function() {
this.beforeInitEvent = new YAHOO.util.CustomEvent("beforeInit");
this.initEvent = new YAHOO.util.CustomEvent("init");
this.appendEvent = new YAHOO.util.CustomEvent("append");
this.beforeRenderEvent = new YAHOO.util.CustomEvent("beforeRender");
this.renderEvent = new YAHOO.util.CustomEvent("render");
this.changeHeaderEvent = new YAHOO.util.CustomEvent("changeHeader");
this.changeBodyEvent = new YAHOO.util.CustomEvent("changeBody");
this.changeFooterEvent = new YAHOO.util.CustomEvent("changeFooter");
this.changeContentEvent = new YAHOO.util.CustomEvent("changeContent");
this.destroyEvent = new YAHOO.util.CustomEvent("destroy");
this.beforeShowEvent = new YAHOO.util.CustomEvent("beforeShow");
this.showEvent = new YAHOO.util.CustomEvent("show");
this.beforeHideEvent = new YAHOO.util.CustomEvent("beforeHide");
this.hideEvent = new YAHOO.util.CustomEvent("hide");
},
/**
* String representing the current user-agent platform
* @type string
*/
platform : function() {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1) {
return "windows";
} else if (ua.indexOf("macintosh") != -1) {
return "mac";
} else {
return false;
}
}(),
/**
* String representing the current user-agent browser
* @type string
*/
browser : function() {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('opera')!=-1) { // Opera (check first in case of spoof)
return 'opera';
} else if (ua.indexOf('msie 7')!=-1) { // IE7
return 'ie7';
} else if (ua.indexOf('msie') !=-1) { // IE
return 'ie';
} else if (ua.indexOf('safari')!=-1) { // Safari (check before Gecko because it includes "like Gecko")
return 'safari';
} else if (ua.indexOf('gecko') != -1) { // Gecko
return 'gecko';
} else {
return false;
}
}(),
/**
* Boolean representing whether or not the current browsing context is secure (https)
* @type boolean
*/
isSecure : function() {
if (window.location.href.toLowerCase().indexOf("https") === 0) {
return true;
} else {
return false;
}
}(),
/**
* Initializes the custom events for Module which are fired automatically at appropriate times by the Module class.
*/
initDefaultConfig : function() {
// Add properties //
this.cfg.addProperty("visible", { value:true, handler:this.configVisible, validator:this.cfg.checkBoolean } );
this.cfg.addProperty("effect", { suppressEvent:true, supercedes:["visible"] } );
this.cfg.addProperty("monitorresize", { value:true, handler:this.configMonitorResize } );
},
/**
* The Module class's initialization method, which is executed for Module 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 Module <em>OR</em>
* @param {Element} el The element representing the Module
* @param {object} userConfig The configuration object literal containing the configuration that should be set for this module. See configuration documentation for more details.
*/
init : function(el, userConfig) {
this.initEvents();
this.beforeInitEvent.fire(YAHOO.widget.Module);
this.cfg = new YAHOO.util.Config(this);
if (this.isSecure) {
this.imageRoot = YAHOO.widget.Module.IMG_ROOT_SSL;
}
if (typeof el == "string") {
var elId = el;
el = document.getElementById(el);
if (! el) {
el = document.createElement("DIV");
el.id = elId;
}
}
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 DOM element that is placed out of the visible area that can be used to detect text resize.
*/
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();
}
}
if(resizeMonitor && resizeMonitor.contentWindow) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -