menu: add item immediately (no 3s delay) + Lampa.Lang localization (ru: Мои фильмы)
This commit is contained in:
1 parent
dd59e79f94
commit
4d35315443
1 file changed
+22
-10
@@ -1,9 +1,17 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var PLUGIN = { name: 'mymovies', title: 'My Movies', menu_action: 'mymovies' };
|
||||
var PLUGIN = { name: 'mymovies', title: 'mymovies_title', menu_action: 'mymovies' };
|
||||
var DEFAULT_BASE = 'https://movies-lmp-18.dynv6.net/';
|
||||
|
||||
// Localized strings. Register once, then use Lampa.Lang.translate(KEY).
|
||||
var STRINGS = {
|
||||
mymovies_title: { ru: 'Мои фильмы', en: 'My Movies' }
|
||||
};
|
||||
function t(key) {
|
||||
try { return Lampa.Lang.translate(key); } catch (e) { return key; }
|
||||
}
|
||||
|
||||
function base() {
|
||||
var b = Lampa.Storage.get(PLUGIN.name + '_base', DEFAULT_BASE);
|
||||
return b.replace(/\/+$/, '') + '/';
|
||||
@@ -386,15 +394,15 @@
|
||||
'<div class="menu__ico">' +
|
||||
'<svg class="sprite-folder"><use xlink:href="#sprite-folder"></use></svg>' +
|
||||
'</div>' +
|
||||
'<div class="menu__text">' + PLUGIN.title + '</div>' +
|
||||
'<div class="menu__text">' + t(PLUGIN.title) + '</div>' +
|
||||
'</li>'
|
||||
);
|
||||
button.on('hover:enter', function () {
|
||||
Lampa.Activity.push({
|
||||
url: '',
|
||||
component: PLUGIN.name,
|
||||
title: PLUGIN.title,
|
||||
page: PLUGIN.title
|
||||
title: t(PLUGIN.title),
|
||||
page: t(PLUGIN.title)
|
||||
});
|
||||
});
|
||||
return button;
|
||||
@@ -410,6 +418,10 @@
|
||||
function start() {
|
||||
if (menuSubscribed) return;
|
||||
menuSubscribed = true;
|
||||
|
||||
// Register localized strings for this plugin.
|
||||
try { Lampa.Lang.add(STRINGS); } catch (e) { /* older Lampa: ignore */ }
|
||||
|
||||
Lampa.Listener.follow('menu', function (e) {
|
||||
if (e.type === 'start' && e.body) {
|
||||
var list = e.body.find('.menu__list');
|
||||
@@ -419,12 +431,12 @@
|
||||
addMenuButton();
|
||||
}
|
||||
});
|
||||
// fallback: re-check shortly after load (covers late menu builds)
|
||||
setTimeout(function () {
|
||||
if ($('.menu .menu__list').length && !$('[data-action="' + PLUGIN.menu_action + '"]').length) {
|
||||
addMenuButton();
|
||||
}
|
||||
}, 3000);
|
||||
|
||||
// If the main menu is already built, add the item immediately so it does
|
||||
// NOT appear late and shove other items around.
|
||||
if ($('.menu .menu__list').length && !$('[data-action="' + PLUGIN.menu_action + '"]').length) {
|
||||
addMenuButton();
|
||||
}
|
||||
}
|
||||
|
||||
if (window.Lampa && Lampa.Listener && Lampa.Activity) {
|
||||
|
||||
Reference in new issue
Block a user