Batch: function (el, method, o, override ){
// Make el always HTMLElement
El = (el & (el. tagName | el. item ))? El: Y. Dom. get (el );
If (! El |! Method ){
Return false;
}
// Determine the returned object
Var scope = (override )? O: window;
// It looks like an HTMLElement or not an Array
If (el. tagName | el. length = undefined ){
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 );
}
Return collection;
}, Pony supplement
Batch is the core of the YUI Dom library. It makes most of the other methods in the Dom Library
The first parameter of can be an id/element object or a group of id/element objects, reducing the use of loops. Here we can find the call and apply usage. After learning about batch, let's take a look at how YUI. util. Dom uses this method.
GetStyle: function (el, property ){
// The toCamel function is described later.
Property = toCamel (property );
// Obtain the node Style
Var f = function (element ){
Return getStyle (element, property );
};
Return Y. Dom. batch (el, f, Y. Dom, true );
}, SetStyle: function (el, property, val ){
Property = toCamel (property );
// Set the node Style
Var f = function (element ){
SetStyle (element, property, val );
};
Y. Dom. batch (el, f, Y. Dom, true );
}. For more information about the usage of these two functions, see the relevant documentation. In fact, it is easy to understand how to use parameters. The above two functions help to understand the call methods of YAHOO. util. Dom. batch.
Next, let's take a rough look at getXY.
GetXY: function (el ){
Var f = function (el ){
// Determine whether the element is "visible to the naked eye"
If (el. parentNode = null | el. offsetParent = null |
This. getStyle (el, 'display') = 'None ')&&
El! = El. ownerDocument. body ){
Return false;
}
Return getXY (el );
};
Return Y. Dom. batch (el, f, Y. Dom, true );
}, The getX and getY methods also call this function, but the array elements that obtain the returned values are different. Due to browser compatibility issues, YAHOO. util. Dom. getXY, which is provided to users, is only used to judge the variable and then throw it to the most complex internal getXY function.
OK, leaving too many "suspense". In the next issue, we will focus on solving them.