📄 container.js
字号:
YAHOO.widget.Overlay.prototype.enforceConstraints = function(type, args, obj) {
var pos = args[0];
var x = pos[0];
var y = pos[1];
var offsetHeight = this.element.offsetHeight;
var offsetWidth = this.element.offsetWidth;
var viewPortWidth = YAHOO.util.Dom.getViewportWidth();
var viewPortHeight = YAHOO.util.Dom.getViewportHeight();
var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
var scrollY = document.documentElement.scrollTop || document.body.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 = document.documentElement.scrollLeft || document.body.scrollLeft;
var scrollY = document.documentElement.scrollTop || document.body.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, 10) + "px";
this.element.style.top = parseInt(y, 10) + "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.
*/
YAHOO.widget.Overlay.prototype.onDomResize = function(e, obj) {
YAHOO.widget.Overlay.superclass.onDomResize.call(this, e, obj);
this.cfg.refireEvent("iframe");
};
/**
* Removes the Overlay element from the DOM and sets all child elements to null.
*/
YAHOO.widget.Overlay.prototype.destroy = function() {
if (this.iframe) {
this.iframe.parentNode.removeChild(this.iframe);
}
this.iframe = null;
YAHOO.widget.Overlay.superclass.destroy.call(this);
};
/**
* Returns a string representation of the object.
* @type string
*/
YAHOO.widget.Overlay.prototype.toString = function() {
return "Overlay " + this.id;
};
/**
* A singleton CustomEvent used for reacting to the DOM event for window scroll
* @type YAHOO.util.CustomEvent
*/
YAHOO.widget.Overlay.windowScrollEvent = new YAHOO.util.CustomEvent("windowScroll");
/**
* A singleton CustomEvent used for reacting to the DOM event for window resize
* @type YAHOO.util.CustomEvent
*/
YAHOO.widget.Overlay.windowResizeEvent = new YAHOO.util.CustomEvent("windowResize");
/**
* The DOM event handler used to fire the CustomEvent for window scroll
* @type Function
*/
YAHOO.widget.Overlay.windowScrollHandler = function(e) {
YAHOO.widget.Overlay.windowScrollEvent.fire();
};
/**
* The DOM event handler used to fire the CustomEvent for window resize
* @type Function
*/
YAHOO.widget.Overlay.windowResizeHandler = function(e) {
YAHOO.widget.Overlay.windowResizeEvent.fire();
};
/**
* @private
*/
YAHOO.widget.Overlay._initialized = null;
if (YAHOO.widget.Overlay._initialized === null) {
YAHOO.util.Event.addListener(window, "scroll", YAHOO.widget.Overlay.windowScrollHandler);
YAHOO.util.Event.addListener(window, "resize", YAHOO.widget.Overlay.windowResizeHandler);
YAHOO.widget.Overlay._initialized = true;
}
/*
Copyright (c) 2006, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
Version 0.11.4
*/
/**
* OverlayManager is used for maintaining the focus status of multiple Overlays.
* @param {Array} overlays Optional. A collection of Overlays to register with the manager.
* @param {object} userConfig The object literal representing the user configuration of the OverlayManager
* @constructor
*/
YAHOO.widget.OverlayManager = function(userConfig) {
this.init(userConfig);
};
/**
* The CSS class representing a focused Overlay
* @type string
*/
YAHOO.widget.OverlayManager.CSS_FOCUSED = "focused";
YAHOO.widget.OverlayManager.prototype = {
constructor : YAHOO.widget.OverlayManager,
/**
* The array of Overlays that are currently registered
* @type Array
*/
overlays : null,
/**
* Initializes the default configuration of the OverlayManager
*/
initDefaultConfig : function() {
this.cfg.addProperty("overlays", { suppressEvent:true } );
this.cfg.addProperty("focusevent", { value:"mousedown" } );
},
/**
* Returns the currently focused Overlay
* @return {Overlay} The currently focused Overlay
*/
getActive : function() {},
/**
* Focuses the specified Overlay
* @param {Overlay} The Overlay to focus
* @param {string} The id of the Overlay to focus
*/
focus : function(overlay) {},
/**
* Removes the specified Overlay from the manager
* @param {Overlay} The Overlay to remove
* @param {string} The id of the Overlay to remove
*/
remove: function(overlay) {},
/**
* Removes focus from all registered Overlays in the manager
*/
blurAll : function() {},
/**
* Initializes the OverlayManager
* @param {Array} overlays Optional. A collection of Overlays to register with the manager.
* @param {object} userConfig The object literal representing the user configuration of the OverlayManager
*/
init : function(userConfig) {
this.cfg = new YAHOO.util.Config(this);
this.initDefaultConfig();
if (userConfig) {
this.cfg.applyConfig(userConfig, true);
}
this.cfg.fireQueue();
var activeOverlay = null;
this.getActive = function() {
return activeOverlay;
};
this.focus = function(overlay) {
var o = this.find(overlay);
if (o) {
this.blurAll();
activeOverlay = o;
YAHOO.util.Dom.addClass(activeOverlay.element, YAHOO.widget.OverlayManager.CSS_FOCUSED);
this.overlays.sort(this.compareZIndexDesc);
var topZIndex = YAHOO.util.Dom.getStyle(this.overlays[0].element, "zIndex");
if (! isNaN(topZIndex) && this.overlays[0] != overlay) {
activeOverlay.cfg.setProperty("zIndex", (parseInt(topZIndex, 10) + 2));
}
this.overlays.sort(this.compareZIndexDesc);
}
};
this.remove = function(overlay) {
var o = this.find(overlay);
if (o) {
var originalZ = YAHOO.util.Dom.getStyle(o.element, "zIndex");
o.cfg.setProperty("zIndex", -1000, true);
this.overlays.sort(this.compareZIndexDesc);
this.overlays = this.overlays.slice(0, this.overlays.length-1);
o.cfg.setProperty("zIndex", originalZ, true);
o.cfg.setProperty("manager", null);
o.focusEvent = null;
o.blurEvent = null;
o.focus = null;
o.blur = null;
}
};
this.blurAll = function() {
activeOverlay = null;
for (var o=0;o<this.overlays.length;o++) {
YAHOO.util.Dom.removeClass(this.overlays[o].element, YAHOO.widget.OverlayManager.CSS_FOCUSED);
}
};
var overlays = this.cfg.getProperty("overlays");
if (! this.overlays) {
this.overlays = [];
}
if (overlays) {
this.register(overlays);
this.overlays.sort(this.compareZIndexDesc);
}
},
/**
* Registers an Overlay or an array of Overlays with the manager. Upon registration, the Overlay receives functions for focus and blur, along with CustomEvents for each.
* @param {Overlay} overlay An Overlay to register with the manager.
* @param {Overlay[]} overlay An array of Overlays to register with the manager.
* @return {boolean} True if any Overlays are registered.
*/
register : function(overlay) {
if (overlay instanceof YAHOO.widget.Overlay) {
overlay.cfg.addProperty("manager", { value:this } );
overlay.focusEvent = new YAHOO.util.CustomEvent("focus");
overlay.blurEvent = new YAHOO.util.CustomEvent("blur");
var mgr=this;
overlay.focus = function() {
mgr.focus(this);
this.focusEvent.fire();
};
overlay.blur = function() {
mgr.blurAll();
this.blurEvent.fire();
};
var focusOnDomEvent = function(e,obj) {
overlay.focus();
};
var focusevent = this.cfg.getProperty("focusevent");
YAHOO.util.Event.addListener(overlay.element,focusevent,focusOnDomEvent,this,true);
var zIndex = YAHOO.util.Dom.getStyle(overlay.element, "zIndex");
if (! isNaN(zIndex)) {
overlay.cfg.setProperty("zIndex", parseInt(zIndex, 10));
} else {
overlay.cfg.setProperty("zIndex", 0);
}
this.overlays.push(overlay);
return true;
} else if (overlay instanceof Array) {
var regcount = 0;
for (var i=0;i<overlay.length;i++) {
if (this.register(overlay[i])) {
regcount++;
}
}
if (regcount > 0) {
return true;
}
} else {
return false;
}
},
/**
* Attempts to locate an Overlay by instance or ID.
* @param {Overlay} overlay An Overlay to locate within the manager
* @param {string} overlay An Overlay id to locate within the manager
* @return {Overlay} The requested Overlay, if found, or null if it cannot be located.
*/
find : function(overlay) {
if (overlay instanceof YAHOO.widget.Overlay) {
for (var o=0;o<this.overlays.length;o++) {
if (this.overlays[o] == overlay) {
return this.overlays[o];
}
}
} else if (typeof overlay == "string") {
for (var p=0;p<this.overlays.length;p++) {
if (this.overlays[p].id == overlay) {
return this.overlays[p];
}
}
}
return null;
},
/**
* Used for sorting the manager's Overlays by z-index.
* @private
*/
compareZIndexDesc : function(o1, o2) {
var zIndex1 = o1.cfg.getProperty("zIndex");
var zIndex2 = o2.cfg.getProperty("zIndex");
if (zIndex1 > zIndex2) {
return -1;
} else if (zIndex1 < zIndex2) {
return 1;
} else {
return 0;
}
},
/**
* Shows all Overlays in the manager.
*/
showAll : function() {
for (var o=0;o<this.overlays.length;o++) {
this.overlays[o].show();
}
},
/**
* Hides all Overlays in the manager.
*/
hideAll : function() {
for (var o=0;o<this.overlays.length;o++) {
this.overlays[o].hide();
}
},
/**
* Returns a string representation of the object.
* @type string
*/
toString : function() {
return "OverlayManager";
}
};
/**
* KeyListener is a utility that provides an easy interface for listening for keydown/keyup events fired against DOM elements.
* @param {Element} attachTo The element or element ID to which the key event should be attached
* @param {string} attachTo The element or element ID to which the key event should be attached
* @param {object} keyData The object literal representing the key(s) to detect. Possible attributes are shift(boolean), alt(boolean), ctrl(boolean) and keys(either an int or an array of ints representing keycodes).
* @param {function} handler The CustomEvent handler to fire when the key event is detected
* @param {object} handler An object literal representing the handler.
* @param {string} event Optional. The event (keydown or keyup) to listen for. Defaults automatically to keydown.
* @constructor
*/
YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
if (! event) {
event = YAHOO.util.KeyListener.KEYDOWN;
}
var keyEvent = new YAHOO.util.CustomEvent("keyPressed");
this.enabledEvent = new YAHOO.util.CustomEvent("enabled");
this.disabledEvent = new YAHOO.util.CustomEvent("disabled");
if (typeof attachTo == 'string') {
attachTo = document.getElementById(attachTo);
}
if (typeof handler == 'function') {
keyEvent.su
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -