Commit 86bb3400 authored by fred's avatar fred

template: use ajax requests when browsing between pages

parent 78687cc0
/* Via
https://developer.mozilla.org/en-US/docs/Web/Guide/DOM/Manipulating_the_browser_history
http://simeonfranklin.com/blog/2011/aug/22/ahah-django-and-jquery/
http://rosspenman.com/pushstate-jquery/
*/
$(function() {
function ajax_load(html) {
$(this).children(':first').unwrap();
init();
}
function loadpage(href) {
console.log('loadpage', href);
$('#wrap').load(href + " #wrap", ajax_load);
}
function init() {
$('a:not([href^="http"])').click(function() {
var href = this.getAttribute('href');
loadpage(href);
history.pushState({'href': href}, '', href);
return false;
});
}
init();
$(window).on("popstate", function(e) {
console.log('popstate', e.originalEvent.state);
if (e.originalEvent.state !== null) {
console.log('href:', location.href);
loadpage(location.href);
}
});
});
......@@ -11,6 +11,7 @@
<script src="{{ STATIC_URL }}js/jquery.fileupload.js"></script>
<script src="{{ STATIC_URL }}js/jquery.iframe-transport.js"></script>
<script src="{{ STATIC_URL }}js/qommon.fileupload.js"></script>
<script src="{{ STATIC_URL }}js/qommon.ahah.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="{{ STATIC_URL }}css/smoothness/jquery-ui-1.10.0.custom.css"/>
{% block extrascripts %}
{% endblock %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment