Skip to content

Commit

Permalink
website: fixup some js and css issues
Browse files Browse the repository at this point in the history
Noticed that the side was blocked waiting for assets to load on my ipad.
Make a pass through and force the webfonts and highlighting stuff to
load async.

Ensure that our react stuff only tries to render after we've loaded
the react js library.

Break out of the nav for loop as soon as we've found a match (cuts build
time in half!)
  • Loading branch information
wez committed Aug 16, 2015
1 parent b303e13 commit 22f16ad
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 21 deletions.
21 changes: 12 additions & 9 deletions website/_includes/anchor_links.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
}
};

document.onreadystatechange = function () {
var scanForPosts = function() {
var contentBlock = document.getElementsByClassName("post")[0] || document.getElementsByClassName("news")[0];
if (!contentBlock) {
return;
}
for (var level = 1; level <= 6; level++) {
linkifyAnchors(level, contentBlock);
}
}
document.addEventListener('onreadystatechange', function () {
if (this.readyState === "complete") {
var contentBlock = document.getElementsByClassName("post")[0] || document.getElementsByClassName("news")[0];
if (!contentBlock) {
return;
}
for (var level = 1; level <= 6; level++) {
linkifyAnchors(level, contentBlock);
}
scanForPosts();
}
};
});
</script>
17 changes: 16 additions & 1 deletion website/_includes/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<section id="fb_oss" class="fbOpenSourceFooter">
<a href="https://code.facebook.com/projects/" target="_blank"><img src="{{ site.baseurl }}/static/oss_logo.png" alt="Facebook Open Source" title="Facebook Open Source" /></a>
</section>
<script>hljs.initHighlightingOnLoad();</script>
</div>
</div>
{% include anchor_links.html %}
Expand All @@ -16,4 +15,20 @@
ga('create', '{{ site.gacode }}', 'auto');
ga('send', 'pageview');
</script>
<script>
window.addEventListener('load', function() {
hljs.initHighlightingOnLoad();

// Async load some styles
function loadStyle(href) {
var s = document.createElement('link');
s.setAttribute('rel', 'stylesheet');
s.setAttribute('href', href);
s.setAttribute('type', 'text/css');
document.getElementsByTagName('head')[0].appendChild(s);
}
loadStyle("//nuclide.io/static/fonts/332720/BC699FA675F9356E3.css");
loadStyle("//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/styles/default.min.css");
loadStyle("//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css");
});
</script>
7 changes: 2 additions & 5 deletions website/_includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
<meta property="og:description" content="{% if page.excerpt %}{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}{% else %}{{ site.description }}{% endif %}" />

<link rel="stylesheet" type="text/css" media="screen" href="{{ site.baseurl }}/css/main.css">
<link rel="stylesheet" type="text/css" href="//nuclide.io/static/fonts/332720/BC699FA675F9356E3.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/styles/default.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

<link rel="icon" href="static/favicon.png" type="image/x-icon">

<base href="{{ site.url }}{{ site.baseurl }}/" />

<script src="//cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react-with-addons.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/highlight.min.js"></script>
<script async defer src="//cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react-with-addons.min.js"></script>
<script async defer src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/highlight.min.js"></script>

<title>{% if page.title %}{{ page.title }}{% else %}{{ site.title }}{% endif %}</title>
<meta name="description" content="{% if page.excerpt %}{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}{% else %}{{ site.description }}{% endif %}">
Expand Down
2 changes: 2 additions & 0 deletions website/_includes/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
];
</script>
<script type="text/javascript">
window.addEventListener('load', function() {
var Nav = React.createClass({displayName: "Nav",
getInitialState: function() {
return {
Expand Down Expand Up @@ -96,5 +97,6 @@
);
}
render(navData);
});
</script>
</div>
10 changes: 4 additions & 6 deletions website/_includes/nav_docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
group : "{{ group.title }}",
items : [
{% for item in group.items %}
{% for docitem in site.docs %}
{% if docitem.id == item.id %}
{% assign doc = docitem %}
{% endif %}
{% endfor %}
{% for docitem in site.docs %}{% if docitem.id == item.id %}{% assign doc = docitem %}{% break %}{% endif %}{% endfor %}
{
key : "{{ site.baseurl }}{{ doc.url }}",
title : "{{ doc.title }}",
Expand All @@ -25,6 +21,7 @@
];
</script>
<script type="text/javascript">
window.addEventListener('load', function() {
var DocNav = React.createClass({displayName: "DocNav",
getInitialState: function() {
return {
Expand Down Expand Up @@ -97,4 +94,5 @@
);
}
docNavRender(docnavData);
</script>
});
</script>

0 comments on commit 22f16ad

Please sign in to comment.