Baidu space popup Result Analysis page 1/3

Source: Internet
Author: User

The pop-up window and drag-and-drop effect of Baidu space looks quite good. Currently, many well-known websites use this technology. Next we will put my down JS Code I analyzed some of them, but there are still many things that I don't understand. I didn't write comments. Please help me explain them. I am a beginner. Please give me some advice on anything wrong.
Let's declare one piece. This code is only used for learning. The technology copyright belongs to Baidu.
It is mainly a file called: Popup. JS, as follows:
/**//*********************************** * *********** Popup. JS *************************************** ***********/
// Add a push method for the array Array
// Add an object to the end of the array
If (! Array. Prototype. Push)
{
Array. Prototype. Push = function ()
{
VaR startlength = This. length;
For (VAR I = 0; I <arguments. length; I ++)
{
This [startlength + I] = arguments [I];
}
Return this. length;
}
};

// Process G Function Parameters
Function g ()
{
// Define an array to save Parameters
VaR elements = new array ();
// Cyclically analyze the parameters in G
For (VAR I = 0; I <arguments. length; I ++)
{
VaR element = arguments [I];

// If the parameter type is string, the object with this parameter as ID is obtained.
If (typeof element = 'string ')
{
Element = Document. getelementbyid (element );
}
// If the parameter length is 1
If (arguments. Length = 1)
{
Return element;
}
// Add the object to the end of the array
Elements. Push (element );
};
Return elements;
};

Function. Prototype. Bind = function (object)
{
VaR _ method = this;
Return function ()
{
_ Method. Apply (object, arguments );
};
};

// Bind events
Function. Prototype. bindaseventlistener = function (object)
{
VaR _ method = this;
Return function (event) {__ method. Call (object, event | window. Event );};
};

Object. Extend = function (destination, source)
{
For (property in source)
{
Destination [property] = source [property];
};
Return destination;
};

If (! Window. Event)
{
VaR event = new object ();
};

Object. Extend (
Event,

{
Observers: false,
Element: function (Event)
{
Return event.tar GET | event. srcelement;
},

Isleftclick: function (Event)
{
Return (event. Which) & (event. Which = 1) | (event. Button) & (event. Button = 1 )));
},

Pointerx: function (Event)
{
Return event. pagex | (event.clientx((document.doc umentelement. scrollleft | document. Body. scrollleft ));
},

Pointery: function (Event)
{
Return event. Pagey | (event.clienty((document.doc umentelement. scrolltop | document. Body. scrolltop ));
},

Stop: function (Event)
{
If (event. preventdefault)
{
Event. preventdefault ();
Event. stoppropagation ();
}
Else
{
Event. returnvalue = false;
Event. cancelbubble = true;
};
},

Findelement: function (event, tagname)
{
VaR element = event. element (event );
While (element. parentnode &&(! Element. tagname | (element. tagname. touppercase ()! = Tagname. touppercase ())))
Element = element. parentnode;
Return element;
},

_ Observeandcache: function (element, name, observer, usecapture)
{
If (! This. Observers)
This. Observers = [];
If (element. addeventlistener)
{
This. Observers. Push ([element, name, observer, usecapture]);
Element. addeventlistener (name, observer, usecapture );
}
Else if (element. attachevent)
{
This. Observers. Push ([element, name, observer, usecapture]);
Element. attachevent ('on' + name, observer );
};
},

Unloadcache: function ()
{
If (! Event. Observers)
Return;
For (VAR I = 0; I <event. Observers. length; I ++)
{
Event. stopobserving. Apply (this, event. Observers [I]);
Event. Observers [I] [0] = NULL;
};
Event. Observers = false;
},

Observe: function (element, name, observer, usecapture)
{
VaR element = g (element );
Usecapture = usecapture | false;
If (name = 'keypress' & (navigator. appversion. Match (/Konqueror | safari | khtml/) | element. attachevent ))
Name = 'keylow ';
This. _ observeandcache (element, name, observer, usecapture );
},

Stopobserving: function (element, name, observer, usecapture)
{
VaR element = g (element );
Usecapture = usecapture | false;
If (name = 'keypress' & (navigator. appversion. Match (/Konqueror | safari | khtml/) | element. detachevent ))
Name = 'keylow ';
If (element. removeeventlistener)
{
Element. removeeventlistener (name, observer, usecapture );
}
Else if (element. detachevent)
{
Element. detachevent ('on' + name, observer );
};
}
}
);

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.