OLD | NEW |
1 import 'dart:html'; | 1 import 'dart:html'; |
2 import 'package:web_ui/web_ui.dart'; | 2 import 'package:web_ui/web_ui.dart'; |
3 import 'package:bot/bot.dart'; | 3 import 'package:bot/bot.dart'; |
4 import 'package:widget/effects.dart'; | 4 import 'package:widget/effects.dart'; |
5 import 'package:widget/widget.dart'; | 5 import 'package:widget/widget.dart'; |
6 | 6 |
7 // TODO:TEST: no active tabs -> first is active | 7 // TODO:TEST: no active tabs -> first is active |
8 // TODO:TEST: 2+ active tabs -> all but first is active | 8 // TODO:TEST: 2+ active tabs -> all but first is active |
9 // TODO:TEST: no tabs -> no crash | 9 // TODO:TEST: no tabs -> no crash |
10 | 10 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 String target = clickedElement.dataset['target']; | 85 String target = clickedElement.dataset['target']; |
86 if(target == null) { | 86 if(target == null) { |
87 final href = clickedElement.attributes['href']; | 87 final href = clickedElement.attributes['href']; |
88 if(href != null && href.startsWith('#')) { | 88 if(href != null && href.startsWith('#')) { |
89 target = href.substring(1); | 89 target = href.substring(1); |
90 } | 90 } |
91 } | 91 } |
92 return target; | 92 return target; |
93 } | 93 } |
94 | 94 |
95 List<Element> _getAllTabs() => this.queryAll('x-tabs > .nav-tabs > li'); | 95 List<Element> _getAllTabs() => this.queryAll('[is=x-tabs] > .nav-tabs > li'); |
96 | 96 |
97 void _ensureAtMostOneTabActive() { | 97 void _ensureAtMostOneTabActive() { |
98 final tabs = _getAllTabs(); | 98 final tabs = _getAllTabs(); |
99 Element activeTab = null; | 99 Element activeTab = null; |
100 tabs.forEach((Element tab) { | 100 tabs.forEach((Element tab) { |
101 if(tab.classes.contains('active')) { | 101 if(tab.classes.contains('active')) { |
102 if(activeTab == null) { | 102 if(activeTab == null) { |
103 activeTab = tab; | 103 activeTab = tab; |
104 } else { | 104 } else { |
105 tab.classes.remove('active'); | 105 tab.classes.remove('active'); |
106 } | 106 } |
107 } | 107 } |
108 }); | 108 }); |
109 | 109 |
110 if(activeTab == null && !tabs.isEmpty) { | 110 if(activeTab == null && !tabs.isEmpty) { |
111 activeTab = tabs[0]; | 111 activeTab = tabs[0]; |
112 activeTab.classes.add('active'); | 112 activeTab.classes.add('active'); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 SwapComponent _getSwap() { | 116 SwapComponent _getSwap() { |
117 final Element element = this.query('x-tabs > x-swap'); | 117 final Element element = this.query('[is=x-tabs] > [is=x-swap]'); |
118 if(element != null) { | 118 if(element != null) { |
119 if(element is SwapComponent) { | 119 if(element is SwapComponent) { |
120 return element; | 120 return element; |
121 } else if(element.xtag is SwapComponent) { | 121 } else if(element.xtag is SwapComponent) { |
122 return element.xtag; | 122 return element.xtag; |
123 } | 123 } |
124 } | 124 } |
125 return null; | 125 return null; |
126 } | 126 } |
127 | 127 |
128 void _updateContent(String target) { | 128 void _updateContent(String target) { |
129 final swap = _getSwap(); | 129 final swap = _getSwap(); |
130 | 130 |
131 if(swap != null) { | 131 if(swap != null) { |
132 final items = swap.items; | 132 final items = swap.items; |
133 | 133 |
134 final targetItem = $(items).firstWhere((e) => e.id == target, orElse: () =
> null); | 134 final targetItem = $(items).firstWhere((e) => e.id == target, orElse: () =
> null); |
135 if(targetItem != null) { | 135 if(targetItem != null) { |
136 swap.showItem(targetItem); | 136 swap.showItem(targetItem); |
137 } | 137 } |
138 } | 138 } |
139 } | 139 } |
140 } | 140 } |
OLD | NEW |