-
-
Save Rayraegah/b92563ecd6f8d6757705 to your computer and use it in GitHub Desktop.
D3 PJAX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<div id="main"> | |
<ul> | |
<li><b>Anteater</b></li> | |
<li><a href="b.html">Baobao</a></li> | |
<li><a href="c.html">Cuttlefish</a></li> | |
</ul> | |
Anteaters, also known as antbear, are the four mammal species of the suborder Vermilingua (meaning "worm tongue") commonly known for eating ants and termites. Together with the sloths, they compose the order Pilosa. The name "anteater" is also colloquially applied to the unrelated aardvark, numbat, echidna, and pangolin. | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<div id="main"> | |
<ul> | |
<li><a href="a.html">Anteater</a></li> | |
<li><b>Baobab</b></li> | |
<li><a href="c.html">Cuttlefish</a></li> | |
</ul> | |
Adansonia is a genus of eight species of tree, six native to Madagascar, one native to mainland Africa and the Arabian Peninsula and one to Australia. The mainland African species also occurs on Madagascar, but it is not a native of that island. A typical common name is baobab. Other common names include boab, boaboa, bottle tree, upside-down tree, and monkey bread tree. The generic name honours Michel Adanson, the French naturalist and explorer who described A. digitata. | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<div id="main"> | |
<ul> | |
<li><a href="a.html">Anteater</a></li> | |
<li><a href="b.html">Baobao</a></li> | |
<li><b>Cuttlefish</b></li> | |
</ul> | |
Cuttlefish are marine animals of the order Sepiida. They belong to the class Cephalopoda (which also includes squid, octopuses, and nautiluses). Despite their name, cuttlefish are not fish but molluscs. | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
This page was generated at <script type="text/javascript">document.write(new Date())</script>. | |
<div id="main"> | |
<ul> | |
<li><a href="a.html">Anteater</a></li> | |
<li><a href="b.html">Baobao</a></li> | |
<li><a href="c.html">Cuttlefish</a></li> | |
</ul> | |
Hello, PJAX! | |
</div> | |
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.5.0"></script> | |
<script type="text/javascript"> | |
pjax("ul li a", "#main"); | |
function pjax(links, content) { | |
d3.selectAll(links).on("click", function() { | |
history.pushState(this.href, this.textContent, this.href); | |
load(this.href); | |
d3.event.preventDefault(); | |
}); | |
function load(href) { | |
d3.html(href, function(fragment) { | |
var target = d3.select(content).node(); | |
target.parentNode.replaceChild(d3.select(fragment).select(content).node(), target); | |
pjax(links, content); // reapply | |
}); | |
} | |
d3.select(window).on("popstate", function() { | |
if (d3.event.state) load(d3.event.state); | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment