YAHOO. util. Dom-Part.2 0

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.