Skip to content

Commit

Permalink
fix: support KaiOS arrow navigation on public pages (mastodon#12251)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson authored and Gargron committed Nov 4, 2019
1 parent e37358b commit 1e232e4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
16 changes: 16 additions & 0 deletions app/javascript/mastodon/load_keyboard_extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// On KaiOS, we may not be able to use a mouse cursor or navigate using Tab-based focus, so we install
// special left/right focus navigation keyboard listeners, at least on public pages (i.e. so folks
// can at least log in using KaiOS devices).

function importArrowKeyNavigation() {
return import(/* webpackChunkName: "arrow-key-navigation" */ 'arrow-key-navigation');
}

export default function loadKeyboardExtensions() {
if (/KAIOS/.test(navigator.userAgent)) {
return importArrowKeyNavigation().then(arrowKeyNav => {
arrowKeyNav.register();
});
}
return Promise.resolve();
}
10 changes: 7 additions & 3 deletions app/javascript/packs/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import escapeTextContentForBrowser from 'escape-html';
import loadPolyfills from '../mastodon/load_polyfills';
import ready from '../mastodon/ready';
import { start } from '../mastodon/common';
import loadKeyboardExtensions from '../mastodon/load_keyboard_extensions';

start();

Expand Down Expand Up @@ -259,6 +260,9 @@ function main() {
});
}

loadPolyfills().then(main).catch(error => {
console.error(error);
});
loadPolyfills()
.then(main)
.then(loadKeyboardExtensions)
.catch(error => {
console.error(error);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@babel/runtime": "^7.5.4",
"@clusterws/cws": "^0.15.2",
"array-includes": "^3.0.3",
"arrow-key-navigation": "^1.0.2",
"autoprefixer": "^9.6.1",
"axios": "^0.19.0",
"babel-loader": "^8.0.6",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,11 @@ arrify@^1.0.1:
resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"
integrity sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=

arrow-key-navigation@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/arrow-key-navigation/-/arrow-key-navigation-1.0.2.tgz#c1b5886240819db6c0b2b84702de1313786ce53e"
integrity sha512-Wj67sJpfK7vrj0/aOstIsRMsUQtpVODBTQDcRaDvvPZdzZMotj8oYGsEsoYiDohShDlDU6ywVkHLtXGH4TfEtQ==

asap@~2.0.3:
version "2.0.6"
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"
Expand Down

0 comments on commit 1e232e4

Please sign in to comment.