OLD | NEW |
1 library x_swap; | 1 library x_swap; |
2 | 2 |
3 import 'dart:async'; | 3 import 'dart:async'; |
4 import 'dart:html'; | 4 import 'dart:html'; |
5 import 'package:meta/meta.dart'; | 5 import 'package:meta/meta.dart'; |
6 import 'package:web_ui/web_ui.dart'; | 6 import 'package:web_ui/web_ui.dart'; |
7 import 'package:bot/bot.dart'; | 7 import 'package:bot/bot.dart'; |
8 import 'package:widget/effects.dart'; | 8 import 'package:widget/effects.dart'; |
9 import 'package:widget/widget.dart'; | 9 import 'package:widget/widget.dart'; |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 final newActive = items[index]; | 44 final newActive = items[index]; |
45 return showItem(newActive, effect: effect, duration: duration, effectTiming:
effectTiming, hideEffect: hideEffect); | 45 return showItem(newActive, effect: effect, duration: duration, effectTiming:
effectTiming, hideEffect: hideEffect); |
46 } | 46 } |
47 | 47 |
48 @override | 48 @override |
49 Future<bool> showItem(Element item, {ShowHideEffect effect, int duration, Effe
ctTiming effectTiming, ShowHideEffect hideEffect}) { | 49 Future<bool> showItem(Element item, {ShowHideEffect effect, int duration, Effe
ctTiming effectTiming, ShowHideEffect hideEffect}) { |
50 assert(items.contains(item)); | 50 assert(items.contains(item)); |
51 | 51 |
52 final oldActiveChild = activeItem; | 52 final oldActiveChild = activeItem; |
53 if(oldActiveChild == item) { | 53 if(oldActiveChild == item) { |
54 return new Future<bool>.immediate(true); | 54 return new Future<bool>.value(true); |
55 } | 55 } |
56 | 56 |
57 [oldActiveChild, item].forEach((e) => e.classes.remove(_dirClassPrev)); | 57 [oldActiveChild, item].forEach((e) => e.classes.remove(_dirClassPrev)); |
58 | 58 |
59 oldActiveChild.classes.remove(_activeClass); | 59 oldActiveChild.classes.remove(_activeClass); |
60 oldActiveChild.classes.add(_dirClassPrev); | 60 oldActiveChild.classes.add(_dirClassPrev); |
61 | 61 |
62 item.classes.add(_activeClass); | 62 item.classes.add(_activeClass); |
63 | 63 |
64 return Swapper.swap(_contentElement, item, effect: effect, duration: duratio
n, effectTiming: effectTiming, hideEffect: hideEffect) | 64 return Swapper.swap(_contentElement, item, effect: effect, duration: duratio
n, effectTiming: effectTiming, hideEffect: hideEffect) |
(...skipping 12 matching lines...) Expand all Loading... |
77 _contentElementField = null; | 77 _contentElementField = null; |
78 } | 78 } |
79 | 79 |
80 Element get _contentElement { | 80 Element get _contentElement { |
81 _initialize(); | 81 _initialize(); |
82 return _contentElementField; | 82 return _contentElementField; |
83 } | 83 } |
84 | 84 |
85 void _initialize() { | 85 void _initialize() { |
86 if(_contentElementField == null) { | 86 if(_contentElementField == null) { |
87 _contentElementField = this.query('x-swap > .content'); | 87 _contentElementField = this.query('[is=x-swap] > .content'); |
88 if(_contentElementField == null) { | 88 if(_contentElementField == null) { |
89 throw 'Could not find the content element. Either the template has chang
ed or state was accessed too early in the component lifecycle.'; | 89 throw 'Could not find the content element. Either the template has chang
ed or state was accessed too early in the component lifecycle.'; |
90 } | 90 } |
91 | 91 |
92 final theItems = _contentElementField.children; | 92 final theItems = _contentElementField.children; |
93 | 93 |
94 // if there are any elements, make sure one and only one is 'active' | 94 // if there are any elements, make sure one and only one is 'active' |
95 final activeFigures = new List<Element>.from(theItems.where((e) => e.class
es.contains(_activeClass)).toList()); | 95 final activeFigures = new List<Element>.from(theItems.where((e) => e.class
es.contains(_activeClass)).toList()); |
96 if(activeFigures.length == 0) { | 96 if(activeFigures.length == 0) { |
97 if(theItems.length > 0) { | 97 if(theItems.length > 0) { |
98 // marke the first of the figures as active | 98 // marke the first of the figures as active |
99 theItems[0].classes.add(_activeClass); | 99 theItems[0].classes.add(_activeClass); |
100 } | 100 } |
101 } else { | 101 } else { |
102 activeFigures.sublist(1) | 102 activeFigures.sublist(1) |
103 .forEach((e) => e.classes.remove(_activeClass)); | 103 .forEach((e) => e.classes.remove(_activeClass)); |
104 } | 104 } |
105 | 105 |
106 // A bit of a hack. Because we call Swap w/ two displayed items: | 106 // A bit of a hack. Because we call Swap w/ two displayed items: |
107 // one marked 'prev' and one marked 'next', Swap tries to hide one of them | 107 // one marked 'prev' and one marked 'next', Swap tries to hide one of them |
108 // this only causes a problem when clicking right the first time, since al
l | 108 // this only causes a problem when clicking right the first time, since al
l |
109 // times after, the cached ShowHideState of the item is set | 109 // times after, the cached ShowHideState of the item is set |
110 // So...we're going to walk the showHide states of all children now | 110 // So...we're going to walk the showHide states of all children now |
111 // ...and ignore the result...but just to populate the values | 111 // ...and ignore the result...but just to populate the values |
112 theItems.forEach((f) => ShowHide.getState(f)); | 112 theItems.forEach((f) => ShowHide.getState(f)); |
113 } | 113 } |
114 } | 114 } |
115 } | 115 } |
OLD | NEW |