Javascript YUI Read code Diary of Yahoo.util.dom-part.2 0_yui. Ext Related

Source: Internet
Author: User
Tags tagname
Batch:function (El, method, O, override) {
Let El always be htmlelement
El = (El && (el.tagname | | el.item))? El:y.dom.get (EL);

if (!el | |!method) {
return false;
}

Determines which objects are returned
var scope = (override)? O:window;

Looks like a 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;
The Pony Supplements

Batch is one of the core of YUI Dom library. Its biggest significance is that it allows most of the other methods of the Dom library
The first argument can be an ID/element object or a set of Id/element objects, reducing the use of loops. Here you can find the use of call and apply. After understanding the batch, come down and see how YUI.util.Dom uses this method, look at two functions at one breath

Getstyle:function (El, property) {
Tocamel function is described later
Property = Tocamel (property);

Get the style of a node
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);

To set the style of a node
var f = function (Element) {
SetStyle (Element, property, Val);
};

Y.dom.batch (EL, F, Y.dom, true);
For specific uses of these two functions, you can look at the relevant documentation. In fact, it is easy to understand how to use the parameters. Look at the two functions above to help you understand how YAHOO.util.Dom.batch is invoked.

Next, a cursory look at the Getxy

Getxy:function (EL) {
var f = function (EL) {
Determine if 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, except that the array element that gets the return value is not the same. Due to the compatibility of browsers, the YAHOO.util.Dom.getXY that are provided to the user are only judged variables and then thrown to the most complex internal getxy function.

OK, leaving too much suspense, the next issue 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.