-------------------------------

Source: Internet
Author: User

$ (Function (window) {var o = {//Remove space trim = function (str) {if (String.prototype.trim) {return str = = Null?        "": String.prototype.trim.call (str); }else{return Str.replace (/(^\s*) | (        \s*$)/g, ""); }},//Gets the first dom of the element = function (el, selector) {//Parameter 1 if (arguments.length = = = 1 && typeof Argume            Nts[0] = = ' String ') {if (document.queryselector) {return document.queryselector (arguments[0]); }//Parameters are 2}else if (arguments.length = = = 2) {if (el.queryselector) {RET            Urn El.queryselector (selector); }        }    },
Back to the collection of elements Domall = function (el, selector) {if (arguments.length = = = 1 && typeof arguments[0] = = ' string ') {if (Document.queryselectorall) {return Document.queryselectorall (arguments[0]); }}else if (arguments.length = = = 2) {if (El.queryselectorall) {return El.queryselectorall (s Elector); } } },
Determines the array IsArray = function (obj) {if (Array.isarray) {return array.isarray (obj); }else{return obj instanceof Array; }},//Add Event Addevt = function (el, name, FN, usecapture) {var usecapture = Usecapture | | false; if (El.addeventlistener) {el.addeventlistener (name, FN, usecapture); }},//remove Event rmevt = function (el, name, FN, usecapture) {var usecapture = Usecapture | | false; if (El.removeeventlistener) {el.removeeventlistener (name, FN, usecapture); }},//Gets the first element, primary = function (EL, selector) {if (arguments.length = = = 1) {return el.children[0 ]; } if (arguments.length = = = 2) {return This.dom (el, selector+ ': First-child '); }},//gets last element = function (el, selector) {if (arguments.length = = = 1) {var children = el.ch Ildren; return children[children.length-1]; } if (arguments. length = = 2) {return This.dom (el, selector+ ': Last-child '); }},//Gets the element's index EQ = function (el, index) {return this.dom (el, ': nth-child (' + index + ') '); },//except this element does = function (el, selector) {return This.domall (el, ': not (' + selector + ') '); },//previous element prev = function (EL) {var node = el.previoussibling; if (node.nodetype && node.nodetype = = = 3) {node = node.previoussibling; return node; }},//next element next = function (EL) {var node = el.nextsibling; if (node.nodetype && node.nodetype = = = 3) {node = node.nextsibling; return node; } },
Event delegate matching element ancestor element closest = function (el, selector) {var doms, targetdom; var issame = function (Doms, EL) {var i = 0, len = doms.length; for (i; i<len; i++) {if (Doms[i].isequalnode (EL)) {return doms[i]; }} return false; }; var traversal = function (el, selector) {doms = U.domall (El.parentnode, selector); Targetdom = Issame (Doms, EL); while (!targetdom) {el = El.parentnode; if (el! = null && El.nodetype = = El. Document_node) {return false; } traversal (el, selector); } return targetdom; }; Return traversal (EL, selector); },//remove element remove = function (EL) {if (El && el.parentnode) {el.parentNode.removeChild (EL); }},//Set property to get element attr = function (el, name, value{if (arguments.length = = 2) {return el.getattribute (name); }else if (arguments.length = = 3) {El.setattribute (name, value); Return el; }},//Remove the attribute of the element removeattr = function (el, name) {if (arguments.length = = = 2) {El.removeattribute ( name); }},//To determine if there is a class Hascls = function (EL, CLS) {if (el.className.indexOf (CLS) >-1) {return Tru E }else{return false; }},//Add Class Addcls = function (EL, CLS) {if (' Classlist ' in El) {El.classList.add (CLS); }else{var precls = el.classname; var newcls = precls + "+ cls; El.classname = Newcls; } return el; },//delete Class Removecls = function (EL, CLS) {if (' Classlist ' in El) {el.classList.remove (CLS); }else{var precls = el.classname; var newcls = precls.replace (CLS, "); El. className = Newcls; } return el; },//Add or remove animations Togglecls = function (EL, CLS) {if (' Classlist ' in El) {el.classList.toggle (CLS); }else{if (U.hascls (El, CLS)) {u.addcls (El, CLS); }else{u.removecls (el, CLS); }} return el; },//Gets or changes the value of the element val = function (El, Val) {if (arguments.length = = = 1) {switch (el.tagname) { Case ' SELECT ': var value = El.options[el.selectedindex].value; return value; Break Case ' INPUT ': return el.value; Break Case ' TEXTAREA ': return el.value; Break }} if (arguments.length = = = 2) {switch (el.tagname) {case ' SELECT ': El.options[el.selectedindex].value = val;Return el; Break Case ' INPUT ': El.value = val; Return el; Break Case ' TEXTAREA ': El.value = val; Return el; Break }}}, prepend = function (el, HTML) {el.insertadjacenthtml (' afterbegin ', HTML); Return el; }, append = function (el, HTML) {el.insertadjacenthtml (' beforeend ', HTML); Return el; }, before = function (el, HTML) {el.insertadjacenthtml (' beforebegin ', HTML); Return el; }, after = function (el, HTML) {el.insertadjacenthtml (' afterend ', HTML); Return el; },//Get or change HTML code HTML = function (el, HTML) {if (arguments.length = = = 1) {return el.innerhtml; }else if (arguments.length = = = 2) {el.innerhtml = html; Return el; }},//Get or change text = function (EL, TXT) {if (arguments.length = = = 1) {return el.textcontent; }else if (arguments.length = = = 2) {el.textcontent = txt; Return el; }}, the//object is located at the distance of the page visible content offset = function (EL) {var sl, St; if (document.documentelement) {sl = Document.documentElement.scrollLeft; st = Document.documentElement.scrollTop; }else{SL = Document.body.scrollLeft; st = Document.body.scrollTop; } var rect = El.getboundingclientrect (); return {l:rect.left + SL, t:rect.top + St, w:el.offsetwidth, H:el.offseth eight}; }, CSS = function (el, CSS) {if (typeof css = = ' string ' && css.indexof (': ') > 0) {El.style & amp;& (El.style.cssText + = '; ' + CSS); } }; Get the element css Cssval = function (el, prop) {if (arguments.length = = = 2) {var computedstyle = window.getcom putedStyle (EL, null); Return Computedstyle.getpropertyvalue (prop); }},//json converted to string jsontostr = function (JSON) {if (typeof json = = = ' object ') {return JSON &AMP;&A mp Json.stringify (JSON); }},//String conversion json Strtojson = function (str) {if (typeof str = = = ' String ') {return JSON && Json.parse (str); }},//Add cache information Setstorage = function (key, value) {if (arguments.length = = = 2) {var v = value; if (typeof v = = ' object ') {v = json.stringify (v); v = ' obj-' + V; }else{v = ' str-' + V; } var ls = uzstorage (); if (LS) {ls.setitem (key, V); }}},//get cache information GetStorage = function (key) {var ls = uzstorage (); if (LS) {var v = ls.getitem (key); if (!v) {return;} if (V.indexof (' obj-') = = = 0) {v = v.slice (4); return Json.parse (v); }else if (v.indexof (' str-') = = = 0) {return V.slice (4); }}},//remove cache information Removestorage = function (key) {var ls = uzstorage (); if (LS && key) {Ls.removeitem (key); }},//Clear all cache information Clearstorage = function () {var ls = uzstorage (); if (LS) {ls.clear (); }}, U.fixios7bar = function (EL) {var strdm = Api.systemtype; if (STRDM = = ' iOS ') {var strsv = api.systemversion; var numsv = parseint (strsv,10); var fullscreen = Api.fullscreen; var ios7statusbarappearance = api.ios7statusbarappearance; if (numsv >= 7 &&!fullscreen && ios7statusbarappearance) {el.style.paddingTop = ' 20px ' ; }}, Post = function (/*url,data,fnsuc,datatype*/) {var Argstojson = parsearguments.apply (null, Argum Ents); var json = {}; var fnsuc = argstojson.fnsuc; Argstojson.url && (json.url = Argstojson.url); Argstojson.data && (json.data = argstojson.data); if (argstojson.datatype) {var type = toLowerCase (Argstojson.datatype); if (type = = ' Text ' | | Type = = ' json ') {json.datatype = type; }}else{json.datatype = ' json '; }; Json.method = ' post '; Api.ajax (JSON, function (Ret,err) {if (ret) {fnsuc && fnsuc (ret); }; } ); }, get = function (/*url,fnsuc,datatype*/) {var Argstojson = parsearguments.apply (null, arguments); var json = {}; var fnsuc = argstojson.fnsuc; Argstojson.url && (json.url = Argstojson.url); Argstojson.data && (json.data = argstojson.data); if (argstojson.datatype) {var type = toLowerCase (argstojsOn.datatype); if (type = = ' Text ' | | Type = = ' json ') {json.datatype = type; }}else{json.datatype = ' text '; }; Json.method = ' get '; Api.ajax (JSON, function (Ret,err) {if (ret) {fnsuc && fnsuc (ret); }; } ); };}; Window.zhanglei = o;}) (window)

  

-------------------------------

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.