@@ -15,23 +15,23 @@ function loadCSS( href, before, media ){
15
15
Arguments explained:
16
16
- `href` is the optional URL or array of URLs for your CSS file(s).
17
17
- `before` optionally defines the element we'll use as a reference for injecting our <link>
18
- By default, `before` uses the first <script> element in the page.
18
+ By default, `before` uses the first ` <script>` element in the page.
19
19
However, since the order in which stylesheets are referenced matters, you might need a more specific location in your document.
20
20
If so, pass a different reference element to the `before` argument and it'll insert before that instead
21
- - `media` is the value for the <link>'s media attribute. Default is "all" or if using the <noscript> option, whatever the original's attribute is.
21
+ - `media` is the value for the ` <link>` 's media attribute. Default is "all" or if using the ` <noscript>` option, whatever the original's attribute is.
22
22
23
23
Note: `insertBefore` is used instead of `appendChild`, for safety re: http://www.paulirish.com/2011/surefire-dom-element-insertion/
24
24
*/
25
25
26
- // Create a <link> element
26
+ // Create a ` <link>` element
27
27
function makeLink ( href ) {
28
28
var ss = window . document . createElement ( "link" ) ;
29
29
ss . rel = "stylesheet" ;
30
30
ss . href = href ;
31
31
return ss ;
32
32
}
33
33
34
- // Inject <link> into DOM
34
+ // Inject ` <link>` into DOM
35
35
function injectLink ( ss , ref ) {
36
36
// Save a reference to the original media attribute, use the `media` argument, or default to "all"
37
37
var ssMedia = ss . media || media || "all" ;
@@ -57,26 +57,26 @@ function loadCSS( href, before, media ){
57
57
injectLink ( makeLink ( href ) , ref ) ;
58
58
}
59
59
} else {
60
- // Otherwise, find all `noscript` elements with the class `async-css` and pull any `link` elements from there
60
+ // Otherwise, find all `noscript` elements with the class `async-css` and pull any `< link> ` elements from there
61
61
var noscripts = window . document . getElementsByTagName ( "noscript" ) ;
62
62
63
63
if ( noscripts . length ) {
64
- // Create a dummy element to drop all of the `noscript`s contents into to check for `link` elements
64
+ // Create a dummy element to drop all of the `< noscript> `s contents into to check for `< link> ` elements
65
65
var el = window . document . createElement ( 'div' ) ;
66
66
67
67
for ( i = 0 ; i < noscripts . length ; i ++ ) {
68
- // Make sure this `noscript` has the `loadCSS` class and has not already been loaded
68
+ // Make sure this `< noscript> ` has the `loadCSS` class and has not already been loaded
69
69
if ( ( " " + noscripts [ i ] . className + " " ) . indexOf ( ' loadCSS ' ) > - 1 && ( " " + noscripts [ i ] . className + " " ) . indexOf ( ' loaded ' ) === - 1 ) {
70
70
el . innerHTML += " " + noscripts [ i ] . innerText ;
71
71
noscripts [ i ] . className += " loaded " ;
72
72
}
73
73
}
74
74
75
- // Extract the link elements from our dummy element, `el`
75
+ // Extract the `< link>` elements from our dummy element, `el`
76
76
var links = el . getElementsByTagName ( "link" ) ;
77
77
78
78
for ( i = 0 ; i < links . length ; i ++ ) {
79
- // Clone the link element to prevent issues with skipped elements
79
+ // Clone the `< link>` element to prevent issues with skipped elements
80
80
var link = links [ i ] . cloneNode ( true ) ;
81
81
injectLink ( link , ref ) ;
82
82
}
0 commit comments