element.js
来自「php绿色服务器,让大家试用greenamp」· JavaScript 代码 · 共 1,746 行 · 第 1/5 页
JS
1,746 行
this.setHeight(height, animate, duration, function(){
this.unclip();
if(typeof onComplete == "function") onComplete();
}.createDelegate(this), easing);
}
}.createDelegate(this), 0);
return this;
},
/**
* Returns true if this element is an ancestor of the passed element
* @param {HTMLElement/String} el
* @return {Boolean}
*/
contains : function(el){
if(!el){return false;}
return D.isAncestor(this.dom, el.dom ? el.dom : el);
},
/**
* Checks whether the element is currently visible using both visibility and display properties.
* @param {Boolean} deep True to walk the dom and see if parent elements are hidden.
* @return {Boolean} true if the element is currently visible
*/
isVisible : function(deep) {
var vis = !(this.getStyle("visibility") == "hidden" || this.getStyle("display") == "none");
if(deep !== true || !vis){
return vis;
}
var p = this.dom.parentNode;
while(p && p.tagName.toLowerCase() != "body"){
if(!Ext.fly(p, '_isVisible').isVisible()){
return false;
}
p = p.parentNode;
}
return true;
},
/**
* Creates a CompositeElement for child nodes based on the passed CSS selector (the selector should not contain an id)
* @param {String} selector The CSS selector
* @param {Boolean} unique true to create a unique Ext.Element for each child (defaults to a shared flyweight object)
* @return {CompositeElement/CompositeElementLite} The composite element
*/
select : function(selector, unique){
return El.select("#" + Ext.id(this.dom) + " " + selector, unique);
},
/**
* Selects child nodes based on the passed CSS selector (the selector should not contain an id)
* @param {String} selector The CSS selector
* @return {Array} An array of the matched nodes
*/
query : function(selector, unique){
return Ext.DomQuery.select("#" + Ext.id(this.dom) + " " + selector);
},
/**
* Selects a single child based on the passed CSS selector (the selector should not contain an id)
* @param {String} selector The CSS selector
* @param {Boolean} returnDom true to return the DOM node instead of Ext.Element
* @return {Element} The element
*/
child : function(selector, returnDom){
var n = Ext.DomQuery.selectNode("#" + Ext.id(this.dom) + " " + selector);
return returnDom ? n : Ext.get(n);
},
/**
* Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id)
* @param {String} selector The CSS selector
* @param {Boolean} returnDom true to return the DOM node instead of Ext.Element
* @return {Element} The element
*/
down : function(selector, returnDom){
var n = Ext.DomQuery.selectNode("#" + Ext.id(this.dom) + " > " + selector);
return returnDom ? n : Ext.get(n);
},
/**
* Initializes a Ext.dd.DD object for this element.
* @param {String} group The group the DD object is member of
* @param {Object} config The DD config object
* @param {Object} overrides An object containing methods to override/implement on the DD object
* @return {Ext.dd.DD} The DD object
*/
initDD : function(group, config, overrides){
var dd = new Ext.dd.DD(Ext.id(this.dom), group, config);
return Ext.apply(dd, overrides);
},
/**
* Initializes a Ext.dd.DDProxy object for this element.
* @param {String} group The group the DDProxy object is member of
* @param {Object} config The DDProxy config object
* @param {Object} overrides An object containing methods to override/implement on the DDProxy object
* @return {Ext.dd.DDProxy} The DDProxy object
*/
initDDProxy : function(group, config, overrides){
var dd = new Ext.dd.DDProxy(Ext.id(this.dom), group, config);
return Ext.apply(dd, overrides);
},
/**
* Initializes a Ext.dd.DDTarget object for this element.
* @param {String} group The group the DDTarget object is member of
* @param {Object} config The DDTarget config object
* @param {Object} overrides An object containing methods to override/implement on the DDTarget object
* @return {Ext.dd.DDTarget} The DDTarget object
*/
initDDTarget : function(group, config, overrides){
var dd = new Ext.dd.DDTarget(Ext.id(this.dom), group, config);
return Ext.apply(dd, overrides);
},
/**
* Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
* the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
* @param {Boolean} visible Whether the element is visible
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Ext.Element} this
*/
setVisible : function(visible, animate){
if(!animate || !A){
if(this.visibilityMode == El.DISPLAY){
this.setDisplayed(visible);
}else{
this.fixDisplay();
this.dom.style.visibility = visible ? "visible" : "hidden";
}
}else{
// closure for composites
var dom = this.dom;
var visMode = this.visibilityMode;
if(visible){
this.setOpacity(.01);
this.setVisible(true);
}
this.anim({opacity: { to: (visible?1:0) }},
this.preanim(arguments, 1),
null, .35, 'easeIn', function(){
if(!visible){
if(visMode == El.DISPLAY){
dom.style.display = "none";
}else{
dom.style.visibility = "hidden";
}
Ext.get(dom).setOpacity(1);
}
});
}
return this;
},
/**
* Returns true if display is not "none"
* @return {Boolean}
*/
isDisplayed : function() {
return this.getStyle("display") != "none";
},
/**
* Toggles the elements visibility or display, depending on visibility mode.
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Ext.Element} this
*/
toggle : function(animate){
this.setVisible(!this.isVisible(), this.preanim(arguments, 0));
return this;
},
/**
* Sets the css display. Uses originalDisplay if value is a boolean true.
* @param {Boolean} value Boolean to display the element using its default display or a string to set the display directly
* @return {Ext.Element} this
*/
setDisplayed : function(value) {
if(typeof value == "boolean"){
value = value ? this.originalDisplay : "none";
}
this.setStyle("display", value);
return this;
},
/**
* Tries to focus the element. Any exceptions are caught.
* @return {Ext.Element} this
*/
focus : function() {
try{
this.dom.focus();
}catch(e){}
return this;
},
/**
* Tries to blur the element. Any exceptions are caught.
* @return {Ext.Element} this
*/
blur : function() {
try{
this.dom.blur();
}catch(e){}
return this;
},
/**
* Add a CSS class to the element.
* @param {String/Array} className The CSS class to add or an array of classes
* @return {Ext.Element} this
*/
addClass : function(className){
if(className instanceof Array){
for(var i = 0, len = className.length; i < len; i++) {
this.addClass(className[i]);
}
}else{
if(className && !this.hasClass(className)){
this.dom.className = this.dom.className + " " + className;
}
}
return this;
},
/**
* Adds the passed className to this element and removes the class from all siblings
* @param {String} className The className to add
* @return {Ext.Element} this
*/
radioClass : function(className){
var siblings = this.dom.parentNode.childNodes;
for(var i = 0; i < siblings.length; i++) {
var s = siblings[i];
if(s.nodeType == 1){
Ext.get(s).removeClass(className);
}
}
this.addClass(className);
return this;
},
/**
* Removes a CSS class from the element.
* @param {String/Array} className The CSS class to remove or an array of classes
* @return {Ext.Element} this
*/
removeClass : function(className){
if(!className || !this.dom.className){
return this;
}
if(className instanceof Array){
for(var i = 0, len = className.length; i < len; i++) {
this.removeClass(className[i]);
}
}else{
if(this.hasClass(className)){
var re = this.classReCache[className];
if (!re) {
re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', "g");
this.classReCache[className] = re;
}
this.dom.className =
this.dom.className.replace(re, " ");
}
}
return this;
},
classReCache: {},
/**
* Toggles (adds or removes) the passed class.
* @param {String} className
* @return {Ext.Element} this
*/
toggleClass : function(className){
if(this.hasClass(className)){
this.removeClass(className);
}else{
this.addClass(className);
}
return this;
},
/**
* Checks if a CSS class is in use by the element.
* @param {String} className The CSS class to check
* @return {Boolean} true or false
*/
hasClass : function(className){
return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
},
/**
* Replaces a CSS class on the element with another.
* @param {String} oldClassName The CSS class to replace
* @param {String} newClassName The replacement CSS class
* @return {Ext.Element} this
*/
replaceClass : function(oldClassName, newClassName){
this.removeClass(oldClassName);
this.addClass(newClassName);
return this;
},
/**
* Get an object with properties matching the styles requested.
* e.g. el.getStyles('color', 'font-size', 'width') might return
* {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
* @param {String} style1
* @param {String} style2
* @param {String} etc
* @return Object
*/
getStyles : function(){
var a = arguments, len = a.length, r = {};
for(var i = 0; i < len; i++){
r[a[i]] = this.getStyle(a[i]);
}
return r;
},
/**
* Normalizes currentStyle and computedStyle. This is not YUI getStyle, it is an optimised version.
* @param {String} property The style property whose value is returned.
* @return {String} The current value of the style property for this element.
*/
getStyle : function(){
return view && view.getComputedStyle ?
function(prop){
var el = this.dom, v, cs, camel;
if(prop == 'float'){
prop = "cssFloat";
}
if(v = el.style[prop]){
return v;
}
if(cs = view.getComputedStyle(el, "")){
if(!(camel = propCache[prop])){
camel = propCache[prop] = prop.replace(camelRe, camelFn);
}
return cs[camel];
}
return null;
} :
function(prop){
var el = this.dom, v, cs, camel;
if(prop == 'opacity'){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?