2013-06-15 09:27:33 +03:00
|
|
|
var template, result;
|
|
|
|
|
2013-06-15 09:03:22 +03:00
|
|
|
function htmlEscape(str) {
|
|
|
|
return String(str)
|
|
|
|
.replace(/&/g, '&')
|
|
|
|
.replace(/"/g, '"')
|
|
|
|
.replace(/'/g, ''')
|
|
|
|
.replace(/</g, '<')
|
|
|
|
.replace(/>/g, '>');
|
2013-06-15 09:27:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function navigateTo (url) {
|
|
|
|
jsonurl = url.replace ("index", "getJSON");
|
|
|
|
$.getJSON(jsonurl, function(data) {
|
|
|
|
history.pushState(data, "", url);
|
|
|
|
updatePage (data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function updatePage (data) {
|
|
|
|
result = template (data);
|
|
|
|
document.title = data.title;
|
|
|
|
$(".container").html (result);
|
|
|
|
|
|
|
|
ajaxifyLinks ();
|
|
|
|
}
|
|
|
|
|
|
|
|
function ajaxifyLinks () {
|
|
|
|
if (history.pushState) {
|
|
|
|
$("a[href^='index']").click (function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
var url = $(this).attr('href');
|
|
|
|
navigateTo (url);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.onpopstate = function(event) {
|
|
|
|
updatePage (event.state);
|
|
|
|
};
|
|
|
|
|
|
|
|
$(document).keydown(function(e){
|
|
|
|
if (e.keyCode == 37 && $("#prevLink").length > 0) {
|
|
|
|
navigateTo ($("#prevLink").attr('href'));
|
|
|
|
}
|
|
|
|
if (e.keyCode == 39 && $("#nextLink").length > 0) {
|
|
|
|
navigateTo ($("#nextLink").attr('href'));
|
|
|
|
}
|
|
|
|
});
|