Var Class = {
Create: function (){
Return function (){
This. initialize. apply (this, arguments );
}
}
};
Object. extend = function (destination, source ){
For (var property in source) destination [property] = source [property];
Return destination;
};
Function. prototype. bind = function (object ){
Var _ method = this;
Return function (){
// Replace this in _ method with the object and call the _ method
Return _ method. apply (object, arguments );
}
};
// ForEach method: change this to a bind object, and call the fn method with the parameter this [I]. this [I] is the current array element, and I is the current index.
If (! Array. prototype. forEach ){
Array. prototype. forEach = function (fn, bind ){
For (var I = 0; I <this. length; I ++) fn. call (bind, this [I], I );
};
}
// The each method is the same as forEach.
Array. prototype. each = Array. prototype. forEach;
// The method for returning the string camel. e.g. "font-color". camelize ()-> fontColor, Which is required when processing css attributes
String. prototype. camelize = function (){
Return this. replace (/-\ D/gi, function (match ){
Return match. charAt (match. length-1). toUpperCase ();
});
};
Var $ A = function (iterable ){
Var nArray = [];
For (var I = 0; I <iterable. length; I ++) nArray. push (iterable [I]);
Return nArray;
};
/*
* If the input parameter is one, an element is returned. Otherwise, an array is returned.
**/
Function $ (){
If (arguments. length = 1) return get $ (arguments [0]);
Var elements = [];
$ C (arguments). each (function (el ){
Elements. push (get $ (el ));
});
Return elements;
Function get $ (el ){
If (typeof el = 'string') el = document. getElementById (el );
Return el;
}
};
If (! Window. Element) var Element = {};
Object. extend (Element ,{
Remove: function (element) {// delete a specified element
Element = $ (element );
Element. parentNode. removeChild (element );
},
HasClassName: function (element, className) {// checks whether the specified element has a corresponding css class.
Element = $ (element );
Return !! Element. className. match (new RegExp ("\ B" + className + "\ B "));
},
AddClassName: function (element, className) {// Add the specified css to the corresponding element
Element = $ (element );
If (! Element. hasClassName (element, className) element. className = (element. className + ''+ className );
},
RemoveClassName: function (element, className) {// Delete the specified css from the corresponding element.
Element = $ (element );
If (Element. hasClassName (element, className) element. className = element. className. replace (className ,'');
}
});
// Return elements with the same css class.
Document. getElementsByClassName = function (className ){
Var elements = [];
Var all = document. getElementsByTagName ('*');
$ A (all). each (function (el ){
If (Element. hasClassName (el, className) elements. push (el );
});
Return elements;
};