Add keyboard shortcuts to the bookmarks page

This commit is contained in:
Frederic Guillot 2013-07-11 23:41:45 -04:00
parent a89d8c0005
commit a5e9d41561
4 changed files with 34 additions and 20 deletions

View File

@ -5,7 +5,7 @@
var queue_length = 5; var queue_length = 5;
function switch_status(item_id) function switch_status(item_id, hide)
{ {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
@ -18,7 +18,7 @@
if (response.status == "read" || response.status == "unread") { if (response.status == "read" || response.status == "unread") {
find_next_item(); find_next_item();
remove_item(response.item_id); if (hide) remove_item(response.item_id);
} }
} }
} }
@ -193,7 +193,10 @@
function remove_item(item_id) function remove_item(item_id)
{ {
var item = document.getElementById("item-" + item_id); var item = document.getElementById("item-" + item_id);
if (item) item.parentNode.removeChild(item);
if (item) {
item.parentNode.removeChild(item);
var container = document.getElementById("page-counter"); var container = document.getElementById("page-counter");
@ -213,6 +216,7 @@
} }
} }
} }
}
function open_original_item() function open_original_item()
@ -221,7 +225,10 @@
if (link) { if (link) {
if (is_listing()) mark_as_read(link.getAttribute("data-item-id")); if (is_listing() && link.getAttribute("data-hide")) {
mark_as_read(link.getAttribute("data-item-id"));
}
link.removeAttribute("data-action"); link.removeAttribute("data-action");
link.click(); link.click();
} }
@ -268,11 +275,14 @@
function change_item_status() function change_item_status()
{ {
if (is_listing() && ! document.getElementById("current-item")) { if (is_listing() && ! document.getElementById("current-item")) {
document.querySelector("article").id = "current-item"; find_next_item();
} }
var item = document.getElementById("current-item"); var item = document.getElementById("current-item");
if (item) switch_status(item.getAttribute("data-item-id"));
if (item) {
switch_status(item.getAttribute("data-item-id"), item.getAttribute("data-hide"));
}
} }

View File

@ -8,13 +8,14 @@
<h2><?= t('Bookmarks') ?> (<?= $nb_items ?>)</h2> <h2><?= t('Bookmarks') ?> (<?= $nb_items ?>)</h2>
</div> </div>
<section class="items"> <section class="items" id="listing">
<?php foreach ($items as $item): ?> <?php foreach ($items as $item): ?>
<?php $item_id = Model\encode_item_id($item['id']) ?> <?php $item_id = Model\encode_item_id($item['id']) ?>
<article id="item-<?= $item_id ?>" data-item-id="<?= $item_id ?>"> <article id="item-<?= $item_id ?>" data-item-id="<?= $item_id ?>">
<h2> <h2>
<a <a
href="?action=show&amp;id=<?= $item_id ?>" href="?action=show&amp;id=<?= $item_id ?>"
data-item-id="<?= $item_id ?>"
id="open-<?= $item_id ?>" id="open-<?= $item_id ?>"
> >
<?= Helper\escape($item['title']) ?> <?= Helper\escape($item['title']) ?>

View File

@ -12,11 +12,12 @@
<section class="items" id="listing"> <section class="items" id="listing">
<?php foreach ($items as $item): ?> <?php foreach ($items as $item): ?>
<?php $item_id = Model\encode_item_id($item['id']) ?> <?php $item_id = Model\encode_item_id($item['id']) ?>
<article id="item-<?= $item_id ?>" data-item-id="<?= $item_id ?>" data-item-page="<?= $menu ?>"> <article id="item-<?= $item_id ?>" data-item-id="<?= $item_id ?>" data-item-page="<?= $menu ?>" data-hide="true">
<h2> <h2>
<?= $item['bookmark'] ? '★ ' : '' ?> <?= $item['bookmark'] ? '★ ' : '' ?>
<a <a
href="?action=show&amp;id=<?= $item_id ?>" href="?action=show&amp;id=<?= $item_id ?>"
data-item-id="<?= $item_id ?>"
id="open-<?= $item_id ?>" id="open-<?= $item_id ?>"
> >
<?= Helper\escape($item['title']) ?> <?= Helper\escape($item['title']) ?>
@ -28,7 +29,7 @@
<a href="?action=mark-item-unread&amp;id=<?= $item_id ?>&amp;offset=<?= $offset ?>"><?= t('mark as unread') ?></a> | <a href="?action=mark-item-unread&amp;id=<?= $item_id ?>&amp;offset=<?= $offset ?>"><?= t('mark as unread') ?></a> |
<?php if (! $item['bookmark']): ?> <?php if (! $item['bookmark']): ?>
<a href="?action=bookmark&amp;value=1&amp;id=<?= $item_id ?>&amp;redirect=history&amp;offset=<?= $offset ?>"><?= t('bookmark') ?></a> | <a id="bookmark-<?= $item_id ?>" href="?action=bookmark&amp;value=1&amp;id=<?= $item_id ?>&amp;redirect=history&amp;offset=<?= $offset ?>"><?= t('bookmark') ?></a> |
<?php endif ?> <?php endif ?>
<a href="?action=mark-item-removed&amp;id=<?= $item_id ?>&amp;offset=<?= $offset ?>"><?= t('remove') ?></a> | <a href="?action=mark-item-removed&amp;id=<?= $item_id ?>&amp;offset=<?= $offset ?>"><?= t('remove') ?></a> |

View File

@ -14,11 +14,12 @@
<section class="items" id="listing"> <section class="items" id="listing">
<?php foreach ($items as $item): ?> <?php foreach ($items as $item): ?>
<?php $item_id = Model\encode_item_id($item['id']) ?> <?php $item_id = Model\encode_item_id($item['id']) ?>
<article id="item-<?= $item_id ?>" data-item-id="<?= $item_id ?>" data-item-page="<?= $menu ?>"> <article id="item-<?= $item_id ?>" data-item-id="<?= $item_id ?>" data-item-page="<?= $menu ?>" data-hide="true">
<h2> <h2>
<?= $item['bookmark'] ? '★ ' : '' ?> <?= $item['bookmark'] ? '★ ' : '' ?>
<a <a
href="?action=read&amp;id=<?= $item_id ?>" href="?action=read&amp;id=<?= $item_id ?>"
data-item-id="<?= $item_id ?>"
id="open-<?= $item_id ?>" id="open-<?= $item_id ?>"
> >
<?= Helper\escape($item['title']) ?> <?= Helper\escape($item['title']) ?>
@ -45,6 +46,7 @@
target="_blank" target="_blank"
data-item-id="<?= $item_id ?>" data-item-id="<?= $item_id ?>"
data-action="mark-read" data-action="mark-read"
data-hide="true"
> >
<?= t('original link') ?> <?= t('original link') ?>
</a> </a>