- Move p19 styles to stylesheet - Wait to update meshcore until after all plugins loaded (reduced processing power) - More intuitive registerPluginTab functionality - OnStates for current plugin tab

- Move p19 styles to stylesheet - Wait to update meshcore until after all plugins loaded (reduced processing power) - More intuitive registerPluginTab functionality - OnStates for current plugin tab

Ryan Blenis committed Nov 30, 2019 at 20:26 UTC 3c3a3d3b14b227c94aa9fcd0892ec549f1e11106
3 files changed +34 -22
pluginHandler.js
+13 -5
@@ -51,8 +51,8 @@ module.exports.pluginHandler = function (parent) {
51 parent.db.updatePlugin(plugin._id, plugin_config);
52 } catch (e) { console.log("Plugin config file for " + plugin.name + " could not be parsed."); }
53 }
54 - obj.parent.updateMeshCore(); // db calls are delayed, lets inject here once we're ready
54 });
55 + obj.parent.updateMeshCore(); // db calls are async, lets inject here once we're ready
56 });
57 } else {
58 obj.loadList.forEach(function (plugin, index) {
@@ -88,17 +88,25 @@ module.exports.pluginHandler = function (parent) {
88 }
89 }
90 };
91 -
91 + // accepts a function returning an object or an object with { tabId: "yourTabIdValue", tabTitle: "Your Tab Title" }
92 obj.registerPluginTab = function(pluginRegInfo) {
93 - var d = pluginRegInfo();
93 + var d = null;
94 + if (typeof pluginRegInfo == 'function') d = pluginRegInfo();
95 + else d = pluginRegInfo;
96 if (!Q(d.tabId)) {
95 - QA('p19headers', '<span onclick="return pluginHandler.callPluginPage(\\''+d.tabId+'\\');">'+d.tabTitle+'</span>');
97 + var defaultOn = 'class="on"';
98 + if (Q('p19headers').querySelectorAll("span.on").length) defaultOn = '';
99 + QA('p19headers', '<span ' + defaultOn + ' onclick="return pluginHandler.callPluginPage(\\''+d.tabId+'\\', this);">'+d.tabTitle+'</span>');
100 + QA('p19pages', '<div id="' + d.tabId + '"></div>');
101 }
102 };
98 - obj.callPluginPage = function(id) {
103 + obj.callPluginPage = function(id, el) {
104 var pages = Q('p19pages').querySelectorAll("#p19pages>div");
105 for (const i of pages) { i.style.display = 'none'; }
106 QV(id, true);
107 + var tabs = Q('p19headers').querySelectorAll("span");
108 + for (const i of tabs) { i.classList.remove('on'); }
109 + el.classList.add('on');
110 };
111 obj.addPluginEx = function() {
112 meshserver.send({ action: 'addplugin', url: Q('pluginurlinput').value});
public/styles/style.css
+21
@@ -2645,3 +2645,24 @@ a {
2645 width: 100%;
2646 height: 100%;
2647 }
2648 +
2649 +#p19headers {
2650 + padding-right: 7px;
2651 + padding-bottom: 10px;
2652 + font-weight: bold;
2653 + border-bottom: 1px dotted blue;
2654 +}
2655 +
2656 +#p19headers > span:nth-child(n+2) {
2657 + border-left: 1px solid black;
2658 +}
2659 +
2660 +#p19headers > span {
2661 + padding-left: 4px;
2662 + padding-right: 4px;
2663 + cursor: pointer;
2664 + font-weight: lighter;
2665 +}
2666 +#p19headers > span.on {
2667 + font-weight: bold;
2668 +}
views/default.handlebars
-17
@@ -893,23 +893,6 @@
893 </div>
894 <div id=p19 style="display:none">
895 <h1>Plugins - <span id=p19deviceName></span></h1>
896 - <style>
897 - #p19headers {
898 - padding-right: 7px;
899 - padding-bottom: 10px;
900 - font-weight: bold;
901 - border-bottom: 1px dotted blue;
902 - }
903 -
904 - #p19headers > span:nth-child(n+2) {
905 - border-left: 1px solid black;
906 - }
907 -
908 - #p19headers > span {
909 - padding-left: 4px;
910 - padding-right: 4px;
911 - }
912 - </style>
896 <div id="p19headers"></div>
897 <div id=p19pages></div>
898 </div>