SOURCE analysis of jquery1.7.2 (v) $.support

Source: Internet
Author: User

$.support's English comments are described in detail here, just a little bit of writing down

Query.support = (function () {var support,all,a,select,opt,input,fragment,tds,events,eventname,i,issupported,div = Document.createelement ("div"), documentelement = document.documentelement;//preliminary Testsdiv.setAttribute (" ClassName "," T ");d iv.innerhtml ="
  
 
Aall = Div.getelementsbytagname ("*"); a = Div.getelementsbytagname ("a") [0];//can ' t get basic test support//cannot support the most basic Supports an object that returns support as NULL if (!all | |!all.length | |!a) {return {};} First batch of supports Testsselect = Document.createelement ("select"); opt = Select.appendchild (document.createeleme NT ("option")); input = Div.getelementsbytagname ("input") [0];support = {//IE strips leading whitespace when. InnerHTML is used IE with space use//This code, first create a Div, then use InnerHTML to assign a value to div,//And then check whether the first child element of the Div NodeType is 3 (for text),//is the blank character is insured remain, otherwise not retained. Leadingwhitespace: (Div.firstChild.nodeType = = = 3),//Ensure that tbody is not automatically inserted, in IE tbody is automatically inserted//make sure that tbody elements a ren ' t automatically inserted//IE would insert them into empty tablestbody:!div.getelementsbytagname ("Tbody"). length,// Make sure link is serialized//makes sure that link elements get serialized correctly by innerhtml//This requires a wrapper element in IE on I E requires a contained element htmlserialize:!! Div.getelementsbytagname ("link"). length,//Get TheStyle information from getattribute get information through getattribute//(ie uses. csstext instead) IE uses csstext instead of Style:/top/.test (a.get Attribute ("style")),//Make sure this URLs aren ' t manipulated//(IE normalizes it by default) hrefnormalized: (A.getattri Bute ("href") = = = = "/A"),/Make sure that element opacity exists//(IE uses filter instead)//use a regex to work around a WebKit issue. See #5145opacity:/^0.55/.test (a.style.opacity),//Verify style float existence//(IE uses stylefloat instead of Cssfloa T) Cssfloat:!! a.style.cssfloat,//Make sure so if no value is specified for a checkbox//the IT defaults to "on".//(WebKit defaults To "" instead) Checkon: (Input.value = = = "on"),/Make sure that a selected-by-default option have a working selected prop erty.//(WebKit defaults to False instead of true, IE too, if it's in an optgroup) optselected:opt.selected,//Test Setatt Ribute on CamelCase class. If It works, we need attrfixes when doing Get/setattribute (IE6/7) GetSetAttribute:div.clasSName!== "T",//Tests for enctype support on a form (#6743) Enctype:!! Document.createelement ("form"). enctype,//makes sure cloning an HTML5 element does not cause problems//Where outerhtml is Undefined, this still workshtml5Clone:document.createElement ("Nav"). CloneNode (True). outerHTML!== "<:nav> ",//would be defined latersubmitbubbles:true,changebubbles:true,focusinbubbles:false,deleteexpando:true, Nocloneevent:true,inlineblockneedslayout:false,shrinkwrapblocks:false,reliablemarginright:true,pixelmargin: true};//Jquery.boxmodel DEPRECATED in 1.3, use jQuery.support.boxModel Insteadjquery.boxmodel = Support.boxmodel = (docu Ment.compatmode = = = "Css1compat");/make sure checked status is properly clonedinput.checked = True;support.noclonecheck ed = Input.clonenode (True). checked;//Make sure the options inside disabled selects aren ' t marked as disabled//(We Bkit marks them as disabled) select.disabled = true;support.optdisabled =!opt.disabled;//Test to see if it's possible to Delete an expando from a element//fails in Internet explorertry {delete div.test;} catch (e) {Support.deleteexpando = f Alse;} if (!div.addeventlistener && div.attachevent && div.fireevent) {div.attachevent ("onclick", function () {//Cloning a node shouldn ' t copy over any//Bound event handlers (IE does this) support.nocloneevent = false;}); Div.clonenode (True). FireEvent ("onclick");} Check If a radio maintains its value//after being appended to the Dominput = document.createelement ("input"); Input.val UE = "T"; Input.setattribute ("type", "Radio"), Support.radiovalue = Input.value = = = "T"; Input.setattribute ("Checked", " Checked "),//#11217-webkit loses check when the name was after the checked Attributeinput.setattribute (" name "," T ");d IV . appendchild (input); fragment = Document.createdocumentfragment (); Fragment.appendchild (div.lastchild);//WebKit Doesn ' t clone checked state correctly in Fragmentssupport.checkclone = Fragment.clonenode (True). CloneNode (True). Lastch ild.checked;//Check If a disconnected checkbox would retain its checked//value of true after appended to the DOM (IE6/7) s upport.appendchecked = Input.checked;fragment.removechild (input); Fragment.appendchild (div);//technique from Juriy zaytsev//HTTP://PERFECTIONKILLS.COM/DETECTING-Event-support-without-browser-sniffing///We only care about the case where non-standard event systems//is used, namely I N IE. short-circuiting here helps us to//avoid a eval call (in SetAttribute) which can cause csp//to go haywire. see:https://developer.mozilla.org/en/security/csp//The function of this code is to test the bubbling support of IE//$.support[' changebubbles ']if ( Div.attachevent) {for (I-in {submit:1,change:1,focusin:1}) {eventName = ' on ' + i;issupported = (eventName in div); I F (!issupported) {Div.setattribute (EventName, "return;"); issupported = (typeof div[EventName] = = = "function");} support[i + "Bubbles"] = issupported;}} Fragment.removechild (div);//Null elements to avoid leaks in iefragment = select = Opt = div = input = null;//Run tests That need a body at Doc Readyjquery (function () {var container, outer, inner, table, TD, Offsetsupport,margindiv, Conmargi NTOP, style, HTML, positiontopleftwidthheight,paddingmarginbordervisibility, Paddingmarginborder,body = Document.getelementsbytagnaMe ("Body") [0];if (!body) {//Return for frameset docs, that don ' t has a bodyreturn;} Conmargintop = 1;paddingmarginborder = "Padding:0;margin:0;border:";p ositiontopleftwidthheight = "Position:absolute; top:0;left:0;width:1px;height:1px; "; paddingmarginbordervisibility = Paddingmarginborder + "0;visibility:hidden;"; style = "style=" + positiontopleftwidthheight + paddingmarginborder + "5px solid #000;"; HTML = "" + " " +"
"; container = document.createelement (" div "); container.style.cssText = paddingmarginbordervisibility +" width:0; Height:0;position:static;top:0;margin-top: "+ conmargintop +" px "; Body.insertbefore (container, body.firstchild);// Construct the test elementdiv = document.createelement ("div"); Container.appendchild (div);//Check If table cells still h Ave Offsetwidth/height when they is set//to Display:none and there is still other visible table cells in a//table row; If so, offsetwidth/height is not reliable for use when//determining if a element has been hidden directly using//disp Lay:none (It is still safe to use offsets if a parent element is//hidden; Don safety goggles and see bug #4512 for more I nformation).//(only IE 8 fails this test) div.innerhtml = "
t
"TDS = Div.getelementsbytagname (" TD "); issupported = (tds[0].offsetheight = = = 0); tds[0].style.display =" "; tds[1 ].style.display = "none";//Check if empty table cells still has offsetwidth/height//(IE <= 8 fail this test) support. Reliablehiddenoffsets = issupported && (tds[0].offsetheight = = = 0);//Check if div with explicit width and no Margin-right incorrectly//gets computed margin-right based on width of container. For more//info See bugs #3333//Fails in WebKit before Feb nightlies//WebKit bug 13343-getcomputedstyle returns WR Ong value for Margin-rightif (window.getcomputedstyle) {div.innerhtml = ""; margindiv = document.createelement ("div"); m ArginDiv.style.width = "0"; marginDiv.style.marginRight = "0";d iv.style.width = "2px";d iv.appendchild (Margindiv); Support.reliablemarginright = (parseint ((window.getComputedStyle (margindiv, null) | | {marginright:0}). MarginRight, 10) | | 0) = = = 0;} if (typeof div.style.zoom!== "undefined") {//ChEck If natively block-level elements act like inline-block//elements when setting their display to ' inline ' and giving// them layout//(IE < 8 does this) div.innerhtml = "";d iv.style.width = div.style.padding = "1px";d Iv.style.border = 0;div . Style.overflow = "hidden";d iv.style.display = "inline";d iv.style.zoom = 1;support.inlineblockneedslayout = ( Div.offsetwidth = = = 3);//Check if elements with layout shrink-wrap their children//(IE 6 does this) Div.style.display = "Block";d iv.style.overflow = "visible";d iv.innerhtml = ""; support.shrinkwrapblocks = (div.offsetwidth!== 3);} Div.style.cssText = positiontopleftwidthheight + paddingmarginbordervisibility;div.innerhtml = Html;outer = Div.firstchild;inner = OUTER.FIRSTCHILD;TD = Outer.nextsibling.firstchild.firstchild;offsetsupport = { Doesnotaddborder: (inner.offsettop!== 5), Doesaddborderfortableandcells: (td.offsettop = = 5)};inner.style.position = "fixed"; inner.style.top = "20px";//Safari Subtracts parent border width here whIch is 5pxoffsetsupport.fixedposition = (Inner.offsettop = = = | | inner.offsettop = = =); inner.style.position = inner. Style.top = ""; outer.style.overflow = "hidden"; outer.style.position = "relative"; o Ffsetsupport.subtractsborderforoverflownotvisible = (Inner.offsettop = = =-5); O Ffsetsupport.doesnotincludemargininbodyoffset = (body.offsettop!== conmargintop), if (window.getComputedStyle) { Div.style.marginTop = "1%"; support.pixelmargin = (window.getComputedStyle (div, null) | | {margintop:0}). margintop!== "1%";} if (typeof container.style.zoom!== "undefined") {container.style.zoom = 1;} Body.removechild (container); margindiv = div = container = null;jquery.extend (support, Offsetsupport);}); return support;}) ();

jquery1.7.2 Source Code Analysis (v) $.support

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.