فهرست منبع

fix popup menu

Gerald 9 سال پیش
والد
کامیت
683587f257
2فایلهای تغییر یافته به همراه23 افزوده شده و 9 حذف شده
  1. 1 1
      src/popup/components/menu.html
  2. 22 8
      src/popup/components/menu.js

+ 1 - 1
src/popup/components/menu.html

@@ -1,6 +1,6 @@
 <div>
   <div class="menu" v-el:top>
-    <menu-item v-for="item in items.top" :options="item"></menu-item>
+    <menu-item v-for="item in items.top" v-show="!item.hide" :options="item"></menu-item>
   </div>
   <hr v-if="items.bot.length">
   <div class="menu placeholder" v-el:placeholder></div>

+ 22 - 8
src/popup/components/menu.js

@@ -24,12 +24,10 @@ define('views/Menu', function (require, _exports, module) {
             else chrome.tabs.create({url: url});
           });
         },
-      }, {
+      }, _this.menuFindScripts = {
         name: _.i18n('menuFindScripts'),
         symbol: 'search',
-        show: function () {
-          return _this.store.domains.length;
-        },
+        hide: false,
         onClick: function () {
           var matches = _this.store.currentTab.url.match(/:\/\/(?:www\.)?([^\/]*)/);
           chrome.tabs.create({
@@ -39,12 +37,10 @@ define('views/Menu', function (require, _exports, module) {
         detailClick: function () {
           app.navigate('domains');
         },
-      }, {
+      }, _this.menuCommands = {
         name: _.i18n('menuCommands'),
         symbol: 'arrow-right',
-        show: function () {
-          return _this.store.commands.length;
-        },
+        hide: false,
         onClick: function () {
           app.navigate('commands');
         },
@@ -68,11 +64,19 @@ define('views/Menu', function (require, _exports, module) {
           });
         },
       });
+      _this.updateDomains();
+      _this.updateCommands();
     },
     watch: {
       'store.scripts': function () {
         this.update();
       },
+      'store.commands': function () {
+        this.updateCommands();
+      },
+      'store.domains': function () {
+        this.updateDomains();
+      },
     },
     methods: {
       update: function () {
@@ -104,6 +108,16 @@ define('views/Menu', function (require, _exports, module) {
           };
         });
       },
+      updateCommands: function () {
+        var _this = this;
+        var commands = _this.store.commands;
+        _this.menuCommands.hide = !commands || !commands.length;
+      },
+      updateDomains: function () {
+        var _this = this;
+        var domains = _this.store.domains;
+        _this.menuFindScripts.hide = !domains || !domains.length;
+      },
     },
   };
 });