Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: lib/components/swap.dart

Issue 14295009: Fix widget.dart to work with the latest web_ui library. Specifically, query selectors need to use "… (Closed) Base URL: https://github.com/kevmoo/widget.dart.git@master
Patch Set: ptal Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/components/modal.html ('k') | lib/components/swap.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « lib/components/modal.html ('k') | lib/components/swap.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698