client/users: add keyboard shortcuts to user list

This commit is contained in:
rr- 2016-04-14 21:01:33 +02:00
parent ef3dc1fa75
commit b382f3398f
9 changed files with 61 additions and 7 deletions

View File

@ -10,27 +10,27 @@ shortcuts:</p>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td><code>[Q]</code></td> <td><kbd>Q</kbd></td>
<td>Focus search field, if available</td> <td>Focus search field, if available</td>
</tr> </tr>
<tr> <tr>
<td><code>[A]</code> and <code>[D]</code></td> <td><kbd>A</kbd> and <kbd>D</kbd>, <kbd>←</kbd> and <kbd>→</kbd></td>
<td>Go to newer/older page or post</td> <td>Go to newer/older page or post</td>
</tr> </tr>
<tr> <tr>
<td><code>[F]</code></td> <td><kbd>F</kbd></td>
<td>Cycle post fit mode</td> <td>Cycle post fit mode</td>
</tr> </tr>
<tr> <tr>
<td><code>[E]</code></td> <td><kbd>E</kbd></td>
<td>Edit post</td> <td>Edit post</td>
</tr> </tr>
<tr> <tr>
<td><code>[P]</code></td> <td><kbd>P</kbd></td>
<td>Focus first post in post list</td> <td>Focus first post in post list</td>
</tr> </tr>
</tbody> </tbody>

View File

@ -8,6 +8,10 @@
{{checkbox text='Endless scroll' id='endless-scroll' name='endless-scroll' checked=this.browsingSettings.endlessScroll}} {{checkbox text='Endless scroll' id='endless-scroll' name='endless-scroll' checked=this.browsingSettings.endlessScroll}}
<p class='hint'>Rather than using a paged navigation, smoothly scroll through the content.</p> <p class='hint'>Rather than using a paged navigation, smoothly scroll through the content.</p>
</li> </li>
<li>
{{checkbox text='Enable keyboard shortcuts' id='keyboard-shortcuts' name='keyboard-shortcuts' checked=this.browsingSettings.keyboardShortcuts}}
<a class='append icon' href='/help/keyboard'><i class='fa fa-question-circle-o'></i></a>
</li>
</ul> </ul>
</div> </div>
<div class='messages'></div> <div class='messages'></div>

View File

@ -2,6 +2,13 @@
require('./util/polyfill.js'); require('./util/polyfill.js');
const page = require('page');
const mousetrap = require('mousetrap');
page(/.*/, (ctx, next) => {
mousetrap.reset();
next();
});
let controllers = []; let controllers = [];
controllers.push(require('./controllers/auth_controller.js')); controllers.push(require('./controllers/auth_controller.js'));
controllers.push(require('./controllers/posts_controller.js')); controllers.push(require('./controllers/posts_controller.js'));
@ -15,7 +22,6 @@ controllers.push(require('./controllers/settings_controller.js'));
controllers.push(require('./controllers/home_controller.js')); controllers.push(require('./controllers/home_controller.js'));
const events = require('./events.js'); const events = require('./events.js');
const page = require('page');
for (let controller of controllers) { for (let controller of controllers) {
controller.registerRoutes(); controller.registerRoutes();
} }

View File

@ -11,6 +11,7 @@ function saveSettings(browsingSettings) {
function getSettings(settings) { function getSettings(settings) {
const defaultSettings = { const defaultSettings = {
endlessScroll: false, endlessScroll: false,
keyboardShortcuts: true,
}; };
let ret = {}; let ret = {};
let userSettings = localStorage.getItem('settings'); let userSettings = localStorage.getItem('settings');

View File

@ -0,0 +1,21 @@
'use strict';
const mousetrap = require('mousetrap');
const settings = require('../settings.js');
function bind(hotkey, func) {
if (settings.getSettings().keyboardShortcuts) {
mousetrap.bind(hotkey, func);
return true;
}
return false;
}
function unbind(hotkey) {
mousetrap.unbind(hotkey);
}
module.exports = {
bind: bind,
unbind: unbind,
};

View File

@ -1,6 +1,8 @@
'use strict'; 'use strict';
const page = require('page');
const events = require('../events.js'); const events = require('../events.js');
const keyboard = require('../util/keyboard.js');
const misc = require('../util/misc.js'); const misc = require('../util/misc.js');
const views = require('../util/views.js'); const views = require('../util/views.js');
@ -76,6 +78,17 @@ class ManualPageView {
const pageNumbers = getVisiblePageNumbers(currentPage, totalPages); const pageNumbers = getVisiblePageNumbers(currentPage, totalPages);
const pages = getPages(currentPage, pageNumbers, ctx.clientUrl); const pages = getPages(currentPage, pageNumbers, ctx.clientUrl);
keyboard.bind(['a', 'left'], () => {
if (currentPage > 1) {
page.show(ctx.clientUrl.format({page: currentPage - 1}));
}
});
keyboard.bind(['d', 'right'], () => {
if (currentPage < totalPages) {
page.show(ctx.clientUrl.format({page: currentPage + 1}));
}
});
if (response.total) { if (response.total) {
views.showView(pageNav, this.navTemplate({ views.showView(pageNav, this.navTemplate({
prevLink: ctx.clientUrl.format({page: currentPage - 1}), prevLink: ctx.clientUrl.format({page: currentPage - 1}),

View File

@ -18,7 +18,10 @@ class SettingsView {
e.preventDefault(); e.preventDefault();
views.clearMessages(source); views.clearMessages(source);
ctx.saveSettings({ ctx.saveSettings({
endlessScroll: form.querySelector('#endless-scroll').checked, endlessScroll:
form.querySelector('#endless-scroll').checked,
keyboardShortcuts:
form.querySelector('#keyboard-shortcuts').checked,
}); });
}); });

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const page = require('page'); const page = require('page');
const keyboard = require('../util/keyboard.js');
const misc = require('../util/misc.js'); const misc = require('../util/misc.js');
const views = require('../util/views.js'); const views = require('../util/views.js');
@ -15,6 +16,10 @@ class UserListHeaderView {
const form = source.querySelector('form'); const form = source.querySelector('form');
keyboard.bind('q', () => {
form.querySelector('input').focus();
});
form.addEventListener('submit', e => { form.addEventListener('submit', e => {
e.preventDefault(); e.preventDefault();
const searchTextInput = form.querySelector('[name=search-text]'); const searchTextInput = form.querySelector('[name=search-text]');

View File

@ -18,6 +18,7 @@
"js-cookie": "^2.1.0", "js-cookie": "^2.1.0",
"js-yaml": "^3.5.5", "js-yaml": "^3.5.5",
"merge": "^1.2.0", "merge": "^1.2.0",
"mousetrap": "^1.5.3",
"page": "^1.7.1", "page": "^1.7.1",
"stylus": "^0.54.2", "stylus": "^0.54.2",
"superagent": "^1.8.3", "superagent": "^1.8.3",