mohl by nekdo tohle prekopat pro pouziti do user skriptu?
jQuery.pageKeyNavigation = function() {
// if LINK tags not exists
// create LINK ref='' in BODY from A href='' rel='' (if exists one)
// first - prvni
if (!$("link[rel=first]").length && $("a[rel=first]").length == 1) {
var urlFirst = $('a[rel=first]').attr("href");
$('head').append('<link rel="first" href="' + urlFirst + '" />');
}
// prev - predchozi
if (!$("link[rel=prev]").length && $("a[rel=prev]").length == 1) {
var urlPrev = $('a[rel=prev]').attr("href");
$('head').append('<link rel="prev" href="' + urlPrev + '" />');
}
// next - dalsi
if (!$("link[rel=next]").length && $("a[rel=next]").length == 1) {
var urlNext = $('a[rel=next]').attr("href");
$('head').append('<link rel="next" href="' + urlNext + '" />');
}
// last - posledni
if (!$("link[rel=last]").length && $("a[rel=last]").length == 1) {
var urlLast = $('a[rel=last]').attr("href");
$('head').append('<link rel="last" href="' + urlLast + '" />');
}
// load url from LINK tags, if exists
if ($("link[rel=next]").length || $("link[rel=previous]").length) {
var nextUrl = '';
var prevUrl = '';
if ($("link[rel=next]").length) {
nextUrl = $("link[rel=next]").attr('href');
}
if ($("link[rel=previous]").length) {
prevUrl = $("link[rel=previous]").attr('href');
}
// Register keypress events on the whole document
$(document).keypress(function(e) {
// storno keypress on form = inputs, select, button, textarea...
if( $(e.target).is(":input") ) return;
switch(e.keyCode) {
// User pressed "left" arrow
case 37:
if(prevUrl != '') {
window.location = prevUrl;
}
break;
// User pressed "right" arrow
case 39:
if(nextUrl != '') {
window.location = nextUrl;
}
break;
}
});
}
} |