1
2
3  Polymer('core-submenu', {
4
5    publish: {
6      active: {value: false, reflect: true}
7    },
8
9    opened: false,
10
11    get items() {
12      return this.$.submenu.items;
13    },
14
15    hasItems: function() {
16      return !!this.items.length;
17    },
18
19    unselectAllItems: function() {
20      this.$.submenu.selected = null;
21      this.$.submenu.clearSelection();
22    },
23
24    activeChanged: function() {
25      if (this.hasItems()) {
26        this.opened = this.active;
27      }
28      if (!this.active) {
29        this.unselectAllItems();
30      }
31    },
32
33    toggle: function() {
34      this.opened = !this.opened;
35    },
36
37    activate: function() {
38      if (this.hasItems() && this.active) {
39        this.toggle();
40        this.unselectAllItems();
41      }
42    }
43
44  });
45
46