diff --git a/plugin.js b/plugin.js index 23eec3c..63f4e2f 100644 --- a/plugin.js +++ b/plugin.js @@ -79,16 +79,46 @@ body = b; }; - // Wire up keyboard/remote navigation using native Lampa Controller. + // Wire up keyboard/remote navigation (pattern from Shikimori plugin). this.start = function () { + if (Lampa.Activity.active().activity !== this.activity) return; if (!grid) return; var cards = grid.find('.card.selector'); if (!cards.length) return; - // Native collection navigation: Lampa handles up/down/left/right and - // fires "hover:enter" on the focused .selector when OK/Enter is pressed. - Lampa.Controller.collectionSet(grid); - Lampa.Controller.collectionFocus(cards[0], grid); + Lampa.Controller.add('content', { + toggle: function () { + Lampa.Controller.collectionSet(grid); + Lampa.Controller.collectionFocus(cards[0], grid); + }, + right: function () { + Navigator.move('right'); + }, + left: function () { + if (Navigator.canmove('left')) Navigator.move('left'); + else Lampa.Controller.toggle('menu'); + }, + up: function () { + Navigator.move('up'); + }, + down: function () { + Navigator.move('down'); + }, + enter: function () { + var el = grid.find('.card.selector.focus')[0] || cards[0]; + if (!el) return; + var id = $(el).attr('data-id'); + var m = comp._movies ? comp._movies.find(function (x) { return x.id === id; }) : null; + if (m) openMovie(m); + }, + back: function () { + Lampa.Activity.back(); + }, + gone: function () { + Lampa.Controller.clear('content'); + } + }); + Lampa.Controller.toggle('content'); }; this.render = function () {