From 13f4de8c1468456a7a3a3a4ee95ed6f07b67b414 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 4 Feb 2020 01:59:08 +0000 Subject: [PATCH] Have arrowkey nav use HTML next/prev links --- core/basethemelet.php | 10 ++-- ext/arrowkey_navigation/info.php | 15 ------ ext/arrowkey_navigation/main.php | 93 -------------------------------- ext/handle_static/script.js | 16 +++++- 4 files changed, 20 insertions(+), 114 deletions(-) delete mode 100644 ext/arrowkey_navigation/info.php delete mode 100644 ext/arrowkey_navigation/main.php diff --git a/core/basethemelet.php b/core/basethemelet.php index c13d833a..cc493bb8 100644 --- a/core/basethemelet.php +++ b/core/basethemelet.php @@ -84,15 +84,15 @@ class BaseThemelet $body = $this->build_paginator($page_number, $total_pages, $base, $query, $show_random); $page->add_block(new Block(null, $body, "main", 90, "paginator")); - $page->add_html_header(""); + $page->add_html_header(""); if ($page_number < $total_pages) { - $page->add_html_header(""); - $page->add_html_header(""); + $page->add_html_header(""); + $page->add_html_header(""); } if ($page_number > 1) { - $page->add_html_header(""); + $page->add_html_header(""); } - $page->add_html_header(""); + $page->add_html_header(""); } private function gen_page_link(string $base_url, ?string $query, int $page, string $name): string diff --git a/ext/arrowkey_navigation/info.php b/ext/arrowkey_navigation/info.php deleted file mode 100644 index a4dd9770..00000000 --- a/ext/arrowkey_navigation/info.php +++ /dev/null @@ -1,15 +0,0 @@ -"support@drudexsoftware.com"]; - public $license = self::LICENSE_GPLV2; - public $description = "Allows viewers no navigate between images using the left & right arrow keys."; - public $documentation = -"Simply enable this extension in the extension manager to enable arrow key navigation."; -} diff --git a/ext/arrowkey_navigation/main.php b/ext/arrowkey_navigation/main.php deleted file mode 100644 index ff4d35a4..00000000 --- a/ext/arrowkey_navigation/main.php +++ /dev/null @@ -1,93 +0,0 @@ -image->id)); - $next_url = make_http(make_link("post/next/".$event->image->id)); - $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(string $prev_url, string $next_url) - { - global $page; - - $page->add_html_header("", 60); - } - - /** - * Returns info about the current page number. - */ - private function get_list_pageinfo(PageRequestEvent $event): array - { - global $config, $database; - - // get the amount of images per page - $images_per_page = $config->get_int(IndexConfig::IMAGES); - - if ($event->count_args() > 1) { - // if there are tags, use pages with tags - $prefix = url_escape($event->get_arg(0)) . "/"; - $page_number = $event->try_page_num(1); - $total_pages = ceil($database->get_one( - "SELECT count FROM tags WHERE tag=:tag", - ["tag"=>$event->get_arg(0)] - ) / $images_per_page); - } else { - // if there are no tags, use default - $prefix = ""; - $page_number = $event->try_page_num(0); - $total_pages = ceil($database->get_one( - "SELECT COUNT(*) FROM images" - ) / $images_per_page); - } - - // creates previous & next values - // When previous first page, go to last page - if ($page_number <= 1) { - $prev = $total_pages; - } else { - $prev = $page_number-1; - } - if ($page_number >= $total_pages) { - $next = 1; - } else { - $next = $page_number+1; - } - - // Create return array - return [ - "prev" => $prefix.$prev, - "next" => $prefix.$next, - ]; - } -} diff --git a/ext/handle_static/script.js b/ext/handle_static/script.js index e06c39c7..8e586949 100644 --- a/ext/handle_static/script.js +++ b/ext/handle_static/script.js @@ -32,6 +32,7 @@ $(document).ready(function() { /** Setup tablesorter **/ $("table.sortable").tablesorter(); + /** Setup sidebar toggle **/ try { var sidebar_hidden = (Cookies.get("ui-sidebar-hidden") || "").split("|"); for(var i in sidebar_hidden) { @@ -53,7 +54,7 @@ $(document).ready(function() { } else { for (var i in sidebar_hidden) { - if (sidebar_hidden[i] === tid) { + if (sidebar_hidden[i] === tid) { sidebar_hidden.splice(i, 1); } } @@ -62,6 +63,7 @@ $(document).ready(function() { }); }); + /** setup unlocker buttons **/ $(".shm-unlocker").each(function(idx, elm) { var tid = $(elm).data("unlock-sel"); var tob = $(tid); @@ -70,4 +72,16 @@ $(document).ready(function() { tob.attr("disabled", false); }); }); + + /** setup arrow key bindings **/ + $(document).keyup(function(e) { + if($(e.target).is('input', 'textarea')){ return; } + if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) { return; } + if (e.keyCode == 37 && $("[rel='prev']").length) { + window.location.href = $("[rel='pref']").attr("href"); + } + else if (e.keyCode == 39 && $("[rel='next']").length) { + window.location.href = $("[rel='next']").attr("href"); + } + }); });