// regex cache var patterns = {
HYPHEN: /(-[a-z])/i, // to normalize get/setStyle
ROOT_TAG: /^body|html$/i, // body for quirks mode, html for standards,
OP_SCROLL:/^(?:inline|table-row)$/i
};
var toCamel = function(property) { if ( !patterns.HYPHEN.test(property) ) { return property; // no hyphens
}
if (propertyCache[property]) { // already converted return propertyCache[property];
}
propertyCache[property] = converted; return converted; //return property.replace(/-([a-z])/gi, function(m0, m1) {return m1.toUpperCase()}) // cant use function as 2nd arg yet due to safari bug
};
var getClassRegEx = function(className) { var re = reClassNameCache[className]; if (!re) {
re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
reClassNameCache[className] = re;
} return re;
};
// branching at load instead of runtime if (document.defaultView && document.defaultView.getComputedStyle) { // W3C DOM method
getStyle = function(el, property) { var value = null;
if (property == 'float') { // fix reserved word
property = 'cssFloat';
}
var computed = el.ownerDocument.defaultView.getComputedStyle(el, ''); if (computed) { // test computed before touching for safari
value = computed[toCamel(property)];
}
return el.style[property] || value;
};
} elseif (document.documentElement.currentStyle && isIE) { // IE method
getStyle = function(el, property) { switch( toCamel(property) ) { case'opacity' :// IE opacity uses filter var val = 100; try { // will error if no DXImageTransform
val = el.filters['DXImageTransform.Microsoft.Alpha'].opacity;
} catch(e) { try { // make sure its in the document
val = el.filters('alpha').opacity;
} catch(e) {
}
} return val / 100; case'float': // fix reserved word
property = 'styleFloat'; // fall through default: // test currentStyle before touching var value = el.currentStyle ? el.currentStyle[property] : null; return ( el.style[property] || value );
}
};
} else { // default to inline only
getStyle = function(el, property) { return el.style[property]; };
}
if (isIE) {
setStyle = function(el, property, val) { switch (property) { case'opacity': if ( lang.isString(el.style.filter) ) { // in case not appended
el.style.filter = 'alpha(opacity=' + val * 100 + ')';
var f = function(element) {
setStyle(element, property, val);
};
Y.Dom.batch(el, f, Y.Dom, true);
},
/** *Getsthecurrentpositionofanelementbasedonpagecoordinates.ElementmustbepartoftheDOMtreetohavepagecoordinates(display:noneorelementsnotappendedreturnfalse). *@methodgetXY *@param{String|HTMLElement|Array}elAcceptsastringtouseasanID,anactualDOMreference,oranArrayofIDsand/orHTMLElements *@return{Array}TheXYpositionoftheelement(s)
*/
getXY: function(el) { var f = function(el) { // has to be part of document to have pageXY if ( (el.parentNode === null || el.offsetParent === null || this.getStyle(el, 'display') == 'none') && el != el.ownerDocument.body) { returnfalse;
}
return getXY(el);
};
return Y.Dom.batch(el, f, Y.Dom, true);
},
/** *GetsthecurrentXpositionofanelementbasedonpagecoordinates.TheelementmustbepartoftheDOMtreetohavepagecoordinates(display:noneorelementsnotappendedreturnfalse). *@methodgetX *@param{String|HTMLElement|Array}elAcceptsastringtouseasanID,anactualDOMreference,oranArrayofIDsand/orHTMLElements *@return{Number|Array}TheXpositionoftheelement(s)
*/
getX: function(el) { var f = function(el) { return Y.Dom.getXY(el)[0];
};
return Y.Dom.batch(el, f, Y.Dom, true);
},
/** *GetsthecurrentYpositionofanelementbasedonpagecoordinates.ElementmustbepartoftheDOMtreetohavepagecoordinates(display:noneorelementsnotappendedreturnfalse). *@methodgetY *@param{String|HTMLElement|Array}elAcceptsastringtouseasanID,anactualDOMreference,oranArrayofIDsand/orHTMLElements *@return{Number|Array}TheYpositionoftheelement(s)
*/
getY: function(el) { var f = function(el) { return Y.Dom.getXY(el)[1];
};
return Y.Dom.batch(el, f, Y.Dom, true);
},
/** *Setthepositionofanhtmlelementinpagecoordinates,regardlessofhowtheelementispositioned. *Theelement(s)mustbepartoftheDOMtreetohavepagecoordinates(display:noneorelementsnotappendedreturnfalse). *@methodsetXY *@param{String|HTMLElement|Array}elAcceptsastringtouseasanID,anactualDOMreference,oranArrayofIDsand/orHTMLElements *@param{Array}posContainsX&Yvaluesfornewposition(coordinatesarepage-based) *@param{Boolean}noRetryBydefaultwetryandsetthepositionasecondtimeifthefirstfails
*/
setXY: function(el, pos, noRetry) { var f = function(el) { var style_pos = this.getStyle(el, 'position'); if (style_pos == 'static') { // default to relative this.setStyle(el, 'position', 'relative');
style_pos = 'relative';
}
var pageXY = this.getXY(el); if (pageXY === false) { // has to be part of doc to have pageXY returnfalse;
}
var delta = [ // assuming pixels; if not we will have to retry
parseInt( this.getStyle(el, 'left'), 10 ),
parseInt( this.getStyle(el, 'top'), 10 )
];
if ( isNaN(delta[0]) ) {// in case of 'auto'
delta[0] = (style_pos == 'relative') ? 0 : el.offsetLeft;
} if ( isNaN(delta[1]) ) { // in case of 'auto'
delta[1] = (style_pos == 'relative') ? 0 : el.offsetTop;
}
// if retry is true, try one more time if we miss if ( (pos[0] !== null && newXY[0] != pos[0]) ||
(pos[1] !== null && newXY[1] != pos[1]) ) { this.setXY(el, pos, true);
}
}
var nodes = [],
elements = root.getElementsByTagName(tag),
re = getClassRegEx(className);
for (var i = 0, len = elements.length; i < len; ++i) { if ( re.test(elements[i].className) ) {
nodes[nodes.length] = elements[i]; if (apply) {
apply.call(elements[i], elements[i]);
}
}
}
return nodes;
},
/** *DetermineswhetheranHTMLElementhasthegivenclassName. *@methodhasClass *@param{String|HTMLElement|Array}elTheelementorcollectiontotest *@param{String}classNametheclassnametosearchfor *@return{Boolean|Array}Abooleanvalueorarrayofbooleanvalues
*/
hasClass: function(el, className) { var re = getClassRegEx(className);
var f = function(el) { return re.test(el.className);
};
return Y.Dom.batch(el, f, Y.Dom, true);
},
/** *Addsaclassnametoagivenelementorcollectionofelements. *@methodaddClass *@param{String|HTMLElement|Array}elTheelementorcollectiontoaddtheclassto *@param{String}classNametheclassnametoaddtotheclassattribute *@return{Boolean|Array}Apass/failbooleanorarrayofbooleans
*/
addClass: function(el, className) { var f = function(el) { if (this.hasClass(el, className)) { returnfalse; // already present
}
var nodes = [],
elements = root.getElementsByTagName(tag);
for (var i = 0, len = elements.length; i < len; ++i) { if ( method(elements[i]) ) {
nodes[nodes.length] = elements[i]; if (apply) {
apply(elements[i]);
}
}
}
return nodes;
},
/** *RunsthesuppliedmethodagainsteachitemintheCollection/Array. *Themethodiscalledwiththeelement(s)asthefirstarg,andtheoptionalparamasthesecond(method(el,o)). *@methodbatch *@param{String|HTMLElement|Array}el(optional)Anelementorarrayofelementstoapplythemethodto *@param{Function}methodThemethodtoapplytotheelement(s) *@param{Any}o(optional)Anoptionalargthatispassedtothesuppliedmethod *@param{Boolean}override(optional)Whetherornottooverridethescopeof"method"with"o" *@return{Any|Array}Thereturnvalue(s)fromthesuppliedmethod
*/
batch: function(el, method, o, override) {
el = (el && (el.tagName || el.item)) ? el : Y.Dom.get(el); // skip get() when possible
if (!el || !method) { returnfalse;
} var scope = (override) ? o : window;
if (el.tagName || el.length === undefined) { // element or not array-like return method.call(scope, el, o);
}
var collection = [];
for (var i = 0, len = el.length; i < len; ++i) {
collection[collection.length] = method.call(scope, el[i], o);
}
/** *ReturnsanarrayofHTMLElementchildNodesthatpassthetestmethod. *@methodgetChildrenBy *@param{HTMLElement}nodeTheHTMLElementtostartfrom *@param{Function}methodAbooleanfunctionusedtotestchildren *thatreceivesthenodebeingtestedasitsonlyargument *@return{Array}AstaticarrayofHTMLElements
*/
getChildrenBy: function(node, method) { var child = Y.Dom.getFirstChildBy(node, method); var children = child ? [child] : [];
Y.Dom.getNextSiblingBy(child, function(node) { if ( !method || method(node) ) {
children[children.length] = node;
} returnfalse; // fail test to collect all children
});
/** *CreatesaRegionbasedontheviewportrelativetothedocument. *@methodgetClientRegion *@return{Region}ARegionobjectrepresentingtheviewportwhichaccountsfordocumentscroll
*/
getClientRegion: function() { var t = Y.Dom.getDocumentScrollTop(),
l = Y.Dom.getDocumentScrollLeft(),
r = Y.Dom.getViewportWidth() + l,
b = Y.Dom.getViewportHeight() + t;
returnnew Y.Region(t, r, b, l);
}
};
var getXY = function() { if (document.documentElement.getBoundingClientRect) { // IE returnfunction(el) { var box = el.getBoundingClientRect(),
round = Math.round;
var rootNode = el.ownerDocument; return [round(box.left + Y.Dom.getDocumentScrollLeft(rootNode)), round(box.top +
Y.Dom.getDocumentScrollTop(rootNode))];
};
} else { returnfunction(el) { // manually calculate by crawling up offsetParents var pos = [el.offsetLeft, el.offsetTop]; var parentNode = el.offsetParent;
// safari: subtract body offsets if el is abs (or any offsetParent), unless body is offsetParent var accountForBody = (isSafari &&
Y.Dom.getStyle(el, 'position') == 'absolute' &&
el.offsetParent == el.ownerDocument.body);
if (accountForBody) { //safari doubles in this case
pos[0] -= el.ownerDocument.body.offsetLeft;
pos[1] -= el.ownerDocument.body.offsetTop;
}
parentNode = el.parentNode;
// account for any scrolled ancestors while ( parentNode.tagName && !patterns.ROOT_TAG.test(parentNode.tagName) )
{ if (parentNode.scrollTop || parentNode.scrollLeft) {
pos[0] -= parentNode.scrollLeft;
pos[1] -= parentNode.scrollTop;
}
/** *Returnstheregionwherethepassedinregionoverlapswiththisone *@methodintersect *@param{Region}regionTheregionthatintersects *@return{Region}Theoverlapregion,ornullifthereisnooverlap
*/
YAHOO.util.Region.prototype.intersect = function(region) { var t = Math.max( this.top, region.top ); var r = Math.min( this.right, region.right ); var b = Math.min( this.bottom, region.bottom ); var l = Math.max( this.left, region.left );
if (b >= t && r >= l) { returnnew YAHOO.util.Region(t, r, b, l);
} else { returnnull;
}
};
/** *Returnstheregionrepresentingthesmallestregionthatcancontainboth *thepassedinregionandthisregion. *@methodunion *@param{Region}regionTheregionthattocreatetheunionwith *@return{Region}Theunionregion
*/
YAHOO.util.Region.prototype.union = function(region) { var t = Math.min( this.top, region.top ); var r = Math.max( this.right, region.right ); var b = Math.max( this.bottom, region.bottom ); var l = Math.min( this.left, region.left );
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.