use jQuery instead of JS + change spacing to tabs

this should fix IE/browser problems (see: #349)
This commit is contained in:
Daku 2014-02-19 06:23:08 +00:00
parent 5df6c09da6
commit fe6b83412f

View file

@ -8,82 +8,75 @@
* Documentation: * Documentation:
* Simply enable this extention in the extention manager to enable arrow key navigation. * Simply enable this extention in the extention manager to enable arrow key navigation.
*/ */
class ArrowkeyNavigation extends Extension { class ArrowkeyNavigation extends Extension {
# Adds functionality for post/view on images # Adds functionality for post/view on images
public function onDisplayingImage(DisplayingImageEvent $event) { public function onDisplayingImage(DisplayingImageEvent $event) {
$prev_url = make_http(make_link("post/prev/".$event->image->id)); $prev_url = make_http(make_link("post/prev/".$event->image->id));
$next_url = make_http(make_link("post/next/".$event->image->id)); $next_url = make_http(make_link("post/next/".$event->image->id));
$this->add_arrowkeys_code($prev_url, $next_url); $this->add_arrowkeys_code($prev_url, $next_url);
} }
# Adds functionality for post/list
public function onPageRequest(PageRequestEvent $event) {
if($event->page_matches("post/list")) {
$pageinfo = $this->get_list_pageinfo($event);
$prev_url = make_http(make_link("post/list/".$pageinfo["prev"]));
$next_url = make_http(make_link("post/list/".$pageinfo["next"]));
$this->add_arrowkeys_code($prev_url, $next_url);
}
}
# adds the javascript to the page with the given urls
private function add_arrowkeys_code($prev_url, $next_url) {
global $page;
$page->add_html_header("<script type=\"text/javascript\"> # Adds functionality for post/list
document.onkeyup=checkKeycode; public function onPageRequest(PageRequestEvent $event) {
function checkKeycode(e) if($event->page_matches("post/list")) {
{ $pageinfo = $this->get_list_pageinfo($event);
var keycode; $prev_url = make_http(make_link("post/list/".$pageinfo["prev"]));
if(window.event) keycode=window.event.keyCode; $next_url = make_http(make_link("post/list/".$pageinfo["next"]));
else if(e) keycode=e.which; $this->add_arrowkeys_code($prev_url, $next_url);
}
}
if (e.srcElement.tagName != \"INPUT\") # adds the javascript to the page with the given urls
{ private function add_arrowkeys_code($prev_url, $next_url) {
if(keycode==\"37\") window.location.href='$prev_url'; global $page;
else if(keycode==\"39\") window.location.href='$next_url';
} $page->add_html_header("<script type=\"text/javascript\">
} (function($){
</script>"); $(document).keyup(function(e) {
} if($(e.target).is('input', 'textarea')){ return; }
if (e.keyCode == 37) { window.location.href = '{$prev_url}'; }
# returns info about the current page number else if (e.keyCode == 39) { window.location.href = '{$next_url}'; }
private function get_list_pageinfo($event) { });
global $config, $database; })(jQuery);
</script>", 60);
// get the amount of images per page }
$images_per_page = $config->get_int('index_images');
# returns info about the current page number
// if there are no tags, use default private function get_list_pageinfo($event) {
if ($event->get_arg(1) == null){ global $config, $database;
$prefix = "";
$page_number = (int)$event->get_arg(0); // get the amount of images per page
$total_pages = ceil($database->get_one( $images_per_page = $config->get_int('index_images');
"SELECT COUNT(*) FROM images") / $images_per_page);
} // if there are no tags, use default
if ($event->get_arg(1) == null){
else { // if there are tags, use pages with tags $prefix = "";
$prefix = $event->get_arg(0)."/"; $page_number = (int)$event->get_arg(0);
$page_number = (int)$event->get_arg(1); $total_pages = ceil($database->get_one(
$total_pages = ceil($database->get_one( "SELECT COUNT(*) FROM images") / $images_per_page);
"SELECT count FROM tags WHERE tag=:tag", }
array("tag"=>$event->get_arg(0))) / $images_per_page); else { // if there are tags, use pages with tags
} $prefix = $event->get_arg(0)."/";
$page_number = (int)$event->get_arg(1);
// creates previous & next values $total_pages = ceil($database->get_one(
// When previous first page, go to last page "SELECT count FROM tags WHERE tag=:tag",
if ($page_number <= 1) $prev = $total_pages; array("tag"=>$event->get_arg(0))) / $images_per_page);
else $prev = $page_number-1; }
if ($page_number >= $total_pages) $next = 1;
else $next = $page_number+1; // creates previous & next values
// When previous first page, go to last page
// Create return array if ($page_number <= 1) $prev = $total_pages;
$pageinfo = array( else $prev = $page_number-1;
"prev" => $prefix.$prev, if ($page_number >= $total_pages) $next = 1;
"next" => $prefix.$next, else $next = $page_number+1;
);
// Create return array
return $pageinfo; $pageinfo = array(
} "prev" => $prefix.$prev,
"next" => $prefix.$next,
);
return $pageinfo;
}
} }
?> ?>