diff options
| author | 2018-04-10 19:39:29 +0200 | |
|---|---|---|
| committer | 2018-04-10 19:39:29 +0200 | |
| commit | dd6835dfd6a7f8fb6baea76a0cddd8289e43130f (patch) | |
| tree | e433366cf41977d0a9aa554721a649a15cfb355d /static | |
| parent | Forces the sidebar and the rest of that container div to fill the page (diff) | |
Flash of Unstyled Content fix
Diffstat (limited to '')
| -rw-r--r-- | static/js/fouc.js | 36 | ||||
| -rw-r--r-- | static/style.css | 11 | 
2 files changed, 47 insertions, 0 deletions
diff --git a/static/js/fouc.js b/static/js/fouc.js new file mode 100644 index 00000000..190e8d37 --- /dev/null +++ b/static/js/fouc.js @@ -0,0 +1,36 @@ +function getScript(url, integrity, crossorigin){ +    var script = document.createElement("script") +    script.type = "text/javascript"; +    script.src = url; +    script.defer = true; +    script.integrity = integrity; +    script.crossOrigin = crossorigin; +    document.getElementsByTagName("head")[0].appendChild(script); +} + +function setClass(selector, myClass) { +    element = document.querySelector(selector); +    console.log(element) +    element.className = myClass; +} + +function removeClass(selector, myClass) { +    element = document.querySelector(selector); +    var reg = new RegExp('(^| )'+myClass+'($| )','g'); +    element.className = element.className.replace(reg,' '); +} + +// hide the html when the page loads, but only if js is turned on. +setClass('html', 'prevent_fouc'); + +// when the DOM has finished loading, unhide the html +document.onreadystatechange = function () { +    if (document.readyState == "interactive") { +        removeClass('html', 'prevent_fouc'); +        getScript( +            'https://pro.fontawesome.com/releases/v5.0.9/js/all.js', +            'sha384-DtPgXIYsUR6lLmJK14ZNUi11aAoezQtw4ut26Zwy9/6QXHH8W3+gjrRDT+lHiiW4', +            'anonymous' +        ) +    } +}
\ No newline at end of file diff --git a/static/style.css b/static/style.css index 9900a817..5c63f106 100644 --- a/static/style.css +++ b/static/style.css @@ -107,4 +107,15 @@ footer div.uk-section div.uk-text-center {  .uk-button-darkish:hover {      background: rgba(0, 0, 0, 0.22); +} + +/* Flash of Unstyled Content fixes */ +.prevent_fouc { +    display: none; +} + +div.navbar-padding { +    padding-left: 40px; +    padding-right: 40px; +    box-sizing: content-box;  }
\ No newline at end of file  |