OLD | NEW |
---|---|
1 import 'dart:async'; | 1 import 'dart:async'; |
2 import 'dart:html'; | 2 import 'dart:html'; |
3 import 'package:web_ui/web_ui.dart'; | 3 import 'package:web_ui/web_ui.dart'; |
4 import 'package:bot/bot.dart'; | 4 import 'package:bot/bot.dart'; |
5 import 'package:widget/effects.dart'; | 5 import 'package:widget/effects.dart'; |
6 import 'package:widget/widget.dart'; | 6 import 'package:widget/widget.dart'; |
7 | 7 |
8 // TODO: option to enable/disable wrapping. Disable buttons if the end is hit... | 8 // TODO: option to enable/disable wrapping. Disable buttons if the end is hit... |
9 | 9 |
10 /** | 10 /** |
11 * [Carousel] allows moving back and forth through a set of child elements. | 11 * [Carousel] allows moving back and forth through a set of child elements. |
12 * | 12 * |
13 * It is based on a [similar component](http://twitter.github.com/bootstrap/java script.html#carousel) | 13 * It is based on a [similar component](http://twitter.github.com/bootstrap/java script.html#carousel) |
14 * in Bootstrap. | 14 * in Bootstrap. |
15 * | 15 * |
16 * [Carousel] leverages the [Swap] component to render the transition between it ems. | 16 * [Carousel] leverages the [Swap] component to render the transition between it ems. |
17 */ | 17 */ |
18 class Carousel extends WebComponent { | 18 class Carousel extends WebComponent { |
19 final ShowHideEffect _fromTheLeft = new SlideEffect(xStart: HorizontalAlignmen t.LEFT); | 19 final ShowHideEffect _fromTheLeft = new SlideEffect(xStart: HorizontalAlignmen t.LEFT); |
20 final ShowHideEffect _fromTheRight = new SlideEffect(xStart: HorizontalAlignme nt.RIGHT); | 20 final ShowHideEffect _fromTheRight = new SlideEffect(xStart: HorizontalAlignme nt.RIGHT); |
21 | 21 |
22 static const _duration = 2000; | 22 static const _duration = 2000; |
23 | 23 |
24 Future<bool> next() => _moveDelta(true); | 24 Future<bool> next() => _moveDelta(true); |
25 | 25 |
26 Future<bool> previous() => _moveDelta(false); | 26 Future<bool> previous() => _moveDelta(false); |
27 | 27 |
28 SwapComponent get _swap => this.query('x-carousel > .carousel > x-swap').xtag; | 28 SwapComponent get _swap => this.query('[is=x-carousel] > .carousel > [is=x-swa p]').xtag; |
Siggi Cherem (dart-lang)
2013/04/16 17:34:36
long line
Jacob
2013/04/16 17:45:46
Done.
| |
29 | 29 |
30 Future<bool> _moveDelta(bool doNext) { | 30 Future<bool> _moveDelta(bool doNext) { |
31 final swap = _swap; | 31 final swap = _swap; |
32 assert(swap != null); | 32 assert(swap != null); |
33 if(swap.items.length == 0) { | 33 if(swap.items.length == 0) { |
34 return new Future.immediate(false); | 34 return new Future.value(false); |
35 } | 35 } |
36 | 36 |
37 assert(doNext != null); | 37 assert(doNext != null); |
38 final delta = doNext ? 1 : -1; | 38 final delta = doNext ? 1 : -1; |
39 | 39 |
40 ShowHideEffect showEffect, hideEffect; | 40 ShowHideEffect showEffect, hideEffect; |
41 if(doNext) { | 41 if(doNext) { |
42 showEffect = _fromTheRight; | 42 showEffect = _fromTheRight; |
43 hideEffect = _fromTheLeft; | 43 hideEffect = _fromTheLeft; |
44 } else { | 44 } else { |
45 showEffect = _fromTheLeft; | 45 showEffect = _fromTheLeft; |
46 hideEffect = _fromTheRight; | 46 hideEffect = _fromTheRight; |
47 } | 47 } |
48 | 48 |
49 final activeIndex = _swap.activeItemIndex; | 49 final activeIndex = _swap.activeItemIndex; |
50 | 50 |
51 final newIndex = (activeIndex + delta) % _swap.items.length; | 51 final newIndex = (activeIndex + delta) % _swap.items.length; |
52 | 52 |
53 return _swap.showItemAtIndex(newIndex, effect: showEffect, hideEffect: hideE ffect, duration: _duration); | 53 return _swap.showItemAtIndex(newIndex, effect: showEffect, hideEffect: hideE ffect, duration: _duration); |
54 } | 54 } |
55 } | 55 } |
OLD | NEW |