private function js($theme) { // If there's a single post, ascend or descend appropriately if ($theme->posts instanceof Post) { $next = Posts::ascend($theme->posts)->permalink; $previous = Posts::descend($theme->posts)->permalink; } else { $page = $theme->page; $items_per_page = isset($theme->posts->get_param_cache['limit']) ? $theme->posts->get_param_cache['limit'] : Options::get('pagination'); $total = Utils::archive_pages($theme->posts->count_all(), $items_per_page); if ($page + 1 > $total) { $next = ''; } else { $next = URL::get(null, array('page' => $page + 1)); } if ($page - 1 < 1) { $previous = ''; } else { $previous = URL::get(null, array('page' => $page - 1)); } } $delay = Options::get('key_nav_delay'); $selector = Options::get('key_nav_selector'); return <<<KEYNAV \$(document).ready(function() { \tcurrent = 0; \t\$.hotkeys.add('j', {propagate:true, disableInInput: true}, function(){ \t\tif (current == \$('{$selector}').length-1) { \t\t\tif ('{$next}' == '') { \t\t\t\t// TODO Show the no more posts message \t\t\t} else { \t\t\t\t// go to next page \t\t\t\twindow.location = '{$next}'; \t\t\t} \t\t} else { \t\t\ttarget = \$('{$selector}').eq(current+1).offset().top \t\t\t\$('html,body').animate({scrollTop: target}, {$delay}); \t\t\tcurrent++; \t\t} \t}); \t\$.hotkeys.add('k', {propagate:true, disableInInput: true}, function(){ \t\tif (current == 0) { \t\t\tif ('{$previous}' == '') { \t\t\t\t// Show the no more posts message \t\t\t} else { \t\t\t\t// go to previous page \t\t\t\twindow.location = '{$previous}'; \t\t\t} \t\t} else { \t\t\ttarget = \$('{$selector}').eq(current-1).offset().top \t\t\t\$('html,body').animate({scrollTop: target}, {$delay}); \t\t\tcurrent--; \t\t} \t}); }); KEYNAV; }
/** * Returns the descending post, relative to this post, according to params * @params The params by which to work out what is the descending post * @return Post The descending post */ public function descend( $params = null ) { return Posts::descend( $this, $params ); }