|
4 | 4 | <head> |
5 | 5 | <title id="title">Pattern Lab</title> |
6 | 6 | <meta charset="UTF-8"> |
7 | | - <meta name="viewport" content="width=device-width" /> |
8 | | - <link rel="stylesheet" href="styleguide/css/pattern-lab.css" media="all" /> |
| 7 | + <meta name="viewport" content="width=device-width" /> |
| 8 | + <meta name="theme-color" content="#ababab"/> |
| 9 | + |
| 10 | + <link inline href="styleguide/css/pattern-lab.critical.css" /> |
| 11 | + |
| 12 | + <link rel="preload" as="script" href="styleguide/js/patternlab-viewer.js"> |
| 13 | + <link rel="preload" href="styleguide/css/pattern-lab.css" as="style" onload="this.onload=null;this.rel='stylesheet'"> |
| 14 | + |
| 15 | + <noscript> |
| 16 | + <link rel="stylesheet" href="styleguide/css/pattern-lab.css" media="all" /> |
| 17 | + </noscript> |
| 18 | + |
| 19 | + <script inline async src="styleguide/js/cssrelpreload.min.js"></script> |
| 20 | + |
9 | 21 | </head> |
10 | 22 |
|
11 | 23 | <body class="pl-c-body"> |
12 | 24 |
|
13 | | - @@include('./partials/header.html') |
14 | | - |
15 | | - @@include('./partials/iframe.html') |
16 | | - |
| 25 | + @@include('./partials/header.html') |
| 26 | + @@include('./partials/iframe.html') |
17 | 27 | @@include('./partials/modal.html') |
18 | 28 |
|
19 | 29 | <!-- mustache templates --> |
|
36 | 46 | </script> |
37 | 47 |
|
38 | 48 | <!-- load Pattern Lab data --> |
39 | | - <script src="styleguide/data/patternlab-data.js"></script> |
| 49 | + <script src="styleguide/data/patternlab-data.js" defer></script> |
40 | 50 |
|
41 | 51 | <!-- applying theme config to get classes on before PL renders so there's no flash of unstyled content --> |
42 | 52 | <!-- @todo Consider moving this to own file --> |
43 | 53 | <script> |
44 | | - if (config && config.theme) { |
45 | | - if (config.theme.color === 'light') { |
| 54 | + // need to make sure that window.config is defined first on acccount of us async loading everything ;) |
| 55 | + window.patternlab = window.patternlab || {}; |
| 56 | + window.patternlab.applyTheme = function(){ |
| 57 | + if (window.config.theme.color === 'light') { |
46 | 58 | document.body.classList.add('pl-c-body--theme-light'); |
47 | 59 | } |
48 | | - if (config.theme.layout === 'vertical') { |
| 60 | + if (window.config.theme.layout === 'vertical') { |
49 | 61 | document.body.classList.add('pl-c-body--theme-sidebar'); |
50 | 62 | } |
51 | | - switch (config.theme.density) { |
| 63 | + switch (window.config.theme.density) { |
52 | 64 | case 'cozy': |
53 | 65 | document.body.classList.add('pl-c-body--theme-density-cozy'); |
54 | 66 | break; |
|
60 | 72 | document.body.classList.add('pl-c-body--theme-density-compact'); |
61 | 73 | } |
62 | 74 | } |
| 75 | + |
| 76 | + // check if config already exists, if so, try to apply theme config; otherwise wait till later just in case. |
| 77 | + if (window.config !== undefined) { |
| 78 | + if (window.config.theme !== undefined) { |
| 79 | + window.patternlab.applyTheme(); |
| 80 | + } |
| 81 | + } |
63 | 82 | </script> |
64 | 83 |
|
65 | | - <script src="annotations/annotations.js"></script> |
| 84 | + <script src="annotations/annotations.js" async></script> |
66 | 85 |
|
67 | 86 | <!-- load Pattern Lab external library js --> |
68 | | - <script src="styleguide/bower_components/jquery.min.js"></script> |
69 | | - <script src="styleguide/bower_components/hogan-3.0.2.min.js"></script> |
70 | | - <script src="styleguide/bower_components/prism.min.js"></script> |
71 | | - <script src="styleguide/bower_components/jwerty.min.js"></script> |
72 | | - <script src="styleguide/bower_components/typeahead.bundle.min.js"></script> |
73 | | - <script src="styleguide/bower_components/EventEmitter.min.js"></script> |
74 | | - <script src="styleguide/bower_components/script.min.js"></script> |
75 | | - |
76 | | - <!-- set-up the dispatcher --> |
77 | | - <script> |
78 | | - var Dispatcher = new EventEmitter(); |
79 | | - </script> |
| 87 | + <script src="styleguide/bower_components/jquery.min.js" defer></script> |
| 88 | + <script src="styleguide/bower_components/hogan-3.0.2.min.js" defer></script> |
| 89 | + <script src="styleguide/bower_components/prism.min.js" defer></script> |
| 90 | + <script src="styleguide/bower_components/jwerty.min.js" defer></script> |
| 91 | + <script src="styleguide/bower_components/typeahead.bundle.min.js" defer></script> |
| 92 | + <script src="styleguide/bower_components/EventEmitter.min.js" defer></script> |
| 93 | + <script src="styleguide/bower_components/script.min.js" defer></script> |
80 | 94 |
|
81 | | - <!-- load the Pattern Lab viewer js --> |
82 | | - <script src="styleguide/js/patternlab-viewer.js"></script> |
| 95 | + |
| 96 | + <script inline src="styleguide/js/whenDefined.min.js"></script> |
| 97 | + <script inline src="styleguide/js/loadJS.js"></script> |
| 98 | + |
| 99 | + <!-- temp workaround to allow everything to be asynced / deffered with current setup. @todo: remove once refactored components + improved build process is in place. --> |
| 100 | + <script> |
| 101 | + window.Dispatcher; |
| 102 | + window.addEventListener('DOMContentLoaded', function () { |
| 103 | + window.Dispatcher = new EventEmitter(); |
| 104 | + |
| 105 | + // load the Pattern Lab viewer js -- preloaded earlier ^ |
| 106 | + loadJS('styleguide/js/patternlab-viewer.js'); |
| 107 | + }); |
| 108 | + |
| 109 | + whenDefined(window, 'config', function() { |
| 110 | + if (window.config.theme){ |
| 111 | + window.patternlab.applyTheme(); |
| 112 | + } |
| 113 | + }); |
| 114 | + |
| 115 | + </script> |
83 | 116 |
|
84 | 117 | </body> |
85 | 118 |
|
|
0 commit comments