From 18279f61d0556cc7d6f7fb1eef809080e6465841 Mon Sep 17 00:00:00 2001 From: Gwendolyn Date: Tue, 27 Aug 2024 13:34:14 +0200 Subject: [PATCH] PgUp and PgDown for switching levels (fixes #192) --- src/c3nav/site/static/site/js/c3nav.js | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/c3nav/site/static/site/js/c3nav.js b/src/c3nav/site/static/site/js/c3nav.js index 3a4ab4d9..df1986e8 100644 --- a/src/c3nav/site/static/site/js/c3nav.js +++ b/src/c3nav/site/static/site/js/c3nav.js @@ -968,6 +968,7 @@ c3nav = { .on('click', '.location', c3nav._locationinput_click_suggestion); $('html').on('focus', '*', c3nav._locationinput_global_focuschange) .on('mousedown', '*', c3nav._locationinput_global_focuschange); + $('html').on('keydown', c3nav._global_keydown); }, _build_location_html: function(location) { var html = $('
') @@ -1143,6 +1144,31 @@ c3nav = { c3nav.fly_to_bounds(true); } }, + _global_keydown: function (e) { + if (e.originalEvent.key === 'PageUp') { + c3nav._level_up(); + e.preventDefault(); + e.stopPropagation(); + } else if (e.originalEvent.key === 'PageDown') { + c3nav._level_down(); + e.preventDefault(); + e.stopPropagation(); + } + }, + _level_up() { + let levelIdx = this.levels.findIndex(x => x[0] === c3nav._levelControl.currentLevel); + if (levelIdx === -1) return; + levelIdx += 1; + if (levelIdx >= c3nav.levels.length) return; + c3nav._levelControl.setLevel(c3nav.levels[levelIdx][0]); + }, + _level_down() { + let levelIdx = this.levels.findIndex(x => x[0] === c3nav._levelControl.currentLevel); + if (levelIdx === -1) return; + levelIdx -= 1; + if (levelIdx < 0) return; + c3nav._levelControl.setLevel(c3nav.levels[levelIdx][0]); + }, _locationinput_hover_suggestion: function () { $(this).addClass('focus').siblings().removeClass('focus'); }, @@ -2129,9 +2155,7 @@ LevelControl = L.Control.extend({ this._levelButtons[id] = link; return overlay; }, - setLevel: function (id) { - console.log('setting level (from/to)', this.currentLevel, id) if (id === this.currentLevel) return true; if (id !== null && this._tileLayers[id] === undefined) return false;