(function () {
var _$ = window.$;
var _jquery = window.jquery;
var jQuery = Window.jquery = window.$ = function (selector) {
return new JQuery.fn.init (selector);
};
Jquery.fn = Jquery.prototype = {
Init:function (selector) {
var elements = Document.queryselectorall (selector);
Array.prototype.push.apply (this,elements);
return this;
},
JQuery: "1.0.0",
length:0,
Size:function () {
return this.length;
}
};
JQuery.fn.init.prototype = Jquery.fn;
Jquery.extend = JQuery.fn.extend = function () {
var o = arguments[0];
For (var p in O) {
THIS[P] = o[p];
}
};
Jquery.extend ({
Trim:function (text) {
Return (text| | ""). Replace (/^\s+|\s+$/g, "");
},
Noconflict:function () {
window.$ = _$;
Window.jquery = _jquery;
return jQuery;
}
});
JQuery.fn.extend ({
Get:function (num) {
return This[num];
},
Each:function (FN) {
for (var i = 0;i< this.length; i++) {
FN (I,this[i]);
}
return this;
},
Css:function () {
var L = arguments.length;
if (L = = 1) {
return this[0].style[arguments[0]];
} else {
var name = Arguments[0];
var value = arguments[1];
This.each (function (Index,ele) {
Ele.style[name] = value;
});
}
return this;
},
Hide:function () {//Hide element
This.each (function (Index,ele) {
Ele.style.display = "None";
});
},
Show:function () {//Display element
This.each (function (Index,ele) {
Ele.style.display = "block";
});
},
Addclass:function () {//Add (Class) class
var name = Arguments[0];
This.each (function (Index,ele) {
var ele_class = Ele.classname,
Blank = (Ele_class! = ")? ‘ ‘ : ‘‘;
Added = Ele_class + blank + name;
Ele.classname = added;
});
},
Removeclass:function () {//Delete (Class) class
var name = Arguments[0];
This.each (function (Index,ele) {
var obj_class = ' +ele.classname+ ';
Obj_class = Obj_class.replace (/(\s+)/gi, "),
removed = Obj_class.replace (' +name+ ', ');
removed = Removed.replace (/(^\s+) | ( \s+$)/g, ");
Ele.classname = removed;
});
},
Remove:function () {//delete property
var name = Arguments[0];
This.each (function (Index,ele) {
Ele.attributes.removeNamedItem (name);
});
},
Width:function () {//Set width
var name = Arguments[0];
This.each (function (Index,ele) {
Ele.style.width = name;
});
},
Height:function () {//Set height
var name = Arguments[0];
This.each (function (Index,ele) {
Ele.style.height = name;
});
},
Getwidth:function () {//Get object width
This.each (function (Index,ele) {
var GW = Ele.offsetwidth;
Console.log (GW);
});
},
Getheight:function () {//Get object height
This.each (function (Index,ele) {
var gh = ele.offsetheight;
Console.log (GH);
});
},
On:function (eventname,callback) {//on Event
This.each (function (Index,ele) {
Ele[eventname] = callback;
});
},
First:function () {//Gets the first child element of the element
This.each (function (Index,ele) {
var ss = Ele.children[0];
Console.log (ss);
});
},
Allele:function () {//Gets all child elements of the element
This.each (function (Index,ele) {
for (Var i=0;i<ele.children.length;i++) {
var ss = Ele.children[i];
Console.log (ss);
}
});
},
});
})();
Write a mini of jquery