]> source.dussan.org Git - jquery.git/commitdiff
Fix #12357: be more kind to non-browser environments. Close gh-938.
authorRichard Gibson <richard.gibson@gmail.com>
Mon, 1 Oct 2012 00:54:28 +0000 (20:54 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Mon, 1 Oct 2012 00:54:28 +0000 (20:54 -0400)
src/support.js

index 68ca91b3ad0a59e1e16e48dd141587ff23792b06..f998f12701eb397c3e230fc02cab6360af7eda8c 100644 (file)
@@ -13,24 +13,23 @@ jQuery.support = (function() {
                clickFn,
                div = document.createElement("div");
 
-       // Preliminary tests
+       // Setup
        div.setAttribute( "className", "t" );
        div.innerHTML = "  <link/><table></table><a href='/a'>a</a><input type='checkbox'/>";
 
+       // Support tests won't run in some limited or non-browser environments
        all = div.getElementsByTagName("*");
        a = div.getElementsByTagName("a")[ 0 ];
-       a.style.cssText = "top:1px;float:left;opacity:.5";
-
-       // Can't get basic test support
-       if ( !all || !all.length ) {
+       if ( !all || !a || !all.length ) {
                return {};
        }
 
-       // First batch of supports tests
+       // First batch of tests
        select = document.createElement("select");
        opt = select.appendChild( document.createElement("option") );
        input = div.getElementsByTagName("input")[ 0 ];
 
+       a.style.cssText = "top:1px;float:left;opacity:.5";
        support = {
                // IE strips leading whitespace when .innerHTML is used
                leadingWhitespace: ( div.firstChild.nodeType === 3 ),
@@ -72,7 +71,7 @@ jQuery.support = (function() {
                // Test setAttribute 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)
+               // Tests for enctype support on a form (#6743)
                enctype: !!document.createElement("form").enctype,
 
                // Makes sure cloning an html5 element does not cause problems